Skip to main content

Python package for Hypothesis (http://hypothes.is)

This package provides python bindings to the Hypothesis API.

Low-level access

The api submodule is a low-level implementation of the Hypothesis API.

The contents of this module reflect the REST nature of the API:

  • API calls are made by functions.

  • Input and output data are uninterpreted data (e.g. JSON strings, not objects resulting from interpreting the JSON).

  • Argument checking is minimal and most exceptions will come when the API returns an error (APIError is raised if the server does not return 200).

  • The auth argument is always given first (except to root(), which does not take authorization). auth can currently be None or a string containing a developer token.

Examples:

>>> h_annot.api.read(None, '53LMZGVCEemN4zOvm3oFEQ')
u'{"updated": "2019-04-22T21:09:23.352503+00:00", "group": "__world__", ...
>>> h_annot.api.read(None, 'bogusannotationid')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "h_annot/api.py", line 39, in read
    raise APIError(r)
h_annot.exceptions.APIError: API call returned 404 (Not Found): not_found

High-level access

The Annotation class is an object abstraction of an annotation. Use the load() class method to get an annotation from its ID:

>>> annot = h_annot.Annotation.load('53LMZGVCEemN4zOvm3oFEQ')
>>> annot.text
u"I'm imagining!!!"

Exceptions are more pythonic:

>>> h_annot.Annotation.load('somebogusannotid')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "h_annot/annotation.py", line 97, in load
    raise KeyError('annotation ID %s not found' % annot_id)
KeyError: 'annotation ID somebogusannotid not found'

The Annotation constructor should not be called directly.

Some attributes can be updated; to do so, set the authentication token using the h_annot.auth() context manager:

>>> with h_annot.auth(authentication_token):
...     annot.text = 'new text'

Annotations don’t have an inherent concept of authentication, so the previous way of declaring authentication to annotations:

>>> annot = h_annot.Annotation.load('someannotationid', 'somedevelkey')
>>> annot.text = 'new text'

is deprecated.

Tags are accessed and changed through the tags attribute. This attribute acts like a case-insensitive set (like Hypothesis itself treats tags).

>>> print annot.tags
TagSet(objectives, interwebs)
>>> for tag in annot.tags:
...     print tag
objectives
interwebs
>>> with h_annot.auth(authentication_token):
...     annot.tags = ['all', 'new', 'tags']
...     annot.tags.add('and one more')
...     annot.tags.remove('new')

Searching via Annotation.search() is deprecated. This search just wrapped the results of api.search() in Annotation constructors, so api.search() should now be used for searches that used Annotation.search(). For a high-level search interface, use h_annot.search(). This takes keyword arguments uri, user, tags, and text. Note that tags are joined by AND and separate words in text are joined by OR, which is the behavior of the Hypothesis search API. h_annot.search() respects the authentication set by the h_annot.auth() context manager.

h_annot.search() returns a SearchResults instance. SearchResults instances respond properly to len(), and iteration will result in annotations:

>>> results = h_annot.search()
800765
>>> len(results)
>>> for annotation in results:
...     print(annotation)
...     break
<Hypothesis annotation WcxuNG0CEemcl4_d0fJoaw>

The SearchResults object will load more results as needed from Hypothesis, but with a one second delay before each subsequent query to avoid rapid repeated hits to Hypothesis if something easily done and seemingly innocuous like list(h_annot.search()) is done.

Release files for python-hypothesis 0.4.2

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

Source distribution (sdist)

Source distribution for python-hypothesis 0.4.2
File Size Uploaded
python-hypothesis-0.4.2.tar.gz 10.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for python-hypothesis 0.4.2
File Interpreter ABI Platform
python_hypothesis-0.4.2-py3-none-any.whl Python 3 none any Details
python_hypothesis-0.4.2-py2-none-any.whl Python 2 none any Details

Total release size: 28.4 kB

Release files / python-hypothesis-0.4.2.tar.gz

Download URL python-hypothesis-0.4.2.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a44b2ceb4aba19e51f788780983c74b3c0d0603781511212fc04e8243d3a516f
BLAKE2b-256 checksum
How to use checksums
bd7433137f84606788468833900d346270bcb423511bb88ef9f91528d56c6676
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release files / python_hypothesis-0.4.2-py3-none-any.whl

Download URL python_hypothesis-0.4.2-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a15edb9cd05c7d0d1eb3db03be155916397a624352821d1d2ff4ee3775c9e3ca
BLAKE2b-256 checksum
How to use checksums
8fa17500f428796d0ee4341f4c0211f6abd81d376f16655da97af58f6253b868
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release files / python_hypothesis-0.4.2-py2-none-any.whl

Download URL python_hypothesis-0.4.2-py2-none-any.whl
Size 9.0 kB
Tags Python 2
SHA-256 checksum
How to use checksums
7145f56592c39c2b0ddf8b0e8aabd555085906b60ab0fde2d2c25d44e1d95331
BLAKE2b-256 checksum
How to use checksums
853b1007a5b3efca99dc277f34b499e284d71301dd033519e74e6e445ca6e699
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.4.2 This release

3 release files

0.4.1

3 release files

0.4.0

3 release files

0.3.0

3 release files

0.2.1

3 release files

0.2.0

1 release file

0.1.1

1 release file

0.1.0

1 release file

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