pykern.api package¶
HTTP WebSocket Quest server & client
- copyright:
Copyright (c) 2024 RadiaSoft LLC. All Rights Reserved.
- license:
Submodules¶
pykern.api.auth_api module¶
?
- copyright:
Copyright (c) 2025 RadiaSoft LLC. All Rights Reserved.
- license:
- class pykern.api.auth_api.AuthAPI(*args, **kwargs)[source]¶
Bases:
API- VERSION = 658584001¶
Defaults version number but allows override
pykern.api.client module¶
WebSocket Quest client
- copyright:
Copyright (c) 2025 RadiaSoft LLC. All Rights Reserved.
- license:
- class pykern.api.client.Client(http_config)[source]¶
Bases:
objectWrapper for tornado.httpclient.AsyncHTTPClient
Maybe called as an async context manager
http_config.request_config is deprecated.
- Parameters:
http_config (PKDict) – tcp_ip, tcp_port, api_uri
- async call_api(api_name, api_args)[source]¶
Make a request to the API server
- Parameters:
- Returns:
value of api_result.
- Return type:
- Raises:
pykern.util.APIError – if there was an raise in the API or on a server protocol violation
Exception – other exceptions that AsyncHTTPClient.fetch may raise, e.g. NotFound
- async subscribe_api(api_name, api_args)[source]¶
Subscribe to api_name from API server
Maybe used in
with:with client.subscribe_api(api, args) as s: while (r := await s.result_get()): process r
Alternately, you must call _Call.unsubscribe:
s = client.subscribe_api(api, args) r = await s.result_get() ... process r and possibly more calls to result_get ... s.unsubscribe()
pykern.api.server module¶
WebSocket Quest server
- copyright:
Copyright (c) 2025 RadiaSoft LLC. All Rights Reserved.
- license:
- class pykern.api.server.Session(qcall, **kwargs)[source]¶
Bases:
AttrState held on server bound to a client.
Currently the state is not persisted when the server terminates. This may change.
- ATTR_KEY = 'session'¶
- IS_SINGLETON = True¶
shared Attrs do not have link to qcall
- class pykern.api.server.Subscription(server_msg)[source]¶
Bases:
AttrEXPERIMENTAL
- ATTR_KEY = 'subscription'¶
- pykern.api.server.start(api_classes, attr_classes, http_config, coros=())[source]¶
Start _Server in pkasyncio
- Parameters:
api_classes (Iterable) – pykern.quest.API subclasses to be dispatched
attr_classes (Iterable) – pykern.quest.Attr subclasses to create API instance
http_config (PKDict) – pkasyncio.Loop.http_server arg
coros (Iterable) – list of coroutines to be passed to pkasyncio.Loop.run
pykern.api.unit_util module¶
Support for pykern.api tests
- copyright:
Copyright (c) 2024 RadiaSoft LLC. All Rights Reserved.
- license:
- class pykern.api.unit_util.Setup(**server_config)[source]¶
Bases:
objectUsage:
async with http_unit.Setup(api_classes=(_class())) as c: from pykern.pkcollections import PKDict from pykern import pkunit e = PKDict(ping="pong") pkunit.pkeq(e.pkupdate(counter=1), await c.call_api("echo", e)) pkunit.pkeq(e.pkupdate(counter=2), await c.call_api("echo", e))
May be subclassed to start multiple servers.
pykern.api.util module¶
API constants
- copyright:
Copyright (c) 2025 RadiaSoft LLC. All Rights Reserved.
- license:
- exception pykern.api.util.APICallError(error)[source]¶
Bases:
APIErrorRaised when call execution ends in exception or other error
- exception pykern.api.util.APIDisconnected[source]¶
Bases:
APIErrorRaised when remote server closed or other error
- exception pykern.api.util.APIForbidden[source]¶
Bases:
APIErrorRaised for forbidden or protocol error
- exception pykern.api.util.APINotFound(api_name)[source]¶
Bases:
APIErrorRaised for an object not found
- exception pykern.api.util.APIProtocolError(error)[source]¶
Bases:
APIErrorRaised when protocol error at lower level
- pykern.api.util.AUTH_API_NAME = 'authenticate_connection'¶
API that authenticates connections (needed for client)
- pykern.api.util.AUTH_API_VERSION = 658584001¶
API version for AUTH (and for pykern.api)
- class pykern.api.util.MsgKind(*values)[source]¶
Bases:
Enum- CALL = 777501¶
- REPLY = 777502¶
- SUBSCRIBE = 777503¶
- UNSUBSCRIBE = 777504¶