ServiceAPI, a base class for APIs which talk to a service, typically a web service via HTTP.
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
Short summary:
-
HTTPServiceAPI:HTTPServiceAPIbase class for other APIs talking to HTTP services. -
LoginPasswordCredentials: A credentials class for login/password authentication. -
RequestsNoAuth: This is a special purpose subclass ofrequests.auth.AuthBaseto apply no authorisation at all. This is for services with their own special purpose authorisation and avoids things like automatic netrc based auth. -
ServiceAPI:SewrviceAPIbase class for other APIs talking to services. -
UsesCredentials: A mixin for accessing credentials.
Classes
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.get(self, suburl, **kw) -> requests.models.Response
Call slef.suburl with method="GET".
HTTPServiceAPI.post(self, suburl, **kw) -> requests.models.Response
Call slef.suburl with method="POST".
HTTPServiceAPI.response_as_json(self, rsp: requests.models.Response) -> dict
Return rsp.json().
HTTPServiceAPI.response_as_json_data(self, rsp: requests.models.Response) -> dict
Return the "data" element from a JSON response.
HTTPServiceAPI.suburl(self, suburl, *, base_url=None, method='GET', mode=None, check=True, cookies=None, headers=None, runstate: Optional[cs.resources.RunState] = <function uses_runstate.<locals>.<lambda> at 0x1097f7ec0>, verbose: bool, **rqkw) -> Union[requests.models.Response, dict]
Request suburl from the service, by default using a GET.
The suburl must be a URL subpath not commencing with '/'.
Return:
mode(Response)ifmodeis callable- the
Responseifmode=="response" - the
Response.json()ifmode=="json" - the
Response.json()["data"]ifmode=="data"
Keyword parameters:
base_url: the base request domain, default fromself.API_BASEmethod: optional request method, default'GET'check: if true, raise an HTTP error if the response status is not 200; defaultTruecookies: optional cookie jar, default fromself.cookiesmode: optional result mode, default fromself.modeOther keyword parameters are passed to the requests method.
class LoginPasswordCredentials(LoginPasswordCredentials)
A credentials class for login/password authentication.
Its default from_str(credname) factory accesses the netrc(5) file.
LoginPasswordCredentials.from_netrc(host, netrc_path=None)
Create an instance from a netrc(5) host.
Raise KeyError if host is unknown.
class LoginState(cs.obj.Refreshable)
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, UsesCredentials, cs.sqltags.UsesSQLTags)
SewrviceAPI base class for other APIs talking to services.
ServiceAPI.__init__(*a, fstags: Optional[cs.fstags.FSTags] = <function uses_fstags.<locals>.<lambda> at 0x1097f71a0>, **kw)
Initialise a ServiceAPI instance.
The concurrency parameter may take the following values:
None: API calls are serialised, setting.concurrency_sem=Noneand.pmap=partial(pmap,concurrent=1)- an
int: API calls are constrained by.concurrency_sem, set to aSemaphorewith this initial value, and.pmap=pmap - a
Semaphore: API calls are constrained by.concurrency_sem, set to thisSemaphore, and.pmap=pmap
ServiceAPI.API_AUTH_GRACETIME
None
ServiceAPI.API_CONCURRENCY_LIMIT
None
ServiceAPI.API_RETRY_COUNT
3
ServiceAPI.API_RETRY_DELAY
5
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.tagged.Entity
The login state, a Entity, stored as login.state.login_userid.
This 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
<property object at 0x109802430>
ServiceAPI.login_state
<functools.cached_property object at 0x108c8b070>
ServiceAPI.startup_shutdown(self)
Open/close the FSTags and Entities.
class UsesCredentials
A mixin for accessing credentials.
UsesCredentials.credentials(self, credname)
Return the credentials for credname.
UsesCredentials.default_credentials()
Return the default credentials for cls.API_HOSTNAME.
Metadata
Release files for cs-service-api 20260914
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cs_service_api-20260914.tar.gz | 6.0 kB | Without provenance | Details for cs_service_api-20260914.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cs_service_api-20260914-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for cs_service_api-20260914-py2.py3-none-any.whl |
Total release size: 13.4 kB
Release files / cs_service_api-20260914.tar.gz
| Download URL | cs_service_api-20260914.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b4b7ac66293493847bda0ab6dc58efed05942315e112d3270b1cc152dcfff196
|
|
BLAKE2b-256 checksum How to use checksums |
5bb132f0dd698fe62640dd6dad28d060ac4e7a5b66265cd864b09ef8ec816846
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / cs_service_api-20260914-py2.py3-none-any.whl
| Download URL | cs_service_api-20260914-py2.py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
5de4f5d6e7a6b90bfcefe800112dc3ce490dc5782f973410787c5f2a3b81f4ed
|
|
BLAKE2b-256 checksum How to use checksums |
0dd9d975e7bb6461d45438e85f396366e1f6d4a4813fdbc546c8dc5cf824e15e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Security for cs-service-api 20260914
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.