nemo_microservices._models
#
Module Contents#
Classes#
Functions#
Construct a BaseModel class without validation. |
|
Loose coercion to the expected type with construction of nested values. |
|
Loose coercion to the expected type with construction of nested values. |
|
Returns whether or not the given type is either a |
|
Add a pydantic config for the given type. |
|
Strict validation that the given value matches the expected type |
Data#
API#
- class nemo_microservices._models.BaseModel(/, **data: Any)#
Bases:
pydantic.BaseModel
- classmethod construct(
- _fields_set: set[str] | None = None,
- **values: object,
- to_dict(
- *,
- mode: typing_extensions.Literal[json, python] = 'python',
- use_api_names: bool = True,
- exclude_unset: bool = True,
- exclude_defaults: bool = False,
- exclude_none: bool = False,
- warnings: bool = True,
Recursively generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
By default, fields that were not set by the API will not be included, and keys will match the API response, not the property names from the model.
For example, if the API responds with
"fooBar": true
but we’ve defined afoo_bar: bool
property, the output will use the"fooBar"
key (unlessuse_api_names=False
is passed).Args: mode: If mode is ‘json’, the dictionary will only contain JSON serializable types. e.g.
datetime
will be turned into a string,"2024-3-22T18:11:19.117000Z"
. If mode is ‘python’, the dictionary may contain any Python objects. e.g.datetime(2024, 3, 22)
use_api_names: Whether to use the key that the API responded with or the property name. Defaults to `True`. exclude_unset: Whether to exclude fields that have not been explicitly set. exclude_defaults: Whether to exclude fields that are set to their default value from the output. exclude_none: Whether to exclude fields that have a value of `None` from the output. warnings: Whether to log warnings when invalid fields are encountered. This is only supported in Pydantic v2.
- to_json(
- *,
- indent: int | None = 2,
- use_api_names: bool = True,
- exclude_unset: bool = True,
- exclude_defaults: bool = False,
- exclude_none: bool = False,
- warnings: bool = True,
Generates a JSON string representing this model as it would be received from or sent to the API (but with indentation).
By default, fields that were not set by the API will not be included, and keys will match the API response, not the property names from the model.
For example, if the API responds with
"fooBar": true
but we’ve defined afoo_bar: bool
property, the output will use the"fooBar"
key (unlessuse_api_names=False
is passed).Args: indent: Indentation to use in the JSON output. If
None
is passed, the output will be compact. Defaults to2
use_api_names: Whether to use the key that the API responded with or the property name. Defaults toTrue
. exclude_unset: Whether to exclude fields that have not been explicitly set. exclude_defaults: Whether to exclude fields that have the default value. exclude_none: Whether to exclude fields that have a value ofNone
. warnings: Whether to show any warnings that occurred during serialization. This is only supported in Pydantic v2.
- class nemo_microservices._models.CachedDiscriminatorType#
Bases:
typing_extensions.Protocol
- class nemo_microservices._models.DiscriminatorDetails(
- *,
- mapping: dict[str, type],
- discriminator_field: str,
- discriminator_alias: str | None,
Initialization
- field_alias_from: str | None#
None
The name of the discriminator field in the API response, e.g.
class Foo(BaseModel): type: Literal['foo'] = Field(alias='type_from_api')
Will result in field_alias_from=’type_from_api’
- field_name: str#
None
The name of the discriminator field in the variant class, e.g.
class Foo(BaseModel): type: Literal['foo']
Will result in field_name=’type’
- mapping: dict[str, type]#
None
Mapping of discriminator value to variant type, e.g.
{‘foo’: FooVariant, ‘bar’: BarVariant}
- class nemo_microservices._models.FinalRequestOptions(/, **data: Any)#
Bases:
pydantic.BaseModel
- classmethod construct(
- _fields_set: set[str] | None = None,
- **values: typing_extensions.Unpack[nemo_microservices._models.FinalRequestOptionsInput],
- extra_json: nemo_microservices._types.AnyMapping | None#
None
- files: nemo_microservices._types.HttpxRequestFiles | None#
None
- follow_redirects: bool | None#
None
- get_max_retries(max_retries: int) int #
- headers: nemo_microservices._types.Headers | nemo_microservices._types.NotGiven#
‘NotGiven(…)’
- idempotency_key: str | None#
None
- json_data: nemo_microservices._types.Body | None#
None
- max_retries: int | nemo_microservices._types.NotGiven#
‘NotGiven(…)’
- method: str#
None
- params: nemo_microservices._types.Query#
None
- post_parser: Callable[[Any], Any] | nemo_microservices._types.NotGiven#
‘NotGiven(…)’
- timeout: float | nemo_microservices._types.Timeout | None | nemo_microservices._types.NotGiven#
‘NotGiven(…)’
- url: str#
None
- class nemo_microservices._models.FinalRequestOptionsInput#
Bases:
typing_extensions.TypedDict
- extra_json: nemo_microservices._types.AnyMapping#
None
- files: nemo_microservices._types.HttpxRequestFiles | None#
None
- follow_redirects: bool#
None
- headers: nemo_microservices._types.Headers#
None
- idempotency_key: str#
None
- json_data: nemo_microservices._types.Body#
None
- max_retries: int#
None
- method: typing_extensions.Required[str]#
None
- params: nemo_microservices._types.Query#
None
- timeout: float | nemo_microservices._types.Timeout | None#
None
- url: typing_extensions.Required[str]#
None
- nemo_microservices._models.P#
‘ParamSpec(…)’
- nemo_microservices._models.build(
- base_model_cls: Callable[nemo_microservices._models.P, nemo_microservices._models._BaseModelT],
- *args: nemo_microservices._models.P,
- **kwargs: nemo_microservices._models.P,
Construct a BaseModel class without validation.
This is useful for cases where you need to instantiate a
BaseModel
from an API response as this provides type-safe params which isn’t supported by helpers likeconstruct_type()
.build(MyModel, my_field_a="foo", my_field_b=123)
- nemo_microservices._models.construct_type(
- *,
- value: object,
- type_: object,
- metadata: typing_extensions.List[Any] | None = None,
Loose coercion to the expected type with construction of nested values.
If the given value does not match the expected type then it is returned as-is.
- nemo_microservices._models.construct_type_unchecked(
- *,
- value: object,
- type_: type[nemo_microservices._models._T],
Loose coercion to the expected type with construction of nested values.
Note: the returned value from this function is not guaranteed to match the given type.
- nemo_microservices._models.is_basemodel(type_: type) bool #
Returns whether or not the given type is either a
BaseModel
or a union ofBaseModel
- nemo_microservices._models.is_basemodel_type(
- type_: type,
- nemo_microservices._models.set_pydantic_config(typ: Any, config: pydantic.ConfigDict) None #
Add a pydantic config for the given type.
Note: this is a no-op on Pydantic v1.
- nemo_microservices._models.validate_type(
- *,
- type_: type[nemo_microservices._models._T],
- value: object,
Strict validation that the given value matches the expected type