ContextRepo
faststream._internal.context.repository.ContextRepo #
ContextRepo(initial: dict[str, Any] | None = None)
A class to represent a context repository.
Initialize the class.
Source code in faststream/_internal/context/repository.py
15 16 17 18 19 20 21 22 23 | |
set_global #
set_global(key: str, v: Any) -> None
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. |
Source code in faststream/_internal/context/repository.py
32 33 34 35 36 37 38 39 40 41 42 | |
reset_global #
reset_global(key: str) -> None
Resets a key in the global context.
| PARAMETER | DESCRIPTION |
|---|---|
key | The key to reset in the global context. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
None | None |
Source code in faststream/_internal/context/repository.py
44 45 46 47 48 49 50 51 52 53 | |
set_local #
set_local(key: str, value: T) -> Token[T]
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. |
Source code in faststream/_internal/context/repository.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
reset_local #
reset_local(key: str, tag: Token[Any]) -> None
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. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
None | None |
Source code in faststream/_internal/context/repository.py
71 72 73 74 75 76 77 78 79 80 81 | |
get_local #
get_local(key: str, default: Any = None) -> Any
Get the value of a local variable.
| PARAMETER | DESCRIPTION |
|---|---|
key | The key of the local variable to retrieve. TYPE: |
default | The default value to return if the local variable is not found. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Any | The value of the local variable. |
Source code in faststream/_internal/context/repository.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
scope #
scope(key: str, value: Any) -> ContextScope
Set one local value for the duration of a with block.
| PARAMETER | DESCRIPTION |
|---|---|
key | The key of the local variable TYPE: |
value | The value to set the local variable to TYPE: |
Source code in faststream/_internal/context/repository.py
101 102 103 104 105 106 107 108 | |
scopes #
scopes(items: Iterable[tuple[str, Any]]) -> ContextScope
Set several local values for the duration of a single with block.
| PARAMETER | DESCRIPTION |
|---|---|
items | The TYPE: |
Source code in faststream/_internal/context/repository.py
110 111 112 113 114 115 116 | |
get #
get(key: str, default: Any = None) -> Any
Get the value associated with a key.
| PARAMETER | DESCRIPTION |
|---|---|
key | The key to retrieve the value for. TYPE: |
default | The default value to return if the key is not found. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Any | The value associated with the key. |
Source code in faststream/_internal/context/repository.py
118 119 120 121 122 123 124 125 126 127 128 129 130 | |
resolve #
resolve(argument: str) -> Any
Resolve the context of an argument.
| PARAMETER | DESCRIPTION |
|---|---|
argument | A string representing the argument. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Any | The resolved context of the argument. |
| RAISES | DESCRIPTION |
|---|---|
(AttributeError, KeyError) | If the argument does not exist in the context. |
Source code in faststream/_internal/context/repository.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
clear #
clear() -> None
Source code in faststream/_internal/context/repository.py
165 166 167 | |