Skip to main content

A lightweight Python API for Hypothes.is

Project description

docs/logos/embopress.png

Hypothepy

https://img.shields.io/pypi/v/hypothepy.svg https://img.shields.io/travis/embo-press/hypothepy.svg Documentation Status Updates

A lightweight Python API for Hypothes.is

Features

  • Light Python interface for all the REST endpoints available.

    • API parameters are simple native python types

    • API calls just return a requests.Response object

    • provides handy helpers

  • Python 3.6+

  • Only version 1 (stable) implemented (for the moment)

  • Only APIKey Authentication implemented (for the moment)

  • Command line interface (cooming soon)

Examples of Usage

from hypothepy.v1.api import HypoApi
hypo = HypoApi(
    api_key='YOUR PERSONAL API KEY',
    user_name='YOUR USER NAME'
)
hypo.annotations.search(user='EMBO')

Helpers

hypothepy provides a set of helpers to facilitate creating additional objects requiered by hypothes.is API

helpers.documents

Allows to create a new document objects that you can directly pass as a parameter to api calls:

from hypothepy.v1.api import HypoApi

hypo = HypoApi()
document = hypo.helpers.documents(title='My Title') # => { 'title': 'My Title' }
hypo.annotations.create(
    # ...
    document=document,
)

helpers.permissions

Similarly to documents, helpers.permissions allows is a handy shortcut for creating permissions objects:

from hypothepy.v1.api import HypoApi

hypo = HypoApi()
hypo.helpers.permissions(
    read   = ['group:__world__'],
    update = ['acct:YOUR USER NAME@hypothes.is'],
    delete = ['acct:YOUR USER NAME@hypothes.is'],
    admin  = ['acct:YOUR USER NAME@hypothes.is'],
)

This example above is such a common pattern that hypo provides a preset shortcut for it under helpers.permissions.READ_ALL:

hypo.helpers.permissions.READ_ALL # => {
                                  #     'read': ['group:__world__'],
                                  #     'update': ['acct:YOUR USER NAME@hypothes.is'],
                                  #     'delete': ['acct:YOUR USER NAME@hypothes.is'],
                                  #     'admin': ['acct:YOUR USER NAME@hypothes.is'],
                                  # }

This is useful when you are, for example, creating new annotations:

hypo.annotations.create(
    uri='http://www.embo.org',
    permissions=hypo.helpers.permissions.READ_ALL,
    # ...
)

History

0.2.0 (2019-08-28)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hypothepy-0.2.1.tar.gz (22.1 kB view hashes)

Uploaded Source

Built Distribution

hypothepy-0.2.1-py2.py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page