Package: python-epo-ops-client
python-epo-ops-clientpython-epo-ops-client is anApache2 licensedclient library
for accessing theEuropean Patent Office's ("EPO")Open Patent
Services("OPS") v.3.2 (based onv 1.3.16 of the reference guide).importepo_opsclient=epo_ops.Client(key='abc',secret='xyz')# Instantiate clientresponse=client.published_data(# Retrieve bibliography datareference_type='publication',# publication, application, priorityinput=epo_ops.models.Docdb('1000000','EP','A1'),# original, docdb, epodocendpoint='biblio',# optional, defaults to biblio in case of published_dataconstituents=[]# optional, list of constituents)Featurespython-epo-ops-clientabstracts away the complexities of accessing EPO OPS:Format the requests properlyBubble up quota problems as proper HTTP errorsHandle token authentication and renewals automaticallyHandle throttling properlyAdd optional caching to minimize impact on the OPS serversThere are two main layers topython-epo-ops-client: Client and Middleware.ClientThe 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 arequests.Responseobject. Ifresponse.status_code != 200then arequests.HTTPErrorexception 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 theepo_ops.exceptionsmodule and are subclasses ofrequests.HTTPError, and therefore offer the same behaviors:IndividualQuotaPerHourExceededRegisteredQuotaPerWeekExceededAgain, 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 methodAPI end pointthrottlefamily(reference_type, input, endpoint=None, constituents=None)familyinpadocimage(path, range=1, extension='tiff')published-data/imagesimagesnumber(reference_type, input, output_format)number-serviceotherpublished_data(reference_type, input, endpoint='biblio', constituents=None)published-dataretrievalpublished_data_search(cql, range_begin=1, range_end=25, constituents=None)published-data/searchsearchregister(reference_type, input, constituents=['biblio'])registerotherregister_search(cql, range_begin=1, range_end=25)register/searchotherregister_search(cql, range_begin=1, range_end=25)register/searchotherBulk operations can be achieved by passing a list of valid models to the
published_data input field.See theOPS guideor use theDeveloper's Areafor more information on
how to use each service.Please submit pull requests for the following services by enhancing theepo_ops.api.Clientclass:Legal serviceMiddlewareAll requests and responses are passed through each middleware object listed inclient.middlewares. Requests are processed in the order listed, and responses
are processed in thereverseorder.Each middleware should subclassmiddlewares.Middlewareand implement theprocess_requestandprocess_responsemethods.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:importepo_opsmiddlewares=[epo_ops.middlewares.Dogpile(),epo_ops.middlewares.Throttler(),]client=epo_ops.Client(key='key',secret='secret',middlewares=middlewares,)You'll also need to install caching dependencies in your projects, such aspip install dogpile.cache.Note that caching middleware should be first in most cases.DogpileDogpile 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 validdogpile.cache Regionyou want to
backend the cachekwargs_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.cachein your project.ThrottlerThrottler 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.StorageThe 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
(Storage.delay_for()).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.
Seeepo_ops.middlewares.throttle.storages.Storagefor more implementation
details.