Skip to main content

Crossref Commons

High-level library for getting data from Crossref APIs (REST, XML, ...). Work in progress.

Installation

pip3 install crossref-commons

Usage

Retrieving entities

Entities of various types can be retrieved by giving their respective IDs:

import crossref_commons.retrieval

crossref_commons.retrieval.get_publication_as_json('10.5621/sciefictstud.40.2.0382')
crossref_commons.retrieval.get_publication_as_xml('10.5621/sciefictstud.40.2.0382')
crossref_commons.retrieval.get_publication_as_refstring('10.5621/sciefictstud.40.2.0382', 'ieee')

crossref_commons.retrieval.get_member_as_json('15')

Equivalently, you can use get_entity function to retrieve any type of entity:

from crossref_commons.retrieval import get_entity
from crossref_commons.types import EntityType, OutputType

get_entity('10.5621/sciefictstud.40.2.0382', EntityType.PUBLICATION, OutputType.JSON)
get_entity('10.5621/sciefictstud.40.2.0382', EntityType.PUBLICATION, OutputType.XML)
get_entity('10.5621/sciefictstud.40.2.0382', EntityType.PUBLICATION, OutputType.REFSTRING, 'ieee')

get_entity('15', EntityType.MEMBER, OutputType.JSON)

Retrieving relations

Currently, aliases and general relations are supported:

from crossref_commons.relations import get_related

get_related('10.1167/18.8.6')

Iterating

It is possible to iterate over publications meeting specific criteria (JSON only):

from crossref_commons.iteration import iterate_publications_as_json

filter = {'funder': '10.13039/501100000038', 'type': 'journal-article'}
queries = {'query.author': 'li', 'query.affiliation': 'university'}
for p in iterate_publications_as_json(max_results=189, filter=filter, queries=queries):
  print(p['DOI'])

Sampling

Instead of iterating over the items meeting the criteria, in some cases it is better to use a random sample. get_sample will automatically handle sizes larger than Crossref REST API's limit of 100:

from crossref_commons.sampling import get_sample

filter = {'funder': '10.13039/501100000038', 'type': 'journal-article'}
queries = {'query.author': 'li', 'query.affiliation': 'university'}
sample = get_sample(size=121, filter=filter, queries=queries)

Searching

If publications should be searched for by various fields instead of DOI, the search module can be used. The query can either be supplied as a string following the Crossref REST API's syntax or as a list of (key, value) pairs, where the key specifies the field to search in, and the value is the value to search for. See the crossref API documentation for the list of available field names (but omit the query. prefix).

>>> from crossref_commons.search import search_publication
>>> (count, results) = search_publication((("author", "richard feynman"), ("bibliographic", "what is science")), sort="score", order="desc")
>>> print(count)
45837
>>> print(results[0]['title'])
['What is science?']

Authorization

You can set the Polite information and/or Plus token by creating a file ~/.crapi_key with the following content:

{
  "Crossref-Plus-API-Token": "<<Plus API token, for Plus users only>>",
  "User-Agent": "<<polite user agent; including mailto:email address>>",
  "Mailto": "<<email address>>"
}

Alternatively, the same information can be provided through environment variables CR_API_PLUS, CR_API_AGENT and CR_API_MAILTO.

Metadata

Release files for crossref-commons-reverse 0.0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crossref-commons-reverse 0.0.7.1
File Size Uploaded
crossref_commons_reverse-0.0.7.1.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for crossref-commons-reverse 0.0.7.1
File Interpreter ABI Platform
crossref_commons_reverse-0.0.7.1-py3-none-any.whl Python 3 none any Details

Total release size: 25.1 kB

Release files / crossref_commons_reverse-0.0.7.1.tar.gz

Download URL crossref_commons_reverse-0.0.7.1.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
04c2843c3fc91c8589820cedf49471346411996a8efaee542983cddfbfee814c
BLAKE2b-256 checksum
How to use checksums
741e532d9c26e9e405cb5f017693c2c75cb746cfae152f1bd4692345b769a4bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.5

Release files / crossref_commons_reverse-0.0.7.1-py3-none-any.whl

Download URL crossref_commons_reverse-0.0.7.1-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba5e3680d1fdb95e2caf0ad2e910d81fbb9eeb48fa36b70f9af192d57c6cac92
BLAKE2b-256 checksum
How to use checksums
06952fa20a08a8c368741a5d588cc8f3eca7a426bcc5b81b725d39ca2565ad90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

0.0.7.1 This release

2 release 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