Skip to main content

dropboxdol

dropbox with a simple (dict-like or list-like) interface

To install: pip install dropboxdol

Setup

Note: To use dropboxdol, you'll need to have a dropbox access token. Additionally, that token should be allowed to do the operation that you are doing. For example, you only need the "sharing.write" permission to CREATE a (new) shared link.

See more information in Dropbox's Auth Guide.

By default, dropboxdol looks for the access tokens and other information is (well, really, the dropbox API) needs) in the "default_dropbox_config.json" file of the dropboxdol app data. You can interact with those files via dropboxdol.config_store, which has a dict-like interface to the files in that folder.

If you don't have a "default_dropbox_config.json" file, you'll need to specify the connection config explicitly (by specifying a config dict, a filepath, filename of the config_store).

Note that at this point, dropbox only dishes out temporary access tokens. This means you can't just save an access token once and be over with it. So to get the convenience of automatic connections, you'll need to specify not only a oauth2_access_token, but also a oauth2_refresh_token, an app_key and an app_secret.

You can read all about that annoying stuff in the Dropbox's Auth Guide.

But here's a few things to make it a bit less painful:

  • make an "app" in the app console
  • specify scope and permissions you want on it
  • note down the app key and the app secret

then use the following, which will walk you through the steps to get your access and refresh tokens.

These will then be stored in the config_file of your choice, so that all you have to do is mention the file to get the connection.

from dropboxdol import create_config_file

create_config_file(
    config_file="NAME_OF_YOUR_APP_OR_WHATEVER_NAME_YOU_WILL_REMEMBER.json",
    app_key="YOUR_APP_KEY",
    app_secret="YOUR_APP_SECRET",
)

If you already have a config file for this app, with app_key and app_secret, you can update the tokens by doing this:

from dropboxdol import complete_config_file_with_refresh_token

complete_config_file_with_refresh_token(
    config_file="NAME_OF_YOUR_APP_OR_WHATEVER_YOU_CALLED_THAT_CONFIG.json",
)

If you want to edit some configs, you can do so by editing the file directly, or use create_or_edit_config_file.

from dropboxdol import create_or_edit_config_file

create_or_edit_config_file(
    config_file="CONFIG_FILE.json",
    # whatever edits you want to make... (specifying None will skip that config, leaving it unchanged)
    oauth2_access_token=None,
    oauth2_refresh_token=None,
    app_key=None,
    app_secret=None,
)

Examples

Get a dropbox "store"

From a link

from dropboxdol import DropboxLinkReaderWithToken

s = DropboxLinkReaderWithToken(
    url="https://www.dropbox.com/sh/0ru09jmk0w9tdnr/AAA-PPON2sYmwUUoGQpBQh1Ia?dl=0"
)
keys = list(s)
keys
['inner_folder',
'b1467f55540c4695bf483bc542e43256',
'0b98e2af76c94a0a9cc2808866dd62de',
'3372aa35ea444c758bfa2e4599b2576d',
'9de9d98a4c4648cca1bc1131c307a365',
'91c744890d374dd8bc914f1153311b0c',
'57af886dd22f4a23a678a3de3eb996a0',
'43ba127e5e9245ec983c9f39e4ed7306']

From a local path (but talking to the remote files)

from dropboxdol import DropboxFiles
from i2 import Sig

t = DropboxFiles("/Apps/py2store/py2store_data")
list(t)
['/test', '/test.txt', '/another_test.txt']
t["/test.txt"]
b'This is a test.\nSee it work.\nAnd what about unicode? \xc3\xa8\xc3\xa9\xc3\xaa\xc3\xab\xc4\x93\xc4\x97\xc4\x99?'

Get dropbox links for local files/folders

(Your token needs the "sharing.write" permission to CREATE a (new) shared link.)

>>> from dropboxdol import dropbox_link
>>> local_file = '/Users/thorwhalen/Dropbox/Apps/py2store/py2store_data/test.txt'
>>> dropbox_url = dropbox_link(local_file)
>>> print(dropbox_url)
https://www.dropbox.com/scl/fi/3o8ooqje4f497npxdeiwg/test.txt?rlkey=x9jsd8u7k147x6fzc7stxozqe&dl=0

If you want to talk "relative" to the dropbox root dir, do this:

>>> from functools import partial
>>> my_dropbox_link = partial(dropbox_link, dropbox_local_rootdir='/Users/thorwhalen/Dropbox')

If you want a "direct (download) link", do this:

>>> dl1_link = my_dropbox_link('Apps/py2store/py2store_data/test.txt', dl=1)
'https://www.dropbox.com/scl/fi/3o8ooqje4f497npxdeiwg/test.txt?rlkey=x9jsd8u7k147x6fzc7stxozqe&dl=1'

Easy read/write access to your dropbox files

A persister for dropbox.

>>> import json
>>> import os
>>> from dropboxdol import DropboxPersister
>>> configs = json.load(open(os.path.expanduser('~/.py2store_configs.json')))
>>> s = DropboxPersister('/py2store_data/test/', **configs['dropbox']['__init__kwargs'])
>>> if '/py2store_data/test/_can_remove' in s:
...     del s['/py2store_data/test/_can_remove']
...
>>>
>>> n = len(s)
>>> if n == 1:
...     assert list(s) == ['/py2store_data/test/_can_remove']
...
>>> s['/py2store_data/test/_can_remove'] = b'this is a test'
>>> assert len(s) == n + 1
>>> assert s['/py2store_data/test/_can_remove'] == b'this is a test'
>>> '/py2store_data/test/_can_remove' in s
True
>>> del s['/py2store_data/test/_can_remove']

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dropboxdol-0.0.13.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dropboxdol-0.0.13-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file dropboxdol-0.0.13.tar.gz.

File metadata

  • Download URL: dropboxdol-0.0.13.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dropboxdol-0.0.13.tar.gz
Algorithm Hash digest
SHA256 149e23920bd005e16062cb477ed0ac726db8e0539cb548617fefef519e169718
MD5 bb607cc5468b600f952a8a861bdfcf12
BLAKE2b-256 d66ff7a3f22bf06f65e2efcafccdcc6a80a061f50f9f0835ad7110ddf01dbdb5

See more details on using hashes here.

File details

Details for the file dropboxdol-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: dropboxdol-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dropboxdol-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 ef1f497800aff95e1dfcebfcc2e3600fe4573d44a9568235ceb765aff4e4a961
MD5 0c5962c9f7ca4df1a21a471d682d7d09
BLAKE2b-256 09e9a620a6b8277dbe3a52e2a80ad1c16af75c6326e6aa63214450d6d87e3ebd

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.13 This release

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page