ContextRepo
faststream.utils.context.main.ContextRepo #
Bases: Singleton
A class to represent a context repository.
METHOD | DESCRIPTION |
---|---|
__init__ | initializes the ContextRepo object |
set_global | sets a global context variable |
reset_global | resets a global context variable |
set_local | sets a local context variable |
reset_local | resets a local context variable |
get_local | gets the value of a local context variable |
clear | clears the global and scope context |
get | gets the value of a context variable |
__getattr__ | gets the value of a context variable using attribute access |
context | gets the current context as a dictionary |
scope | creates a context scope for a specific key and value |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Initialize the class.
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Source code in faststream/utils/context/main.py
clear #
get #
Get the value associated with a key.
PARAMETER | DESCRIPTION |
---|---|
key | The key to retrieve the value for. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Any | The value associated with the key. |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Source code in faststream/utils/context/main.py
get_local #
Get the value of a local variable.
PARAMETER | DESCRIPTION |
---|---|
key | The key of the local variable to retrieve. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Any | The value of the local variable. |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Source code in faststream/utils/context/main.py
reset_global #
Resets a key in the global context.
PARAMETER | DESCRIPTION |
---|---|
key | The key to reset in the global context. TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | None |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Source code in faststream/utils/context/main.py
reset_local #
Resets the local context for a given key.
PARAMETER | DESCRIPTION |
---|---|
key | The key to reset the local context for. TYPE: |
tag | The tag associated with the local context. |
RETURNS | DESCRIPTION |
---|---|
None | None |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Source code in faststream/utils/context/main.py
scope #
Sets a local variable and yields control to the caller. After the caller is done, the local variable is reset.
PARAMETER | DESCRIPTION |
---|---|
key | The key of the local variable TYPE: |
value | The value to set the local variable to TYPE: |
YIELDS | DESCRIPTION |
---|---|
Iterator[None] | None |
RETURNS | DESCRIPTION |
---|---|
Iterator[None] | An iterator that yields None |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Source code in faststream/utils/context/main.py
set_global #
Sets a value in the global context.
PARAMETER | DESCRIPTION |
---|---|
key | The key to set in the global context. TYPE: |
v | The value to set. TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | None. |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Source code in faststream/utils/context/main.py
set_local #
Set a local context variable.
PARAMETER | DESCRIPTION |
---|---|
key | The key for the context variable. TYPE: |
value | The value to set for the context variable. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Token[T] | Token[T]: A token representing the context variable. |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)