ORIONIS API REFERENCE

THE ORIONIS API

Build with clarity.

Explore the building blocks of an async-first Python framework. Every module, class, and method — connected, searchable, and ready to build with.

class documentation

class ScopeManager: (source)

Constructor: ScopeManager()

View In Hierarchy

Own scoped service instances and their creation and cleanup lifecycle.

Async Method __aenter__ Enter the asynchronous context and set the current scope.
Async Method __aexit__ Exit the asynchronous context and clear the current scope.
Method __contains__ Check whether the given key exists in the scope.
Method __getitem__ Retrieve the instance associated with the given key.
Method __init__ Initialize the ScopeManager.
Method __setitem__ Store an instance under the specified key.
Method clear Remove all instances from the current scope.
Method creationLock Return the construction lock owned by this scope and service key.
Async Method get Retrieve the instance associated with the given key asynchronously.
Async Method resolve Resolve and return the instance for a given key.
Method set Store an instance in the scope.
Class Variable __slots__ Declare the instance attribute slots reserved by this class.
Instance Variable __active Active flag used by ScopeManager.
Instance Variable __closed Whether this resource has completed its close lifecycle.
Instance Variable __creation_locks Locks coordinating concurrent creation of the same scoped service.
Instance Variable _instances Dictionary to hold instances for the current scope.
Instance Variable _token Context-variable token used to restore the previous scope.
Property isActive Report whether the owning scope is still open.
async def __aenter__(self) -> Self: (source)

Enter the asynchronous context and set the current scope.

Sets the current scope in the ScopedContext to this instance.

Returns
typing.SelfThe current ScopeManager instance.
Raises
RuntimeErrorIf the scope is already active or has previously closed.
async def __aexit__(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None): (source)

Exit the asynchronous context and clear the current scope.

Parameters
exc_type:type[BaseException] | NoneThe exception type, if any.
exc_val:BaseException | NoneThe exception value, if any.
exc_tb:types.TracebackType | NoneThe traceback object, if any.
Returns
NoneThis method does not return a value.
def __contains__(self, key: object) -> bool: (source)

Check whether the given key exists in the scope.

Parameters
key:objectThe key to check for existence.
Returns
boolTrue if the key exists in the scope, otherwise False.
def __getitem__(self, key: object) -> object | None: (source)

Retrieve the instance associated with the given key.

Parameters
key:objectThe key identifying the instance.
Returns
object or NoneThe instance associated with the key, or None if not present.
def __init__(self): (source)

Initialize the ScopeManager.

Initializes an empty dictionary to store scoped instances.

Returns
NoneThis method does not return a value.
def __setitem__(self, key: object, value: object): (source)

Store an instance under the specified key.

Parameters
key:objectKey to associate with the instance.
value:objectInstance to store.
Returns
NoneThis method does not return a value.
Raises
RuntimeErrorIf the scope has already closed.
def clear(self): (source)

Remove all instances from the current scope.

Release unstarted native coroutines. Existing services, running coroutines, and externally supplied tasks retain their caller-owned lifecycles.

Returns
NoneThis method does not return a value.
def creationLock(self, key: object) -> asyncio.Lock: (source)

Return the construction lock owned by this scope and service key.

Parameters
key:objectContract identifying a scoped service.
Returns
asyncio.LockLock shared by tasks resolving that service within this scope.
Raises
RuntimeErrorIf the scope has already closed.
async def get(self, key: object) -> Any | None: (source)

Retrieve the instance associated with the given key asynchronously.

Notes

Awaiting a stored task does not overwrite a replacement or repopulate the scope after clear(). Completion after scope exit is rejected.

Parameters
key:objectThe key identifying the instance.
Returns
typing.Any or NoneThe resolved instance associated with the key, or None if not found.
async def resolve(self, key: object) -> Any: (source)

Resolve and return the instance for a given key.

This method retrieves the instance associated with the provided key. Raises a KeyError if the instance is not found in the scope.

Parameters
key:objectThe key identifying the instance.
Returns
typing.AnyThe resolved instance associated with the key.
Raises
KeyErrorIf the instance for the given key is not found in the scope.
def set(self, key: object, value: Any): (source)

Store an instance in the scope.

Parameters
key:objectKey to associate with the instance.
value:typing.AnyInstance to store, can be synchronous or a coroutine.
Returns
NoneThis method does not return a value.
__slots__: tuple[str, ...] = (source)

Declare the instance attribute slots reserved by this class.

__active: bool = (source)

Active flag used by ScopeManager.

__closed: bool = (source)

Whether this resource has completed its close lifecycle.

__creation_locks: dict[object, asyncio.Lock] | None = (source)

Locks coordinating concurrent creation of the same scoped service.

Dictionary to hold instances for the current scope.

Context-variable token used to restore the previous scope.

Report whether the owning scope is still open.

Returns
boolFalse before entry and after exit, including in child tasks retaining a reference to this scope.