Context Management in qnexus¶
Functions for managing context in the client.
- qnexus.context.deactivate_project(
- token: Token,
Deactivate a project from the current context.
- qnexus.context.deactivate_properties(
- token: Token,
Deactivate the current properties.
- qnexus.context.deactivate_scope(
- token: Token,
Deactivate the current API Scope filter.
- qnexus.context.get_active_project(
- project_required: bool = False,
Get a reference to the active project if set.
>>> get_active_project()
>>> from qnexus.models.annotations import Annotations >>> token = set_active_project_token( ... ProjectRef(id="dca33f7f-9619-4cf7-a3fb-56256b117d6e", ... annotations=Annotations(name="example"))) >>> get_active_project() ProjectRef( id=UUID('dca33f7f-9619-4cf7-a3fb-56256b117d6e'), annotations=Annotations(name='example', description=None, properties=OrderedDict()) )
>>> deactivate_project(token)
- qnexus.context.get_active_properties() OrderedDict[str, bool | int | float | str][source]¶
Get the keys and values of the currently active properties.
>>> get_active_properties() OrderedDict()
>>> token = update_active_properties_token(foo=3, bar=True) >>> get_active_properties() OrderedDict([('foo', 3), ('bar', True)])
>>> deactivate_properties(token)
- qnexus.context.get_active_scope() ScopeFilterEnum[source]¶
Get the currently active API Scope filter.
>>> get_active_scope()
>>> token = _QNEXUS_SCOPE.set(ScopeFilterEnum.ORG_ADMIN) >>> get_active_scope() <ScopeFilterEnum.ORG_ADMIN: 'org_admin'>
>>> deactivate_scope(token) >>> get_active_scope() <ScopeFilterEnum.USER: 'user'>
- qnexus.context.merge_project_from_context(
- func: Callable[[P], T],
Decorator to merge a project from the context. ProjectRef in kwargs takes precedence (will be selected).
- qnexus.context.merge_properties_from_context(
- func: Callable[[P], T],
Decorator to take the union of properties from the context with any provided in kwargs. Properties in kwargs take precendence.
- qnexus.context.merge_scope_from_context(
- func: Callable[[P], T],
Decorator to merge an API Scope filter from the context. Scope in kwargs takes precedence (will be selected).
- qnexus.context.set_active_project(
- project: ProjectRef,
Globally set a project as active.
- qnexus.context.set_active_project_token(
- project: ProjectRef,
Globally set a project as active, returning a Token to the ProjectRef in the context.
- qnexus.context.set_active_scope(
- scope: ScopeFilterEnum,
Globally set an API Scope filter as active.
- qnexus.context.set_active_scope_token(
- scope: ScopeFilterEnum,
Globally set an API Scope filter as active, returning a Token to the ScopeFilterEnum in the context.
- qnexus.context.update_active_properties( ) None[source]¶
Globally update and merge properties with the existing ones.
- qnexus.context.update_active_properties_token( ) Token[source]¶
Globally update and merge properties with the existing ones, returning a token to the PropertiesDict in the context.
- qnexus.context.using_project(
- project: ProjectRef,
Attach a ProjectRef to the current context.
All operations in the context will make use of the project.
>>> from qnexus.models.annotations import Annotations >>> project = ProjectRef( ... id="cd325b9c-d4a2-4b6e-ae58-8fad89749fac", ... annotations=Annotations(name="example")) >>> with using_project(project): ... get_active_project() ProjectRef( id=UUID('cd325b9c-d4a2-4b6e-ae58-8fad89749fac'), annotations=Annotations(name='example', description=None, properties=OrderedDict()) )
>>> get_active_project()