Python Client for the European Patent Office's Open Patent Services API
import epo_ops client = epo_ops.Client(key='abc', secret='xyz') # Instantiate client response = client.published_data( # Retrieve bibliography data reference_type = 'publication', # publication, application, priority input = epo_ops.models.Docdb('1000000', 'EP', 'A1'), # original, docdb, epodoc endpoint = 'biblio', # optional, defaults to biblio in case of published_data constituents =  # optional, list of constituents )
python-epo-ops-client abstracts away the complexities of accessing EPO OPS:
- Format the requests properly
- Bubble up quota problems as proper HTTP errors
- Handle token authentication and renewals automatically
- Handle throttling properly
- Add optional caching to minimize impact on the OPS servers
There are two main layers to
python-epo-ops-client: Client and Middleware.
The Client contains all the formatting and token handling logic and is what you'll interact with mostly.
When you issue a request, the response is a
requests.Response object. If
response.status_code != 200
requests.HTTPError exception will be raised — it's your responsibility
to handle those exceptions if you want to. The one case that's handled is when
the access token has expired: in this case, the client will automatically handle
the HTTP 400 status and renew the token.
Note that the Client does not attempt to interpret the data supplied by OPS, so it's your responsibility to parse the XML or JSON payload for your own purpose.
The following custom exceptions are raised for cases when OPS quotas are
exceeded, they are all in the
epo_ops.exceptions module and are subclasses of
requests.HTTPError, and therefore offer the same behaviors:
Again, it's up to you to parse the response and decide what to do.
Currently the Client knows how to issue request for the following services:
|Client method||API end point||throttle|
Bulk operations can be achieved by passing a list of valid models to the published_data input field.
Please submit pull requests for the following services by enhancing the
- Legal service
All requests and responses are passed through each middleware object listed in
client.middlewares. Requests are processed in the order listed, and responses
are processed in the reverse order.
Each middleware should subclass
middlewares.Middleware and implement the
There are two middleware classes out of the box: Throttler and Dogpile. Throttler is in charge of the OPS throttling rules and will delay requests accordingly. Dogpile is an optional cache which will cache all HTTP status 200, 404, 405, and 413 responses.
By default, only the Throttler middleware is enabled, if you want to enable caching:
import epo_ops middlewares = [ epo_ops.middlewares.Dogpile(), epo_ops.middlewares.Throttler(), ] client = epo_ops.Client( key='key', secret='secret', middlewares=middlewares, )
Note that caching middleware should be first in most cases.
Dogpile is based on (surprise) dogpile.cache. By default it is instantiated with a DBMBackend region with timeout of 2 weeks.
Dogpile takes three optional instantiation parameters:
region: You can pass whatever valid dogpile.cache Region you want to backend the cache
kwargs_handlers: A list of keyword argument handlers, which it will use to process the kwargs passed to the request object in order to extract elements for generating the cache key. Currently one handler is implemented (and instantiated by default) to make sure that the range request header is part of the cache key.
http_status_codes: A list of HTTP status codes that you would like to have cached. By default 200, 404, 405, and 413 responses are cached.
Note: dogpile.cache is not installed by default, if you want to use it,
pip install dogpile.cache in your project.
Throttler contains all the logic for handling different throttling scenarios. Since OPS throttling is based on a one minute rolling window, we must persist historical (at least for the past minute) throtting data in order to know what the proper request frequency is. Each Throttler must be instantiated with a Storage object.
The Storage object is responsible for:
- Knowing how to update the historical record with each request
Storage.update()), making sure to observe the one minute rolling window rule.
- Calculating how long to wait before issuing the next request
Currently the only Storage backend provided is SQLite, but you can easily write
your own Storage backend (such as file, Redis, etc.). To use a custom Storage
type, just pass the Storage object when you're instantiating a Throttler object.
epo_ops.middlewares.throttle.storages.Storage for more implementation
Tests are written using pytest. To run the tests:
- Register a OPS user login with EPO
- Create an app
- Look up the Mock Server URL at Apiary
- Set the
OPS_SECRETenvironment variables accordingly
The tests must be run with a working internet connection, since both OPS and the mock Apiary services are online.
- Add support for bulk retrieval, thanks to mmath
- Drop support for PyPy, Python 3.4 (probably still works)
- Add support for Python 3.7, 3.8
- Invalid and expired tokens are now treated the same, since OPS doesn't distinguish between the two use cases.
- Bug fix: Cache 4xx results as well, thanks to amotl
- Bug fix: explicitly declare content-type during request
- Drop support for Python 2.6
- Officially support Python 3.6
- Update to latest dependencies
- Add image retrieval service, thanks to rfaga
- EPO OPS v3.2 compatibility, thanks to eltermann
- Add number service, thanks to eltermann
- Dropping support for Python 3.3 (although it probably still works).
- Update to latest dependencies, no new features.
- Allow no middleware to be specified
- Minor tweaks to development infrastructure, no new features.
- This has been working for a while now, let's call it 1.0!
- No new features, just updating third party dependencies
- No new features, just updating third party dependencies
- Created default Dogpile DBM path if it doesn't exist
- Fixed bug with how service URL is constructed
- Added support for register retrieval and search
- Verified PyPy3 support
- Updated various dependency pacakges
- Python 3.4 compatibility
requestsdependency to 2.3.0
- Python 2.6 and 3.3 compatibility
- Allow configuration of which HTTP responses (based on status code) to cache
- Introduced dogpile.cache for caching http200 resopnses
- Introduced the concept of middleware
- Initial release
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size python_epo_ops_client-3.1.1-py2.py3-none-any.whl (22.0 kB)||File type Wheel||Python version py2.py3||Upload date||Hashes View|
|Filename, size python-epo-ops-client-3.1.1.tar.gz (20.2 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for python_epo_ops_client-3.1.1-py2.py3-none-any.whl
Hashes for python-epo-ops-client-3.1.1.tar.gz