Package: pytacite
pytacitePytacite is a Python library forDataCite. DataCite is a non-profit organisation that provides persistent identifiers (DOIs) for research data and other research outputs. It holds a large index of metadata of outputs. DataCite offers an open and freeREST APIto query metadata.
Pytacite is a lightweight and thin Python interface to this API. Pytacite aims to
stay as close as possible to the design of the original service.The following features of DataCite are currently supported by pytacite:Get single entitiesFilter and query entitiesSort entitiesSample entitiesPaginationUsage reportsAuthenticationSide-load associations with includeWe aim to cover the entire API, and we are looking for help. We are welcoming Pull Requests.Key featuresPipe operations- pytacite can handle multiple operations in a sequence. This allows the developer to write understandable queries. For examples, seecode snippets.Permissive license-DataCite data is CC0 licensed:raised_hands:. pytacite is published under the MIT license.Installationpytacite requires Python 3.8 or later.pipinstallpytaciteGetting startedPytacite offers support for:DOIs,Clients,ClientPrefixes,Events,Prefixes,Providers, andProviderPrefixes.frompytaciteimportDOIs,Clients,Events,Prefixes,ClientPrefixes,Providers,ProviderPrefixesGet single entityGet a single DOI, Event, Prefix, ProviderPrefix from DataCite by the id.DOIs()["10.14454/FXWS-0523"]The result is aDOIobject, which is very similar to a dictionary. Find the
available fields with.keys(). Most interesting attributes are stored in
the"attributes"field.For example, get the titles:DOIs()["10.14454/FXWS-0523"]["attributes"]["titles"][{'title':'DataCite Metadata Schema for the Publication and Citation of Research Data and Other Research Outputs v4.4'}]It works similar for other resource collections.Prefixes()["10.12682"]Events()["9a34e232-5b30-453b-a393-ea10a6ce565d"]Get lists of entitiesresults=DOIs().get()For lists of entities, you can alsocountthe number of records found
instead of returning the results. This also works for search queries and
filters.DOIs().count()# 50869984For lists of entities, you can return the result as well as the metadata. By default, only the results are returned.results,meta=DOIs().get(return_meta=True)print(meta){'total':50869984,'totalPages':400,'page':1,'states':[{'id':'findable','title':'Findable','count':50869984}],'resourceTypes':[{'id':'dataset','title':'Dataset','count':15426144},<...>]<...>'subjects':[{'id':'FOS: Biological sciences','title':'Fos: Biological Sciences','count':3304486},<...>],'citations':[],'views':[],'downloads':[]}Filters and queriesDataCite makes use of filter and queries. Filters can narrow down queries(~.~)and queries can help to search fields. See:Filtering:https://support.datacite.org/docs/api-queries#filtering-list-responsesMaking Queries:https://support.datacite.org/docs/api-queries#making-queriesThe following example returns records created in the year 2020 on Dryad.DOIs().filter(created=2020,client_id="dryad.dryad").get()which is identical to:DOIs().filter(created=2020).filter(client_id="dryad.dryad").get()Queries can work in a similar fashion and can be applied to all fields. For example, search for records withclimate changein the title.DOIs().query("climate change").get()Important to note, this returnsa list of all the DOI records that contain the phrasesclimateandchangein their metadata(potential mistake in DataCite documentation).Nested attribute filtersSome attribute filters are nested and separated with dots by DataCite. For
example, filter oncreators.nameIdentifiers.nameIdentifierScheme.In case of nested attribute filters, use a dict to build the query.DOIs()\.query(creators={"nameIdentifiers":{"nameIdentifierScheme":"ORCID"}})\.query(publicationYear=2016)\.query(language="es")\.count()# 562Sort entity listsClients().sort("created",ascending=True).get()Logical expressionsSee DataCite onlogical operatorslike AND, OR, and NOT.PagingDataCite offers two methods for paging:basic pagingandcursor paging. Both methods are supported by
pytacite.Basic (offset) pagingOnly the first 10,000 records can be retrieved with basic (offset)paging.pager=DOIs().filter(prefix="10.5438").paginate(method="number",per_page=100)forpageinpager:print(len(page))Cursor pagingUsepaginate()for paging results. By default,paginates argumentn_maxis set to 10000. UseNoneto retrieve all results.pager=DOIs().filter(prefix="10.5438").paginate(per_page=100)forpageinpager:print(len(page))Looking for an easy method to iterate the records of a pager?fromitertoolsimportchainfrompytaciteimportDOIsquery=DOIs().filter(prefix="10.5438")forrecordinchain(*query.paginate(per_page=100)):print(record["id"])Get random DOIsGetrandom DOIs. Somehow, this has very slow response times (caused by DataCite).DOIs().random().get(per_page=10)Code snippetsA list of awesome use cases of the DataCite dataset.Creators of a datasetfrompytaciteimportDOIsw=DOIs()["10.34894/HE6NAQ"]w["attributes"]["creators"]Get the works of a single creatorWork in progress: get rid of quotes.DOIs()\.query(creators={"nameIdentifiers":{"nameIdentifier":"\"https://orcid.org/0000-0001-7736-2091\""}})\.get()Software published on Zenodo in 2016Resources:https://support.datacite.org/reference/get_clientshttps://support.datacite.org/reference/get_doisGet the DataCite identifier of the client first:frompytaciteimportClientsc=Clients().query("Zenodo").get()print(c[0]["id"])# cern.zenodoFilter the DOIs on the client identifier. It can be a bit confusing when to usefilterandqueryhere.DOIs()\.filter(client_id=c[0]["id"])\.filter(resource_type_id="software")\.query(publicationYear=2016)\.get()# 9720Number of repositories running on Dataverse softwarefrompytaciteimportClientsClients()\.filter(software="dataverse")\.count()# 31Alternativesdataciteis a nice Python wrapper for Metadata Store API which is not covered by pytacite.R users can useRDataCitelibrary.LicenseMITContactThis library is a community contribution. The authors of this Python library aren't affiliated with DataCite.Feel free to reach out with questions, remarks, and suggestions. Theissue trackeris a good starting point. You can also email me atjonathandebruinos@gmail.com.