dropboxdol.connection#
Objects to connect to Dropbox.
Functions
|
|
|
|
|
Copy a configuration file from one location to another. |
|
Create a configuration file for a Dropbox client. |
|
|
|
Return a Dropbox client using the best available configuration source. |
|
Create a Dropbox client using explicit credentials with additional validation. |
|
Create a Dropbox client by loading configuration from a JSON file. |
|
Create a Dropbox client using configuration from environment variables. |
Retrieve a configuration value. |
|
|
Runs an interactive OAuth flow to obtain an access token and a refresh token. |
- dropboxdol.connection.copy_config_file(src_config_file, dest_config_file=None)[source]#
Copy a configuration file from one location to another.
If the destination file already exists, a FileExistsError will be raised.
- dropboxdol.connection.create_config_file(config_file, *, app_key, app_secret, oauth2_access_token=None, oauth2_refresh_token=None)[source]#
Create a configuration file for a Dropbox client.
If the file already exists, a FileExistsError will be raised. The
config_filemust be a sring ending with ‘.json’. If oauth2_refresh_token is not given, an interactive flow will be used to obtain it, also replacing the oauth2_access_token.
- dropboxdol.connection.get_client(config='default_dropbox_config.json', **kwargs)[source]#
Return a Dropbox client using the best available configuration source.
Priority:
If an oauth2_access_token is provided and ends with ‘.json’, load configuration from that file.
Else, if the environment variable (named by oauth2_access_token) exists, use environment variables.
Otherwise, use explicit parameters provided via kwargs.
Expected keyword arguments:
oauth2_access_token
oauth2_refresh_token
app_key
app_secret
- Return type:
Dropbox
- dropboxdol.connection.get_client_from_args(oauth2_access_token, oauth2_refresh_token=None, app_key=None, app_secret=None)[source]#
Create a Dropbox client using explicit credentials with additional validation.
Validation includes:
Ensuring that oauth2_access_token is provided and is a non-empty string.
If any of oauth2_refresh_token, app_key, or app_secret are provided, then all must be provided to enable auto-refresh.
Issuing soft warnings if any of the parameters appear to be environment variable names (all uppercase), which might indicate that the caller intended to pass literal values.
- dropboxdol.connection.get_client_from_config_file(config_filepath)[source]#
Create a Dropbox client by loading configuration from a JSON file.
The JSON file must contain the keys:
“oauth2_access_token”
“oauth2_refresh_token”
“app_key”
“app_secret”
- Raises:
FileNotFoundError – If the config file does not exist.
Exception – If required keys are missing.
- Return type:
Dropbox
- dropboxdol.connection.get_client_from_environment_vars(oauth2_access_token, oauth2_refresh_token=None, app_key=None, app_secret=None)[source]#
Create a Dropbox client using configuration from environment variables.
The provided parameter names are interpreted as the names of the environment variables. For example, calling:
- get_client_from_environment_vars(“DROPBOX_ACCESS_TOKEN”, “DROPBOX_REFRESH_TOKEN”,
“DROPBOX_APP_KEY”, “DROPBOX_APP_SECRET”)
will use the values from os.environ (if they exist), or fall back to the literal strings.
- Return type:
Dropbox
- dropboxdol.connection.get_envvar_if_upper_case_and_exists(config)[source]#
Retrieve a configuration value.
First checks os.environ for the given key. If present, returns its value; otherwise, returns the key itself (allowing you to pass literal values).
- Return type:
- dropboxdol.connection.get_tokens_interactive(app_key, app_secret)[source]#
Runs an interactive OAuth flow to obtain an access token and a refresh token.
Ensure you pass your Dropbox app key and secret. This flow will print an authorization URL. Visit the URL in your browser, authorize the app, then paste the resulting code into the prompt.
- Returns:
A tuple (access_token, refresh_token)