Zenodo Client Module#
Class Signature#
|
zenopy client class |
Member Functions#
Creates an empty config file in the config_file_path |
|
Creates an instance of the _DepositionActions class |
|
Creates an instance of the _DepositionFiles class |
|
Creates an instance of the _Records class |
|
Creates an instance of the _Resources class |
|
List all sections in a config file |
|
List all tokens in a specific section |
|
Reads the config file from disk |
|
Reading a specific token from a selected section |
|
Commit the current contents of the config object to config file on disk |
|
Setting the appropriate token within a specific section |
Specifications#
- class zenopy.client.Zenodo(token: str | None = None, config_file_path: str | Path | None = None, use_sandbox: bool = False)[source]#
zenopy client class
The zenopy client class instance allows the users to connect to their accounts on Zenodo server and communicate with it through REST APIs.
Examples
>>> import zenopy >>> cli = zenopy.Zenodo() WARNING: The config file (~/.zenodorc) is found.
- property config_obj: ConfigParser#
Getter for the client’s active ConfigParser object
- Returns:
_config_obj – The client’s active
ConfigParser
object which stores all authentication tokens and credentials in memory.- Return type:
configparser.ConfigParser
- create_config_file(config_file_path: str | None = None) None [source]#
Creates an empty config file in the config_file_path
- Parameters:
config_file_path (str, optional) – A valid address for creating the config file, by default None
- Raises:
RuntimeError – If the provided
config_file_path
is None or an empty stringconfigparser.Error – If a config file does already exist in the target address provided by
config_file_path
- init_deposition()[source]#
Creates an instance of the _Depositions class
The returned object exposes all functionalities pertinent to the
_Depositions
class.Examples
>>> import zenopy >>> cli = zenopy.Zenodo() WARNING: The config file (~/.zenodorc) is found. >>> depo = cli.init_deposition() >>> depo <zenopy.depositions._Depositions at 0x7fad2e053790>
- Returns:
An instance of the
zenopy.depositions._Depositions
class- Return type:
zenopy.depositions._Depositions
- init_deposition_actions()[source]#
Creates an instance of the _DepositionActions class
The returned object exposes all functionalities pertinent to the
_DepositionActions
class such as editing, publishing, creating a new version and discarding ongoing changes on the deposition draft.Examples
>>> import zenopy >>> cli = zenopy.Zenodo() WARNING: The config file (~/.zenodorc) is found. >>> depo_act = cli.init_deposition_actions() >>> depo_act <zenopy.deposition_actions._DepositionActions at 0x7f2f77742a10>
- Returns:
An instance of the
zenopy.deposition_actions._DepositionActions
class- Return type:
zenopy.deposition_actions._DepositionActions
- init_deposition_file()[source]#
Creates an instance of the _DepositionFiles class
The returned object exposes all functionalities of the
_DepositionFiles
class such as creating, listing, retrieving, sorting, etc. of files in a deposition draft.Examples
>>> import zenopy >>> cli = zenopy.Zenodo() WARNING: The config file (~/.zenodorc) is found. >>> depo_file = cli.init_deposition_file() >>> depo_file <zenopy.deposition_files._DepositionFiles at 0x7fad2e0533a0>
- Returns:
An instance of the
zenopy.deposition_files._DepositionFiles
class- Return type:
zenopy.deposition_files._DepositionFiles
- init_records()[source]#
Creates an instance of the _Records class
The returned object exposes all functionalities of the
_Records
class such as retrieving the records and performing elastic search among them.Examples
>>> import zenopy >>> cli = zenopy.Zenodo() WARNING: The config file (~/.zenodorc) is found. >>> rec_obj = cli.init_records() >>> rec_obj <zenopy.records._Records at 0x7fb020d5b760>
- Returns:
An instance of the
zenopy.records._Records
class- Return type:
zenopy.depositions._Records
- init_resources(resource: str | None = None)[source]#
Creates an instance of the _Resources class
The returned object provides users with search capabilities through the created resources type objects. The resource type can be
communities
,licenses
,grants
, orfunders
.Examples
>>> import zenopy >>> cli = zenopy.Zenodo() WARNING: The config file (~/.zenodorc) is found. >>> resrc_obj = cli.init_resources(resource="communities") >>> resrc_obj <zenopy.resources._Resources at 0x7f51ad3e58d0>
- Returns:
An instance of the
zenopy.resources._Resources
class- Return type:
zenopy.resources._Resources
- list_sections()[source]#
List all sections in a config file
- Returns:
_config_obj.sections() – A list of section titles in the instance’s active
_config_obj
attribute- Return type:
list[str]
Examples
>>> import zenopy >>> cli = zenopy.Zenodo() WARNING: The config file (~/.zenodorc) is found. # equivalent to `cli.config_obj.sections()` >>> cli.list_sections() ['ZENODO', 'SANDBOX']
- list_tokens(section: str | None = None) list[tuple[str, str]] [source]#
List all tokens in a specific section
Lists all tokens in a specific section in the client instance’s active
_config_obj
attribute.- Returns:
_config_obj[section].items() – A list of all available token labels and values formatted as doubles (key-value pairs as tuples)
- Return type:
list[tuple[str, str]]
- Raises:
configparser.NoSectionError – if the provided argument (section) is None or does not exist in the client instance’s active
_config_obj
attribute.
- read_config_file(config_file_path: str | None = None) ConfigParser [source]#
Reads the config file from disk
Reads the config file from a path pointed to by the
config_file_path
argument and returns aconfigparser.ConfigParser
object constructed from it.- Returns:
configparser.ConfigParser().read(path) – a
configparser.ConfigParser
object the contents of which is read from disk- Return type:
configparser.ConfigParser
- Raises:
RuntimeError – If
config_file_path
is None or refers to a non-existent config file
- read_token(section: str | None = None, key: str | None = None) str [source]#
Reading a specific token from a selected section
- Raises:
configparser.NoSectionError – If the section argument does not exist in the client instance’s active
_config_obj
attributeconfigparser.NoOptionError – If the key argument does not exist in the client instance’s active
_config_obj
attribute
Notes
The
read_token()
is case insensitive with respect to the entered section argument and automatically turns it to upper case.
- property token: str#
Getter for the Zenodo class token attribute
- Returns:
_token – The first token from [ZENODO] (if
_use_sandbox == False
) or [SANDBOX] (if_use_sandbox == True
) sections listed in the configuration file- Return type:
str
- update_config_file() None [source]#
Commit the current contents of the config object to config file on disk
Commits the current contents of the client instance’s active
_config_obj
attribute to the config file located at_config_file_path
on disk.- Raises:
configparser.Error – If the client instance’s
_config_file_path
points to a non-existent config file
- property use_sandbox: bool#
Getter for the Zenodo class use_sandbox boolean attribute
- Returns:
_use_sandbox – Boolean attribute for switching between the SANDBOX and ZENODO accounts
- Return type:
str
- write_token(section: str | None = None, key: str | None = None, token: str | None = None, force_rewrite: bool = False) None [source]#
Setting the appropriate token within a specific section
Setting the passed token-key pair arguments in the corresponding designated config file section.
- Raises:
configparser.NoSectionError – If the section argument does not exist in the client instance’s active
_config_obj
attributeconfigparser.NoOptionError – If the key argument does not exist in the client instance’s active
_config_obj
attributeconfigparser.Error – If the passed token already exists in the section selected by the user.
Notes
Set
force_rewrite = True
if you want to overwrite an existing token in a config file section