ServiceAPI, a base class for APIs which talk to a service, typically a web service via HTTP.
Latest release 20240723: ServiceAPI: acquire the fstags automatically at init.
An instance of a ServiceAPI embodies some basic features
that feel common to web based services:
- a notion of a login
- local state, an
SQLTagsfor data about entities of the service - downloads, if that is a thing, with
FSTagsfor file annotations
Class HTTPServiceAPI(ServiceAPI)
HTTPServiceAPI base class for other APIs talking to HTTP services.
Subclasses must define:
API_BASE: the base URL of API calls. For example, thePlayOnAPIdefines this asf'https://{API_HOSTNAME}/v3/'.
HTTPServiceAPI.json(self, suburl, _response_encoding=None, **kw):
Request suburl from the service, by default using a GET.
Return the result decoded as JSON.
Parameters are as for HTTPServiceAPI.suburl.
HTTPServiceAPI.suburl(*a, upd: Optional[cs.upd.Upd] = <function uses_upd.<locals>.<lambda> at 0x102fe7060>, **kw):
Request suburl from the service, by default using a GET.
The suburl must be a URL subpath not commencing with '/'.
Keyword parameters:
_base_url: the base request domain, default fromself.API_BASE_method: the request method, default'GET'_no_raise_for_status: do not raise an HTTP error if the response status is not 200, defaultFalse(raise if not 200)cookies: optional cookie jar, default fromself.cookiesOther keyword parameters are passed to the requests method.
Class RequestsNoAuth(requests.auth.AuthBase)
This is a special purpose subclass of requests.auth.AuthBase
to apply no authorisation at all.
This is for services with their own special purpose authorisation
and avoids things like automatic netrc based auth.
Class ServiceAPI(cs.resources.MultiOpenMixin)
SewrviceAPI base class for other APIs talking to services.
ServiceAPI.available(self) -> Set[cs.sqltags.SQLTagSet]:
Return a set of the SQLTagSet instances representing available
items at the service, for example purchased books
available to your login.
ServiceAPI.get_login_state(self, do_refresh=False) -> cs.sqltags.SQLTagSet:
The login state, a mapping. Performs a login if necessary
or if do_refresh is true (default False).
ServiceAPI.login(self) -> Mapping:
Do a login: authenticate to the service, return a mapping of related information.
Not all services require this and we expect such subclasses to avoid use of login-based methods.
ServiceAPI.login_expiry:
Expiry UNIX time for the login state.
This implementation returns None.
ServiceAPI.login_state:
The login state, a mapping. Performs a login if necessary.
ServiceAPI.startup_shutdown(self):
Open/close the FSTags and SQLTags.
Release Log
Release 20240723: ServiceAPI: acquire the fstags automatically at init.
Release 20230703: Retry logic for requests.
Release 20230217: Initial release.
Release files for cs-service-api 20240723
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cs_service_api-20240723.tar.gz | 4.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cs.service_api-20240723-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.4 kB
Release files / cs_service_api-20240723.tar.gz
| Download URL | cs_service_api-20240723.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5723d8caf1914d150ce36eb8187f67760d226c96f0bca860fb1e3c1602107484
|
|
BLAKE2b-256 checksum How to use checksums |
f7dffc591071cac6dd155159f57d67989233a4f1fec4938f18c2cbc963c739dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.0
|
Release files / cs.service_api-20240723-py3-none-any.whl
| Download URL | cs.service_api-20240723-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0b37516e40e34db5150ce93290b5477187eee7f7ac088dc24dbc2a97c5751b2a
|
|
BLAKE2b-256 checksum How to use checksums |
38ff058ab7ff98f5e8ea6a375d47ea3f33021180d8b89c68ba3585a21f35268a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.0
|