Code Monkey home page Code Monkey logo

habanero's Introduction

habanero

pypi Docs ghactions coverage Ruff

This is a low level client for working with Crossref's search API. It's been named to be more generic, as other organizations are/will adopt Crossref's search API, making it possible to interact with all from one client.

Crossref API docs

Other Crossref API clients:

Crossref's API issue tracker: https://gitlab.com/crossref/issues

habanero includes three modules you can import as needed (or import all):

Crossref - Crossref search API. The Crossref module includes methods matching Crossref API routes, and a few convenience methods for getting DOI agency and random DOIs:

  • works - /works route
  • members - /members route
  • prefixes - /prefixes route
  • funders - /funders route
  • journals - /journals route
  • types - /types route
  • licenses - /licenses route
  • registration_agency - get DOI minting agency
  • random_dois - get random set of DOIs

counts - citation counts. Includes the single citation_count method

cn - content negotiation. Includes the methods:

  • content_negotiation - get citations in a variety of formats
  • csl_styles - get CSL styles, used in content_negotation method

WorksContainer - A class for handling Crossref works. Pass output of works from methods on the Crossref class to more easily extract specific fields of works.

Note about searching:

You are using the Crossref search API described at https://api.crossref.org/swagger-ui/index.html. When you search with query terms, on Crossref servers they are not searching full text, or even abstracts of articles, but only what is available in the data that is returned to you. That is, they search article titles, authors, etc. For some discussion on this, see https://gitlab.com/crossref/issues/-/issues/101

Rate limits

See the headers X-Rate-Limit-Limit and X-Rate-Limit-Interval for current rate limits.

The Polite Pool

To get in the polite pool it's a good idea now to include a mailto email address. See docs for more information.

Installation

Stable version

pip (or pip3) install habanero

If you need to fix bibtex format citations using content negotiation use

pip (or pip3) install habanero[bibtex]

Dev version

pip install git+https://github.com/sckott/habanero.git#egg=habanero

Or build it yourself locally

git clone https://github.com/sckott/habanero.git
cd habanero
make install

Usage

Initialize a client

from habanero import Crossref
cr = Crossref()

Works route

# query
x = cr.works(query = "ecology")
x['message']
x['message']['total-results']
x['message']['items']

# fetch data by DOI
cr.works(ids = '10.1371/journal.pone.0033693')

Members route

# ids here is the Crossref Member ID; 98 = Hindawi
cr.members(ids = 98, works = True)

Citation counts

from habanero import counts
counts.citation_count(doi = "10.1016/j.fbr.2012.01.001")

Content negotiation - get citations in many formats

from habanero import cn
cn.content_negotiation(ids = '10.1126/science.169.3946.635')
cn.content_negotiation(ids = '10.1126/science.169.3946.635', format = "citeproc-json")
cn.content_negotiation(ids = "10.1126/science.169.3946.635", format = "rdf-xml")
cn.content_negotiation(ids = "10.1126/science.169.3946.635", format = "text")
cn.content_negotiation(ids = "10.1126/science.169.3946.635", format = "text", style = "apa")
cn.content_negotiation(ids = "10.1126/science.169.3946.635", format = "bibentry")

Meta

habanero's People

Contributors

colintalbert avatar daniel-mietchen avatar dependabot-preview[bot] avatar dependabot[bot] avatar dhimmel avatar ioverka avatar kyleniemeyer avatar radcliffe avatar sckott avatar yurivict avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

habanero's Issues

Parse http errors, to give back meaningful error messages

e.g., cr.journals(ids = "2167-8359", works = False, filter = {'from_pub_date': '2014-03-03'}) gives

HTTPError: 400 Client Error: Bad Request for url: http://api.crossref.org/journals/2167-8359?filter=from-pub-date%3A2014-03-03

But actual error is

{
  status: "failed",
  message-type: "validation-failure",
  message: [
    {
            type: "parameter-not-allowed",
            value: "filter",
            message: "This route does not support filter"
        }
    ]
}

style not functioning/not getting passed to request

I can't seem to get different citation styles to work. I think I've tracked the problem down to:
https://github.com/sckott/habanero/blob/master/habanero/cnrequest.py#L46

if I copy/duplicate the lines:
https://github.com/sckott/habanero/blob/master/habanero/cnrequest.py#L39-L40
after that line it starts working for me.

Environment: Windows 64, Python 3.4, habanero installed from: https://anaconda.org/conda-forge/habanero

I can submit a pull request if you think it worthwhile

date conversion helper

convert_crossref_date = Using the date probably important, but we need to make users convert separately, and not doing by default internally

Todo

  • agency method
  • random DOIs method
  • content negotiation
  • citation count
  • crosscite drop this, use content negotiation via dx.doi.org instead

python3 install error from pypi

~$ pip3 install habanero 

Collecting habanero
  Downloading habanero-0.1.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/private/var/folders/gs/4khph0xs0436gmd2gdnwsg080000gn/T/pip-build-cjtn36i_/habanero/setup.py", line 8, in <module>
        with codecs.open('Changelog.rst', 'r', 'utf-8') as f:
      File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/codecs.py", line 891, in open
        file = builtins.open(filename, mode, buffering)
    FileNotFoundError: [Errno 2] No such file or directory: 'Changelog.rst'

weird that it errors on a changelog file not found, but I must have done something wrong there.

note: pip install habanero works fine for python2

Funders route

make note that funders without IDs don't show up on the /funders route

Make nicer docs

Using sphinx and readthedocs now, not great right now, cleanup

library name change

Given crossref's software is cayenne, maybe habanero (don't conflict with the R and Ruby clients)

search for Title fails with KeyError: 'content-type'

import habanero
cr = habanero.Crossref()
print 'Title 1:'
title = 'On the use of fittin'
x = cr.works(query_title = title)
print len(x['message']['items'])
print 'Title 2:'
title = 'On the use of fitting'
x = cr.works(query_title = title)
print len(x['message']['items'])

The search for Title 1 works but the search for Title 2 fails with KeyError: 'content-type'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.