pdstools.infinity.internal._resource

Classes

SyncAPIResource

Helper class that provides a standard way to create an ABC using

AsyncAPIResource

Helper class that provides a standard way to create an ABC using

Functions

_run_sync(async_fn, *args, **kwargs)

Run an async function synchronously.

api_method(func)

Mark an async def resource method for automatic sync wrapping.

_maybe_await(result)

Await the result if it's awaitable, otherwise return it as-is.

Module Contents

_run_sync(async_fn, *args, **kwargs)

Run an async function synchronously.

Uses anyio.run when no event loop is running, and falls back to start_blocking_portal when called from within an existing loop (e.g. Jupyter).

api_method(func)

Mark an async def resource method for automatic sync wrapping.

Methods decorated with @api_method should be defined as async def and may await any of the _a_get/_a_post/… helpers on the resource.

  • On AsyncAPIResource subclasses the method is left as-is (native coroutine).

  • On SyncAPIResource subclasses the method is automatically replaced by a synchronous wrapper (via __init_subclass__) that executes the coroutine with _run_sync().

async _maybe_await(result)

Await the result if it’s awaitable, otherwise return it as-is.

Useful in mixin methods that call something which is sync on SyncAPIResource (returns a plain value) but async on AsyncAPIResource (returns a coroutine).

class SyncAPIResource(client: pdstools.infinity.internal._base_client.SyncAPIClient)

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Parameters:

client (pdstools.infinity.internal._base_client.SyncAPIClient)

_client: pdstools.infinity.internal._base_client.SyncAPIClient
classmethod __init_subclass__(**kwargs)
_get
_post
_patch
_put
_delete
_get_api_list
async _a_get(endpoint: str, **kwargs)
Parameters:

endpoint (str)

async _a_post(endpoint: str, **kwargs)
Parameters:

endpoint (str)

async _a_patch(endpoint: str, **kwargs)
Parameters:

endpoint (str)

async _a_put(endpoint: str, **kwargs)
Parameters:

endpoint (str)

async _a_delete(endpoint: str, **kwargs)
Parameters:

endpoint (str)

async _sleep(seconds: float) None
Parameters:

seconds (float)

Return type:

None

property _public_fields
property _public_dict
__repr__(fields: list[str] | None = None)
Parameters:

fields (list[str] | None)

class AsyncAPIResource(client: pdstools.infinity.internal._base_client.AsyncAPIClient)

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Parameters:

client (pdstools.infinity.internal._base_client.AsyncAPIClient)

_client: pdstools.infinity.internal._base_client.AsyncAPIClient
_get_api_list
async _a_get(endpoint: str, **kwargs)
Parameters:

endpoint (str)

async _a_post(endpoint: str, **kwargs)
Parameters:

endpoint (str)

async _a_patch(endpoint: str, **kwargs)
Parameters:

endpoint (str)

async _a_put(endpoint: str, **kwargs)
Parameters:

endpoint (str)

async _a_delete(endpoint: str, **kwargs)
Parameters:

endpoint (str)

_get
_post
_patch
_put
_delete
async _sleep(seconds: float) None
Parameters:

seconds (float)

Return type:

None

property _public_fields
property _public_dict
__repr__(fields: list[str] | None = None)
Parameters:

fields (list[str] | None)