zenodo-client


Namezenodo-client JSON
Version 0.3.3 PyPI version JSON
download
home_pagehttps://github.com/cthoyt/zenodo-client
SummaryA wrapper for the Zenodo API.
upload_time2024-03-28 16:16:51
maintainerCharles Tapley Hoyt
docs_urlNone
authorCharles Tapley Hoyt
requires_python>=3.8
licenseMIT
keywords cookiecutter snekpack zenodo
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!--
<p align="center">
  <img src="docs/source/logo.png" height="150">
</p>
-->

<h1 align="center">
  Zenodo Client
</h1>

<p align="center">
    <a href="https://github.com/cthoyt/zenodo-client/actions/workflows/tests.yml">
        <img alt="Tests" src="https://github.com/cthoyt/zenodo-client/workflows/Tests/badge.svg" />
    </a>
    <a href="https://pypi.org/project/zenodo_client">
        <img alt="PyPI" src="https://img.shields.io/pypi/v/zenodo_client" />
    </a>
    <a href="https://pypi.org/project/zenodo_client">
        <img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/zenodo_client" />
    </a>
    <a href="https://github.com/cthoyt/zenodo-client/blob/main/LICENSE">
        <img alt="PyPI - License" src="https://img.shields.io/pypi/l/zenodo_client" />
    </a>
    <a href='https://zenodo_client.readthedocs.io/en/latest/?badge=latest'>
        <img src='https://readthedocs.org/projects/zenodo_client/badge/?version=latest' alt='Documentation Status' />
    </a>
    <a href="https://codecov.io/gh/cthoyt/zenodo-client/branch/main">
        <img src="https://codecov.io/gh/cthoyt/zenodo-client/branch/main/graph/badge.svg" alt="Codecov status" />
    </a>  
    <a href="https://github.com/cthoyt/cookiecutter-python-package">
        <img alt="Cookiecutter template from @cthoyt" src="https://img.shields.io/badge/Cookiecutter-snekpack-blue" /> 
    </a>
    <a href='https://github.com/psf/black'>
        <img src='https://img.shields.io/badge/code%20style-black-000000.svg' alt='Code style: black' />
    </a>
    <a href="https://github.com/cthoyt/zenodo-client/blob/main/.github/CODE_OF_CONDUCT.md">
        <img src="https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg" alt="Contributor Covenant"/>
    </a>
    <a href="https://zenodo.org/badge/latestdoi/343513445">
        <img src="https://zenodo.org/badge/343513445.svg" alt="DOI">
    </a>
</p>

A wrapper for the Zenodo API.

## 💪 Getting Started

