dropboxdol


Namedropboxdol JSON
Version 0.0.7 PyPI version JSON
download
home_pagehttps://github.com/i2mint/dropboxdol
Summarydropbox with a simple (dict-like or list-like) interface
upload_time2025-10-11 16:53:18
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseapache-2.0
keywords dropbox data access
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://developers.dropbox.com/oauth-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](https://developers.dropbox.com/oauth-guide).

But here's a few things to make it a bit less painful:
* make an "app" in the [app console](https://www.dropbox.com/developers/apps?_tk=pilot_lp&_ad=topbar4&_camp=myapps)
* 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.

```python
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:

```python
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`.

```python
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

```python
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)

```python
from dropboxdol import DropboxFiles
from i2 import Sig 

t = DropboxFiles('/Apps/py2store/py2store_data')
list(t)
```

    ['/test', '/test.txt', '/another_test.txt']

```python
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.)

```python
>>> 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:

```python
>>> 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:

```python
>>> 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.

```python
>>> 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']
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/i2mint/dropboxdol",
    "name": "dropboxdol",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "dropbox, data access",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/02/33/e96e80621ce214b0c984e1bc95a8324980ff4bdf3d89f2d6681d1635bccc/dropboxdol-0.0.7.tar.gz",
    "platform": "any",
    "description": "# dropboxdol\n\ndropbox with a simple (dict-like or list-like) interface\n\n\nTo install:\t```pip install dropboxdol```\n\n\n# Setup\n\nNote: To use `dropboxdol`, you'll need to have a dropbox access token. \nAdditionally, that token should be allowed to do the operation that you are doing. \nFor example, you only need the \"sharing.write\" permission to CREATE a (new) shared link. \n\nSee more information in [Dropbox's Auth Guide](https://developers.dropbox.com/oauth-guide). \n\n\nBy default, `dropboxdol` looks for the access tokens and other information is \n(well, really, the dropbox API) needs)\nin the `\"default_dropbox_config.json\"` file of the dropboxdol app data. \nYou can interact with those files via `dropboxdol.config_store`, which has a dict-like interface to the files in that folder. \n\nIf you don't have a `\"default_dropbox_config.json\"` file, you'll need to specify the \nconnection config explicitly (by specifying a config dict, a filepath, filename of the \n`config_store`).\n\nNote that at this point, dropbox only dishes out temporary access tokens.\nThis means you can't just save an access token once and be over with it. \nSo to get the convenience of automatic connections, you'll need to specify not only a \n`oauth2_access_token`, but also a `oauth2_refresh_token`, an `app_key` and an `app_secret`. \n\nYou can read all about that annoying stuff in the [Dropbox's Auth Guide](https://developers.dropbox.com/oauth-guide).\n\nBut here's a few things to make it a bit less painful:\n* make an \"app\" in the [app console](https://www.dropbox.com/developers/apps?_tk=pilot_lp&_ad=topbar4&_camp=myapps)\n* specify scope and permissions you want on it\n* note down the app key and the app secret\n\nthen use the following, which will walk you through the steps to get your access and refresh tokens.\n\nThese will then be stored in the `config_file` of your choice, so that all you have to \ndo is mention the file to get the connection.\n\n```python\nfrom dropboxdol import create_config_file\n\ncreate_config_file(\n    config_file='NAME_OF_YOUR_APP_OR_WHATEVER_NAME_YOU_WILL_REMEMBER.json',\n    app_key='YOUR_APP_KEY', \n    app_secret='YOUR_APP_SECRET',\n)\n```\n\nIf you already have a config file for this app, with app_key and app_secret, \nyou can update the tokens by doing this:\n\n```python\nfrom dropboxdol import complete_config_file_with_refresh_token\n\ncomplete_config_file_with_refresh_token(\n    config_file='NAME_OF_YOUR_APP_OR_WHATEVER_YOU_CALLED_THAT_CONFIG.json',\n)\n```\n\nIf you want to edit some configs, you can do so by editing the file directly, or use \n`create_or_edit_config_file`.\n\n```python\nfrom dropboxdol import create_or_edit_config_file\n\ncreate_or_edit_config_file(\n    config_file='CONFIG_FILE.json',\n    # whatever edits you want to make... (specifying None will skip that config, leaving it unchanged)\n    oauth2_access_token=None,\n    oauth2_refresh_token=None,\n    app_key=None,\n    app_secret=None,\n)\n```\n\n# Examples \n\n\n## Get a dropbox \"store\"\n\n### From a link\n\n```python\nfrom dropboxdol import DropboxLinkReaderWithToken\n\ns = DropboxLinkReaderWithToken(\n    url=\"https://www.dropbox.com/sh/0ru09jmk0w9tdnr/AAA-PPON2sYmwUUoGQpBQh1Ia?dl=0\"\n)\nkeys = list(s)\nkeys\n```\n\n    ['inner_folder',\n    'b1467f55540c4695bf483bc542e43256',\n    '0b98e2af76c94a0a9cc2808866dd62de',\n    '3372aa35ea444c758bfa2e4599b2576d',\n    '9de9d98a4c4648cca1bc1131c307a365',\n    '91c744890d374dd8bc914f1153311b0c',\n    '57af886dd22f4a23a678a3de3eb996a0',\n    '43ba127e5e9245ec983c9f39e4ed7306']\n\n\n### From a local path (but talking to the remote files)\n\n```python\nfrom dropboxdol import DropboxFiles\nfrom i2 import Sig \n\nt = DropboxFiles('/Apps/py2store/py2store_data')\nlist(t)\n```\n\n    ['/test', '/test.txt', '/another_test.txt']\n\n```python\nt['/test.txt']\n```\n\n    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?'\n\n\n## Get dropbox links for local files/folders\n\n(Your token needs the \"sharing.write\" permission to CREATE a (new) shared link.)\n\n```python\n>>> from dropboxdol import dropbox_link\n>>> local_file = '/Users/thorwhalen/Dropbox/Apps/py2store/py2store_data/test.txt'\n>>> dropbox_url = dropbox_link(local_file)\n>>> print(dropbox_url)\n```\n\n    https://www.dropbox.com/scl/fi/3o8ooqje4f497npxdeiwg/test.txt?rlkey=x9jsd8u7k147x6fzc7stxozqe&dl=0\n\nIf you want to talk \"relative\" to the dropbox root dir, do this:\n\n```python\n>>> from functools import partial\n>>> my_dropbox_link = partial(dropbox_link, dropbox_local_rootdir='/Users/thorwhalen/Dropbox')\n```\n\nIf you want a \"direct (download) link\", do this:\n\n```python\n>>> dl1_link = my_dropbox_link('Apps/py2store/py2store_data/test.txt', dl=1)\n```\n\n    'https://www.dropbox.com/scl/fi/3o8ooqje4f497npxdeiwg/test.txt?rlkey=x9jsd8u7k147x6fzc7stxozqe&dl=1'\n\n\n## Easy read/write access to your dropbox files \n\nA persister for dropbox.\n\n```python\n>>> import json\n>>> import os\n>>> from dropboxdol import DropboxPersister\n>>> configs = json.load(open(os.path.expanduser('~/.py2store_configs.json')))\n>>> s = DropboxPersister('/py2store_data/test/', **configs['dropbox']['__init__kwargs'])\n>>> if '/py2store_data/test/_can_remove' in s:\n...     del s['/py2store_data/test/_can_remove']\n...\n>>>\n>>> n = len(s)\n>>> if n == 1:\n...     assert list(s) == ['/py2store_data/test/_can_remove']\n...\n>>> s['/py2store_data/test/_can_remove'] = b'this is a test'\n>>> assert len(s) == n + 1\n>>> assert s['/py2store_data/test/_can_remove'] == b'this is a test'\n>>> '/py2store_data/test/_can_remove' in s\nTrue\n>>> del s['/py2store_data/test/_can_remove']\n```\n\n\n",
    "bugtrack_url": null,
    "license": "apache-2.0",
    "summary": "dropbox with a simple (dict-like or list-like) interface",
    "version": "0.0.7",
    "project_urls": {
        "Homepage": "https://github.com/i2mint/dropboxdol"
    },
    "split_keywords": [
        "dropbox",
        " data access"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2c2f029de5ae20688d88234b53931c6db6238b8d533bdb455f378fdec3c89d03",
                "md5": "9d8268416c6233e9458317aa61b6ae73",
                "sha256": "932a1cb0e166e1050e4547919609d8f1998162cb00d0c9bb82617263dd934978"
            },
            "downloads": -1,
            "filename": "dropboxdol-0.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9d8268416c6233e9458317aa61b6ae73",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 20017,
            "upload_time": "2025-10-11T16:53:17",
            "upload_time_iso_8601": "2025-10-11T16:53:17.236477Z",
            "url": "https://files.pythonhosted.org/packages/2c/2f/029de5ae20688d88234b53931c6db6238b8d533bdb455f378fdec3c89d03/dropboxdol-0.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0233e96e80621ce214b0c984e1bc95a8324980ff4bdf3d89f2d6681d1635bccc",
                "md5": "2803a6fa5b1c514893eef9ff37c048bd",
                "sha256": "de01f310bf708cf35f17820455c03741454bfc9600e1bb63b7be8842571de788"
            },
            "downloads": -1,
            "filename": "dropboxdol-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "2803a6fa5b1c514893eef9ff37c048bd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 19509,
            "upload_time": "2025-10-11T16:53:18",
            "upload_time_iso_8601": "2025-10-11T16:53:18.058284Z",
            "url": "https://files.pythonhosted.org/packages/02/33/e96e80621ce214b0c984e1bc95a8324980ff4bdf3d89f2d6681d1635bccc/dropboxdol-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-11 16:53:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "i2mint",
    "github_project": "dropboxdol",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dropboxdol"
}
        
Elapsed time: 4.42875s