orcid


Nameorcid JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://github.com/ORCID/python-orcid
SummaryA python wrapper over the ORCID API
upload_time2018-07-17 08:02:25
maintainer
docs_urlNone
authorMateusz Susik
requires_python
licenseBSD
keywords orcid api wrapper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            python-orcid
============

.. image:: https://badges.gitter.im/ORCID/python-orcid.svg
   :alt: Join the chat at https://gitter.im/ORCID/python-orcid
   :target: https://gitter.im/ORCID/python-orcid?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge

.. image:: https://img.shields.io/travis/ORCID/python-orcid.svg?style=flat-square
  :target: https://travis-ci.org/ORCID/python-orcid
.. image:: https://img.shields.io/coveralls/ORCID/python-orcid.svg?style=flat-square
  :target: https://coveralls.io/r/ORCID/python-orcid?branch=master
.. image:: https://img.shields.io/pypi/l/orcid.svg?style=flat-square
  :target: https://pypi.python.org/pypi/orcid/
.. image:: https://img.shields.io/badge/status-beta-red.svg?style=flat-square
  :target: https://pypi.python.org/pypi/orcid/

Authors
-------

Mateusz Susik <mateuszsusik@gmail.com>

Installation
------------

.. code-block:: bash

    pip install orcid


Notes
-----

This README might be slightly outdated. You can help by submitting a pull request.

Exception handling
--------------

The methods of this library might throw client or server errors. An error is 
an exception coming from the proven
`requests <http://docs.python-requests.org/en/latest/>`_ library. The usual
way to work with them should be:

.. code-block:: python
  
    from requests import RequestException
    import orcid
    api = orcid.MemberAPI(key, secret, sandbox=True)
    try:
        api.add_record(author-orcid, token, 'work',
                       {'title': 'Title', 'type': 'artistic-performance'})
    except RequestException as e:
        # Here the error should be handled. As the exception message might be
        # too generic, additional info can be obtained by:
        print(e.response.text)
        # The response is a requests Response instance.


Introduction
------------

`ORCID <http://orcid.org/>`_ is an open, non-profit, community-based effort to
provide a registry of unique researcher identifiers and a transparent method
of linking research activities and outputs to these identifiers. ORCID is
unique in its ability to reach across disciplines, research sectors, and
national boundaries and its cooperation with other identifier systems.

ORCID offers an API (Application Programming Interface) that allows your
systems and applications to connect to the ORCID registry, including reading
from and writing to ORCID records.

There are two types of API available for developers.


PublicAPI
=========

The public API allows the developers to use the search engine and read author
records. In order to use it, you need to pass institution's key and secret.

The functionality of this API is also available in the member API.

Token
-----

In order to read or update records, the ``token`` is needed. The tokens come
from OAuth 3-legged authorization. You can perform the authorization using
this library (examples below).

However, if the user is already connected to ORCiD and authenticated (so you
have an authorization code), this process can be simplified:

.. code-block:: python

    import orcid
    api = orcid.PublicAPI(institution_key, institution_secret, sandbox=True)
    token = api.get_token_from_authorization_code(authorization_code,
                                                  redirect_uri)

A special case are the tokens for performing search queries. Such queries
do not need user authentication, only institution credentials are needed.

.. code-block:: python

    import orcid
    api = orcid.PublicAPI(institution_key, institution_secret, sandbox=True)
    search_token = api.get_search_token_from_orcid()

By reusing the same token, the search functions will run faster skipping
the authentication process.


Searching
---------

.. code-block:: python

    import orcid
    api = orcid.PublicAPI(institution_key, institution_secret, sandbox=True)
    search_results = api.search('text:English', access_token=Token)


While creating a search query, it is possible to use a generator in
order to reduce time needed to fetch a record.

.. code-block:: python

    search_results = api.search_generator('text:English',
                                          pagination=20)
    first_result = next(search_results)


Reading records
---------------