The first example shows how you can set some configuration then never worry about whether it's been
uploaded already or not - all baked in with [`pystow`](https://github.com/cthoyt/pystow). On the
first time this script is run, the new deposition is made, published, and the identifier is stored
with the given key in your `~/.config/zenodo.ini`. Next time it's run, the deposition will be looked
up, and the data will be uploaded. Versioning is given automatically by date, and if multiple
versions are uploaded on one day, then a dash and the revision are appended.

```python
from zenodo_client import Creator, Metadata, ensure_zenodo

# Define the metadata that will be used on initial upload
data = Metadata(
    title='Test Upload 3',
    upload_type='dataset',
    description='test description',
    creators=[
        Creator(
            name='Hoyt, Charles Tapley',
            affiliation='Harvard Medical School',
            orcid='0000-0003-4423-4370',
        ),
    ],
)
res = ensure_zenodo(
    key='test3',  # this is a unique key you pick that will be used to store
                  # the numeric deposition ID on your local system's cache
    data=data,
    paths=[
        '/Users/cthoyt/Desktop/test1.png',
    ],
    sandbox=True,  # remove this when you're ready to upload to real Zenodo
)
from pprint import pprint

pprint(res.json())
```

A real-world example can be found here: https://github.com/cthoyt/nsockg.

The following example shows how to use the Zenodo uploader if you already know what your deposition
identifier is.

```python
from zenodo_client import update_zenodo

# The ID from your deposition
SANDBOX_DEP_ID = '724868'

# Paths to local files. Good to use in combination with resources that are always
# dumped to the same place by a given script
paths = [
    # os.path.join(DATABASE_DIRECTORY, 'alts_sample.tsv')
    '/Users/cthoyt/Desktop/alts_sample.tsv',
]

# Don't forget to set the ZENODO_API_TOKEN environment variable or
# any valid way to get zenodo/api_token from PyStow.
update_zenodo(SANDBOX_DEP_ID, paths)
```

The following example shows how to look up the latest version of a record.

```python
from zenodo_client import Zenodo

zenodo = Zenodo()
OOH_NA_NA_RECORD = '4020486'
new_record = zenodo.get_latest_record(OOH_NA_NA_RECORD)
```

Even further, the latest version of `names.tsv.gz` can be automatically downloaded to the
`~/.data/zenodo/<conceptrecid>/<version>/<path>` via `pystow` with:

```python
from zenodo_client import Zenodo

zenodo = Zenodo()
OOH_NA_NA_RECORD = '4020486'
new_record = zenodo.download_latest(OOH_NA_NA_RECORD, 'names.tsv.gz')
```

A real-world example can be found [here](https://github.com/pyobo/pyobo/blob/master/src/pyobo/resource_utils.py)
where the latest build of the [Ooh Na Na](https://cthoyt.com/2020/04/18/ooh-na-na.html) nomenclature
database is automatically downloaded from Zenodo, even though the PyOBO package only hardcodes the
first deposition ID.

### Command Line Interface

The zenodo_client command line tool is automatically installed. It can be used from the shell with
the `--help` flag to show all subcommands:

```shell
$ zenodo_client --help
```

It can be run with `zenodo_client <deposition ID> <path 1> ... <path N>`

## 🚀 Installation

The most recent release can be installed from
[PyPI](https://pypi.org/project/zenodo_client/) with:

```shell
$ pip install zenodo_client
```

The most recent code and data can be installed directly from GitHub with:

```bash
$ pip install git+https://github.com/cthoyt/zenodo-client.git
```

## 👐 Contributing

Contributions, whether filing an issue, making a pull request, or forking, are appreciated. See
[CONTRIBUTING.md](https://github.com/cthoyt/zenodo-client/blob/master/.github/CONTRIBUTING.md) for more information on getting involved.

## 👋 Attribution

### ⚖️ License

The code in this package is licensed under the MIT License.

### 🍪 Cookiecutter

This package was created with [@audreyfeldroy](https://github.com/audreyfeldroy)'s
[cookiecutter](https://github.com/cookiecutter/cookiecutter) package using [@cthoyt](https://github.com/cthoyt)'s
[cookiecutter-snekpack](https://github.com/cthoyt/cookiecutter-snekpack) template.

## 🛠️ For Developers

<details>
  <summary>See developer instructions</summary>

The final section of the README is for if you want to get involved by making a code contribution.

### Development Installation

To install in development mode, use the following:

```bash
$ git clone git+https://github.com/cthoyt/zenodo-client.git
$ cd zenodo-client
$ pip install -e .
```

### 🥼 Testing

After cloning the repository and installing `tox` with `pip install tox`, the unit tests in the `tests/` folder can be
run reproducibly with:

```shell
$ tox
```

Additionally, these tests are automatically re-run with each commit in a [GitHub Action](https://github.com/cthoyt/zenodo-client/actions?query=workflow%3ATests).

### 📖 Building the Documentation

The documentation can be built locally using the following:

```shell
$ git clone git+https://github.com/cthoyt/zenodo-client.git
$ cd zenodo-client
$ tox -e docs
$ open docs/build/html/index.html
``` 

The documentation automatically installs the package as well as the `docs`
extra specified in the [`setup.cfg`](setup.cfg). `sphinx` plugins
like `texext` can be added there. Additionally, they need to be added to the
`extensions` list in [`docs/source/conf.py`](docs/source/conf.py).

### 📦 Making a Release

After installing the package in development mode and installing
`tox` with `pip install tox`, the commands for making a new release are contained within the `finish` environment
in `tox.ini`. Run the following from the shell:

```shell
$ tox -e finish
```

This script does the following:

1. Uses [Bump2Version](https://github.com/c4urself/bump2version) to switch the version number in the `setup.cfg`,
   `src/zenodo_client/version.py`, and [`docs/source/conf.py`](docs/source/conf.py) to not have the `-dev` suffix
2. Packages the code in both a tar archive and a wheel using [`build`](https://github.com/pypa/build)
3. Uploads to PyPI using [`twine`](https://github.com/pypa/twine). Be sure to have a `.pypirc` file configured to avoid the need for manual input at this
   step
4. Push to GitHub. You'll need to make a release going with the commit where the version was bumped.
5. Bump the version to the next patch. If you made big changes and want to bump the version by minor, you can
   use `tox -e bumpversion -- minor` after.
</details>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cthoyt/zenodo-client",
    "name": "zenodo-client",
    "maintainer": "Charles Tapley Hoyt",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "cthoyt@gmail.com",
    "keywords": "cookiecutter, snekpack, Zenodo",
    "author": "Charles Tapley Hoyt",
    "author_email": "cthoyt@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d7/52/627b8e937480492d394a52a9fd80b2e549f4490b5aacc803c5477001edd4/zenodo_client-0.3.3.tar.gz",
    "platform": null,
    "description": "<!--\n<p align=\"center\">\n  <img src=\"docs/source/logo.png\" height=\"150\">\n</p>\n-->\n\n<h1 align=\"center\">\n  Zenodo Client\n</h1>\n\n<p align=\"center\">\n    <a href=\"https://github.com/cthoyt/zenodo-client/actions/workflows/tests.yml\">\n        <img alt=\"Tests\" src=\"https://github.com/cthoyt/zenodo-client/workflows/Tests/badge.svg\" />\n    </a>\n    <a href=\"https://pypi.org/project/zenodo_client\">\n        <img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/zenodo_client\" />\n    </a>\n    <a href=\"https://pypi.org/project/zenodo_client\">\n        <img alt=\"PyPI - Python Version\" src=\"https://img.shields.io/pypi/pyversions/zenodo_client\" />\n    </a>\n    <a href=\"https://github.com/cthoyt/zenodo-client/blob/main/LICENSE\">\n        <img alt=\"PyPI - License\" src=\"https://img.shields.io/pypi/l/zenodo_client\" />\n    </a>\n    <a href='https://zenodo_client.readthedocs.io/en/latest/?badge=latest'>\n        <img src='https://readthedocs.org/projects/zenodo_client/badge/?version=latest' alt='Documentation Status' />\n    </a>\n    <a href=\"https://codecov.io/gh/cthoyt/zenodo-client/branch/main\">\n        <img src=\"https://codecov.io/gh/cthoyt/zenodo-client/branch/main/graph/badge.svg\" alt=\"Codecov status\" />\n    </a>  \n    <a href=\"https://github.com/cthoyt/cookiecutter-python-package\">\n        <img alt=\"Cookiecutter template from @cthoyt\" src=\"https://img.shields.io/badge/Cookiecutter-snekpack-blue\" /> \n    </a>\n    <a href='https://github.com/psf/black'>\n        <img src='https://img.shields.io/badge/code%20style-black-000000.svg' alt='Code style: black' />\n    </a>\n    <a href=\"https://github.com/cthoyt/zenodo-client/blob/main/.github/CODE_OF_CONDUCT.md\">\n        <img src=\"https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg\" alt=\"Contributor Covenant\"/>\n    </a>\n    <a href=\"https://zenodo.org/badge/latestdoi/343513445\">\n        <img src=\"https://zenodo.org/badge/343513445.svg\" alt=\"DOI\">\n    </a>\n</p>\n\nA wrapper for the Zenodo API.\n\n## \ud83d\udcaa Getting Started\n\nThe first example shows how you can set some configuration then never worry about whether it's been\nuploaded already or not - all baked in with [`pystow`](https://github.com/cthoyt/pystow). On the\nfirst time this script is run, the new deposition is made, published, and the identifier is stored\nwith the given key in your `~/.config/zenodo.ini`. Next time it's run, the deposition will be looked\nup, and the data will be uploaded. Versioning is given automatically by date, and if multiple\nversions are uploaded on one day, then a dash and the revision are appended.\n\n```python\nfrom zenodo_client import Creator, Metadata, ensure_zenodo\n\n# Define the metadata that will be used on initial upload\ndata = Metadata(\n    title='Test Upload 3',\n    upload_type='dataset',\n    description='test description',\n    creators=[\n        Creator(\n            name='Hoyt, Charles Tapley',\n            affiliation='Harvard Medical School',\n            orcid='0000-0003-4423-4370',\n        ),\n    ],\n)\nres = ensure_zenodo(\n    key='test3',  # this is a unique key you pick that will be used to store\n                  # the numeric deposition ID on your local system's cache\n    data=data,\n    paths=[\n        '/Users/cthoyt/Desktop/test1.png',\n    ],\n    sandbox=True,  # remove this when you're ready to upload to real Zenodo\n)\nfrom pprint import pprint\n\npprint(res.json())\n```\n\nA real-world example can be found here: https://github.com/cthoyt/nsockg.\n\nThe following example shows how to use the Zenodo uploader if you already know what your deposition\nidentifier is.\n\n```python\nfrom zenodo_client import update_zenodo\n\n# The ID from your deposition\nSANDBOX_DEP_ID = '724868'\n\n# Paths to local files. Good to use in combination with resources that are always\n# dumped to the same place by a given script\npaths = [\n    # os.path.join(DATABASE_DIRECTORY, 'alts_sample.tsv')\n    '/Users/cthoyt/Desktop/alts_sample.tsv',\n]\n\n# Don't forget to set the ZENODO_API_TOKEN environment variable or\n# any valid way to get zenodo/api_token from PyStow.\nupdate_zenodo(SANDBOX_DEP_ID, paths)\n```\n\nThe following example shows how to look up the latest version of a record.\n\n```python\nfrom zenodo_client import Zenodo\n\nzenodo = Zenodo()\nOOH_NA_NA_RECORD = '4020486'\nnew_record = zenodo.get_latest_record(OOH_NA_NA_RECORD)\n```\n\nEven further, the latest version of `names.tsv.gz` can be automatically downloaded to the\n`~/.data/zenodo/<conceptrecid>/<version>/<path>` via `pystow` with:\n\n```python\nfrom zenodo_client import Zenodo\n\nzenodo = Zenodo()\nOOH_NA_NA_RECORD = '4020486'\nnew_record = zenodo.download_latest(OOH_NA_NA_RECORD, 'names.tsv.gz')\n```\n\nA real-world example can be found [here](https://github.com/pyobo/pyobo/blob/master/src/pyobo/resource_utils.py)\nwhere the latest build of the [Ooh Na Na](https://cthoyt.com/2020/04/18/ooh-na-na.html) nomenclature\ndatabase is automatically downloaded from Zenodo, even though the PyOBO package only hardcodes the\nfirst deposition ID.\n\n### Command Line Interface\n\nThe zenodo_client command line tool is automatically installed. It can be used from the shell with\nthe `--help` flag to show all subcommands:\n\n```shell\n$ zenodo_client --help\n```\n\nIt can be run with `zenodo_client <deposition ID> <path 1> ... <path N>`\n\n## \ud83d\ude80 Installation\n\nThe most recent release can be installed from\n[PyPI](https://pypi.org/project/zenodo_client/) with:\n\n```shell\n$ pip install zenodo_client\n```\n\nThe most recent code and data can be installed directly from GitHub with:\n\n```bash\n$ pip install git+https://github.com/cthoyt/zenodo-client.git\n```\n\n## \ud83d\udc50 Contributing\n\nContributions, whether filing an issue, making a pull request, or forking, are appreciated. See\n[CONTRIBUTING.md](https://github.com/cthoyt/zenodo-client/blob/master/.github/CONTRIBUTING.md) for more information on getting involved.\n\n## \ud83d\udc4b Attribution\n\n### \u2696\ufe0f License\n\nThe code in this package is licensed under the MIT License.\n\n### \ud83c\udf6a Cookiecutter\n\nThis package was created with [@audreyfeldroy](https://github.com/audreyfeldroy)'s\n[cookiecutter](https://github.com/cookiecutter/cookiecutter) package using [@cthoyt](https://github.com/cthoyt)'s\n[cookiecutter-snekpack](https://github.com/cthoyt/cookiecutter-snekpack) template.\n\n## \ud83d\udee0\ufe0f For Developers\n\n<details>\n  <summary>See developer instructions</summary>\n\nThe final section of the README is for if you want to get involved by making a code contribution.\n\n### Development Installation\n\nTo install in development mode, use the following:\n\n```bash\n$ git clone git+https://github.com/cthoyt/zenodo-client.git\n$ cd zenodo-client\n$ pip install -e .\n```\n\n### \ud83e\udd7c Testing\n\nAfter cloning the repository and installing `tox` with `pip install tox`, the unit tests in the `tests/` folder can be\nrun reproducibly with:\n\n```shell\n$ tox\n```\n\nAdditionally, these tests are automatically re-run with each commit in a [GitHub Action](https://github.com/cthoyt/zenodo-client/actions?query=workflow%3ATests).\n\n### \ud83d\udcd6 Building the Documentation\n\nThe documentation can be built locally using the following:\n\n```shell\n$ git clone git+https://github.com/cthoyt/zenodo-client.git\n$ cd zenodo-client\n$ tox -e docs\n$ open docs/build/html/index.html\n``` \n\nThe documentation automatically installs the package as well as the `docs`\nextra specified in the [`setup.cfg`](setup.cfg). `sphinx` plugins\nlike `texext` can be added there. Additionally, they need to be added to the\n`extensions` list in [`docs/source/conf.py`](docs/source/conf.py).\n\n### \ud83d\udce6 Making a Release\n\nAfter installing the package in development mode and installing\n`tox` with `pip install tox`, the commands for making a new release are contained within the `finish` environment\nin `tox.ini`. Run the following from the shell:\n\n```shell\n$ tox -e finish\n```\n\nThis script does the following:\n\n1. Uses [Bump2Version](https://github.com/c4urself/bump2version) to switch the version number in the `setup.cfg`,\n   `src/zenodo_client/version.py`, and [`docs/source/conf.py`](docs/source/conf.py) to not have the `-dev` suffix\n2. Packages the code in both a tar archive and a wheel using [`build`](https://github.com/pypa/build)\n3. Uploads to PyPI using [`twine`](https://github.com/pypa/twine). Be sure to have a `.pypirc` file configured to avoid the need for manual input at this\n   step\n4. Push to GitHub. You'll need to make a release going with the commit where the version was bumped.\n5. Bump the version to the next patch. If you made big changes and want to bump the version by minor, you can\n   use `tox -e bumpversion -- minor` after.\n</details>\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A wrapper for the Zenodo API.",
    "version": "0.3.3",
    "project_urls": {
        "Documentation": "https://zenodo_client.readthedocs.io",
        "Download": "https://github.com/cthoyt/zenodo-client/releases",
        "Homepage": "https://github.com/cthoyt/zenodo-client",
        "Source": "https://github.com/cthoyt/zenodo-client",
        "Tracker": "https://github.com/cthoyt/zenodo-client/issues"
    },
    "split_keywords": [
        "cookiecutter",
        " snekpack",
        " zenodo"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "377999d069be7318a12c3f986164afe7f5430c7565182e86dd3e47ec42f40db2",
                "md5": "3e1e8fdb36d914773e4133b47ed7e1d3",
                "sha256": "c24362691bd29f98275dcea57fb8bf3713cc8e8cc914200b286be0fdc5d8d04c"
            },
            "downloads": -1,
            "filename": "zenodo_client-0.3.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3e1e8fdb36d914773e4133b47ed7e1d3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 13987,
            "upload_time": "2024-03-28T16:16:48",
            "upload_time_iso_8601": "2024-03-28T16:16:48.942562Z",
            "url": "https://files.pythonhosted.org/packages/37/79/99d069be7318a12c3f986164afe7f5430c7565182e86dd3e47ec42f40db2/zenodo_client-0.3.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d752627b8e937480492d394a52a9fd80b2e549f4490b5aacc803c5477001edd4",
                "md5": "a5e4cc13449f77db7c8f07cab32494cc",
                "sha256": "b3a4a55805d79960d26a21de2daf06ff1a7082802c89b950ad594586609643e5"
            },
            "downloads": -1,
            "filename": "zenodo_client-0.3.3.tar.gz",
            "has_sig": false,
            "md5_digest": "a5e4cc13449f77db7c8f07cab32494cc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 21602,
            "upload_time": "2024-03-28T16:16:51",
            "upload_time_iso_8601": "2024-03-28T16:16:51.068358Z",
            "url": "https://files.pythonhosted.org/packages/d7/52/627b8e937480492d394a52a9fd80b2e549f4490b5aacc803c5477001edd4/zenodo_client-0.3.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-28 16:16:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cthoyt",
    "github_project": "zenodo-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "zenodo-client"
}
        
Elapsed time: 0.22148s