.. code-block:: python

    import orcid
    api = orcid.PublicAPI(institution_key, institution_secret, sandbox=True)
    search_results = api.search_public('text:English')
    # Get the summary
    token = api.get_token(user_id, user_password, redirect_uri)
    summary = api.read_record_public('0000-0001-1111-1111', 'activities',
                                     token)
    summary = api.read_record_public('0000-0001-1111-1111', 'record',
                                     token)


Every record in the `summary` dictionary should contain *put-codes*. Using
them, it is possible to query the specific record for details. Type of the
record and the put-code need to be provided.

.. code-block:: python

    # Get the specific record
    work = api.read_record_public('0000-0001-1111-1111', 'work', token,
                                  '1111')

An exception is made for ``works`` `request_type`. It is possible to
fetch multiple selected works at once by selecting multiple
``put_codes`` in a list.

.. code-block:: python

    work = api.read_record_public('0000-0001-1111-1111', 'works', token,
                                  ['1111', '2222', '3333'])

Additional utilities
--------------------

Python-orcid offers a function for creating a login/register URL.

.. code-block:: python

    url = api.get_login_url('/authenticate', redirect_uri, email=email)


MemberAPI
=========

The member API allows the developers to add/change/remove records.
To modify the records one needs a token which can be obtained following
the OAuth 3-legged authorization process.

The member API lets the developer obtain more information when using the
search API or fetching the records.

To create an instance of the member API handler, the institution key and the
institution secret have to be provided.

.. code-block:: python

    import orcid
    api = orcid.MemberAPI(institution_key, institution_secret,
                          sandbox=True)
    search_results = api.search('text:English')
    # Get the summary
    token = api.get_token(user_id, user_password, redirect_uri,
                          '/read-limited')
    summary = api.read_record_member('0000-0001-1111-1111', 'activities',
                                     token)

All the methods from the public API are available in the member API.

Getting ORCID
-------------

If the ORCID of an author is not known, one can obtain it by authorizing the
user:

.. code-block:: python

    orcid = api.get_user_orcid(user_id, password, redirect_uri)


Adding/updating/removing records
--------------------------------

Using the member API, one can add/update/remove records from the ORCID profile.

All the types of records are supported.

.. code-block:: python

    put_code = api.add_record(author-orcid, token, 'work', json)
    # Change the type to 'other'
    api.update_record(author-orcid, token, 'work', put-code,
                      {'type': 'OTHER'})
    api.remove_record(author-orcid, token, 'work', put-code)


The ``token`` is the string received from OAuth 3-legged authorization.

The last argument is the record itself. The record should
follow ORCID's JSON records definitions. Here is an
example of a dictionary that can be passed as an argument:

.. code-block:: python

    {
      "title": {
        "title": {
          "value": "Work # 1"
        },
        "subtitle": null,
        "translated-title": null
      },
      "journal-title": {
        "value": "journal # 1"
      },
      "short-description": null,
      "type": "JOURNAL_ARTICLE",
      "external-ids": {
        "external-id": [{
          "external-id-type": "doi",
          "external-id-value": "ext-id-1",
          "external-id-url": {
            "value": "http://dx.doi.org/ext-id-1"
          },
          "external-id-relationship": "SELF"
        }]
      }
    }

If you do not know how to structure your JSON, visit
`ORCID swagger <https://api.orcid.org/v2.0>`_

It is possible to update many works in the same time!
Us ``works`` request type and pass a JSON like this one:

.. code-block:: python

  "bulk": [
  {
    "work": {
      "title": {
        "title": {
          "value": "Work # 1"
        },
      },
      "journal-title": {
        "value": "journal # 1"
      },
      "type": "JOURNAL_ARTICLE",
      "external-ids": {
        "external-id": [{
          "external-id-type": "doi",
          "external-id-value": "ext-id-1",
          "external-id-url": {
            "value": "http://dx.doi.org/ext-id-1"
          },
          "external-id-relationship": "SELF"
        }]
      }
    }
  },
  {
    "work": {
      "title": {
        "title": {
          "value": "Work # 2"
        },
      },
      "journal-title": {
        "value": "journal # 2"
      },
      "type": "JOURNAL_ARTICLE",
      "external-ids": {
        "external-id": [{
          "external-id-type": "doi",
          "external-id-value": "ext-id-2",
          "external-id-url": {
            "value": "http://dx.doi.org/ext-id-2"
          },
          "external-id-relationship": "SELF"
        }]
      }
    }
  }
  ]
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ORCID/python-orcid",
    "name": "orcid",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "orcid,api,wrapper",
    "author": "Mateusz Susik",
    "author_email": "mateuszsusik@protonmail.ch",
    "download_url": "https://files.pythonhosted.org/packages/fe/d7/a065d914f1312abc02c3dcaecd75bcbb8d03062db33991cfcc9f37b93da6/orcid-1.0.3.tar.gz",
    "platform": "",
    "description": "python-orcid\n============\n\n.. image:: https://badges.gitter.im/ORCID/python-orcid.svg\n   :alt: Join the chat at https://gitter.im/ORCID/python-orcid\n   :target: https://gitter.im/ORCID/python-orcid?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge\n\n.. image:: https://img.shields.io/travis/ORCID/python-orcid.svg?style=flat-square\n  :target: https://travis-ci.org/ORCID/python-orcid\n.. image:: https://img.shields.io/coveralls/ORCID/python-orcid.svg?style=flat-square\n  :target: https://coveralls.io/r/ORCID/python-orcid?branch=master\n.. image:: https://img.shields.io/pypi/l/orcid.svg?style=flat-square\n  :target: https://pypi.python.org/pypi/orcid/\n.. image:: https://img.shields.io/badge/status-beta-red.svg?style=flat-square\n  :target: https://pypi.python.org/pypi/orcid/\n\nAuthors\n-------\n\nMateusz Susik <mateuszsusik@gmail.com>\n\nInstallation\n------------\n\n.. code-block:: bash\n\n    pip install orcid\n\n\nNotes\n-----\n\nThis README might be slightly outdated. You can help by submitting a pull request.\n\nException handling\n--------------\n\nThe methods of this library might throw client or server errors. An error is \nan exception coming from the proven\n`requests <http://docs.python-requests.org/en/latest/>`_ library. The usual\nway to work with them should be:\n\n.. code-block:: python\n  \n    from requests import RequestException\n    import orcid\n    api = orcid.MemberAPI(key, secret, sandbox=True)\n    try:\n        api.add_record(author-orcid, token, 'work',\n                       {'title': 'Title', 'type': 'artistic-performance'})\n    except RequestException as e:\n        # Here the error should be handled. As the exception message might be\n        # too generic, additional info can be obtained by:\n        print(e.response.text)\n        # The response is a requests Response instance.\n\n\nIntroduction\n------------\n\n`ORCID <http://orcid.org/>`_ is an open, non-profit, community-based effort to\nprovide a registry of unique researcher identifiers and a transparent method\nof linking research activities and outputs to these identifiers. ORCID is\nunique in its ability to reach across disciplines, research sectors, and\nnational boundaries and its cooperation with other identifier systems.\n\nORCID offers an API (Application Programming Interface) that allows your\nsystems and applications to connect to the ORCID registry, including reading\nfrom and writing to ORCID records.\n\nThere are two types of API available for developers.\n\n\nPublicAPI\n=========\n\nThe public API allows the developers to use the search engine and read author\nrecords. In order to use it, you need to pass institution's key and secret.\n\nThe functionality of this API is also available in the member API.\n\nToken\n-----\n\nIn order to read or update records, the ``token`` is needed. The tokens come\nfrom OAuth 3-legged authorization. You can perform the authorization using\nthis library (examples below).\n\nHowever, if the user is already connected to ORCiD and authenticated (so you\nhave an authorization code), this process can be simplified:\n\n.. code-block:: python\n\n    import orcid\n    api = orcid.PublicAPI(institution_key, institution_secret, sandbox=True)\n    token = api.get_token_from_authorization_code(authorization_code,\n                                                  redirect_uri)\n\nA special case are the tokens for performing search queries. Such queries\ndo not need user authentication, only institution credentials are needed.\n\n.. code-block:: python\n\n    import orcid\n    api = orcid.PublicAPI(institution_key, institution_secret, sandbox=True)\n    search_token = api.get_search_token_from_orcid()\n\nBy reusing the same token, the search functions will run faster skipping\nthe authentication process.\n\n\nSearching\n---------\n\n.. code-block:: python\n\n    import orcid\n    api = orcid.PublicAPI(institution_key, institution_secret, sandbox=True)\n    search_results = api.search('text:English', access_token=Token)\n\n\nWhile creating a search query, it is possible to use a generator in\norder to reduce time needed to fetch a record.\n\n.. code-block:: python\n\n    search_results = api.search_generator('text:English',\n                                          pagination=20)\n    first_result = next(search_results)\n\n\nReading records\n---------------\n\n.. code-block:: python\n\n    import orcid\n    api = orcid.PublicAPI(institution_key, institution_secret, sandbox=True)\n    search_results = api.search_public('text:English')\n    # Get the summary\n    token = api.get_token(user_id, user_password, redirect_uri)\n    summary = api.read_record_public('0000-0001-1111-1111', 'activities',\n                                     token)\n    summary = api.read_record_public('0000-0001-1111-1111', 'record',\n                                     token)\n\n\nEvery record in the `summary` dictionary should contain *put-codes*. Using\nthem, it is possible to query the specific record for details. Type of the\nrecord and the put-code need to be provided.\n\n.. code-block:: python\n\n    # Get the specific record\n    work = api.read_record_public('0000-0001-1111-1111', 'work', token,\n                                  '1111')\n\nAn exception is made for ``works`` `request_type`. It is possible to\nfetch multiple selected works at once by selecting multiple\n``put_codes`` in a list.\n\n.. code-block:: python\n\n    work = api.read_record_public('0000-0001-1111-1111', 'works', token,\n                                  ['1111', '2222', '3333'])\n\nAdditional utilities\n--------------------\n\nPython-orcid offers a function for creating a login/register URL.\n\n.. code-block:: python\n\n    url = api.get_login_url('/authenticate', redirect_uri, email=email)\n\n\nMemberAPI\n=========\n\nThe member API allows the developers to add/change/remove records.\nTo modify the records one needs a token which can be obtained following\nthe OAuth 3-legged authorization process.\n\nThe member API lets the developer obtain more information when using the\nsearch API or fetching the records.\n\nTo create an instance of the member API handler, the institution key and the\ninstitution secret have to be provided.\n\n.. code-block:: python\n\n    import orcid\n    api = orcid.MemberAPI(institution_key, institution_secret,\n                          sandbox=True)\n    search_results = api.search('text:English')\n    # Get the summary\n    token = api.get_token(user_id, user_password, redirect_uri,\n                          '/read-limited')\n    summary = api.read_record_member('0000-0001-1111-1111', 'activities',\n                                     token)\n\nAll the methods from the public API are available in the member API.\n\nGetting ORCID\n-------------\n\nIf the ORCID of an author is not known, one can obtain it by authorizing the\nuser:\n\n.. code-block:: python\n\n    orcid = api.get_user_orcid(user_id, password, redirect_uri)\n\n\nAdding/updating/removing records\n--------------------------------\n\nUsing the member API, one can add/update/remove records from the ORCID profile.\n\nAll the types of records are supported.\n\n.. code-block:: python\n\n    put_code = api.add_record(author-orcid, token, 'work', json)\n    # Change the type to 'other'\n    api.update_record(author-orcid, token, 'work', put-code,\n                      {'type': 'OTHER'})\n    api.remove_record(author-orcid, token, 'work', put-code)\n\n\nThe ``token`` is the string received from OAuth 3-legged authorization.\n\nThe last argument is the record itself. The record should\nfollow ORCID's JSON records definitions. Here is an\nexample of a dictionary that can be passed as an argument:\n\n.. code-block:: python\n\n    {\n      \"title\": {\n        \"title\": {\n          \"value\": \"Work # 1\"\n        },\n        \"subtitle\": null,\n        \"translated-title\": null\n      },\n      \"journal-title\": {\n        \"value\": \"journal # 1\"\n      },\n      \"short-description\": null,\n      \"type\": \"JOURNAL_ARTICLE\",\n      \"external-ids\": {\n        \"external-id\": [{\n          \"external-id-type\": \"doi\",\n          \"external-id-value\": \"ext-id-1\",\n          \"external-id-url\": {\n            \"value\": \"http://dx.doi.org/ext-id-1\"\n          },\n          \"external-id-relationship\": \"SELF\"\n        }]\n      }\n    }\n\nIf you do not know how to structure your JSON, visit\n`ORCID swagger <https://api.orcid.org/v2.0>`_\n\nIt is possible to update many works in the same time!\nUs ``works`` request type and pass a JSON like this one:\n\n.. code-block:: python\n\n  \"bulk\": [\n  {\n    \"work\": {\n      \"title\": {\n        \"title\": {\n          \"value\": \"Work # 1\"\n        },\n      },\n      \"journal-title\": {\n        \"value\": \"journal # 1\"\n      },\n      \"type\": \"JOURNAL_ARTICLE\",\n      \"external-ids\": {\n        \"external-id\": [{\n          \"external-id-type\": \"doi\",\n          \"external-id-value\": \"ext-id-1\",\n          \"external-id-url\": {\n            \"value\": \"http://dx.doi.org/ext-id-1\"\n          },\n          \"external-id-relationship\": \"SELF\"\n        }]\n      }\n    }\n  },\n  {\n    \"work\": {\n      \"title\": {\n        \"title\": {\n          \"value\": \"Work # 2\"\n        },\n      },\n      \"journal-title\": {\n        \"value\": \"journal # 2\"\n      },\n      \"type\": \"JOURNAL_ARTICLE\",\n      \"external-ids\": {\n        \"external-id\": [{\n          \"external-id-type\": \"doi\",\n          \"external-id-value\": \"ext-id-2\",\n          \"external-id-url\": {\n            \"value\": \"http://dx.doi.org/ext-id-2\"\n          },\n          \"external-id-relationship\": \"SELF\"\n        }]\n      }\n    }\n  }\n  ]",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "A python wrapper over the ORCID API",
    "version": "1.0.3",
    "project_urls": {
        "Homepage": "https://github.com/ORCID/python-orcid"
    },
    "split_keywords": [
        "orcid",
        "api",
        "wrapper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fed7a065d914f1312abc02c3dcaecd75bcbb8d03062db33991cfcc9f37b93da6",
                "md5": "004f2ea940166a5e1dca84ee9f78968a",
                "sha256": "5fe28b6d92aed5abe7145c959e4fa2afb90260be215ff3f36ad31c94ee41d0db"
            },
            "downloads": -1,
            "filename": "orcid-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "004f2ea940166a5e1dca84ee9f78968a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10768,
            "upload_time": "2018-07-17T08:02:25",
            "upload_time_iso_8601": "2018-07-17T08:02:25.143563Z",
            "url": "https://files.pythonhosted.org/packages/fe/d7/a065d914f1312abc02c3dcaecd75bcbb8d03062db33991cfcc9f37b93da6/orcid-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2018-07-17 08:02:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ORCID",
    "github_project": "python-orcid",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "lcname": "orcid"
}
        
Elapsed time: 0.08990s