nemo_microservices._models#

Module Contents#

Classes#

Functions#

build

Construct a BaseModel class without validation.

construct_type

Loose coercion to the expected type with construction of nested values.

construct_type_unchecked

Loose coercion to the expected type with construction of nested values.

is_basemodel

Returns whether or not the given type is either a BaseModel or a union of BaseModel

is_basemodel_type

set_pydantic_config

Add a pydantic config for the given type.

validate_type

Strict validation that the given value matches the expected type

Data#

P

API#

class nemo_microservices._models.BaseModel(/, **data: Any)#

Bases: pydantic.BaseModel

classmethod construct(
_fields_set: set[str] | None = None,
**values: object,
) nemo_microservices._types.ModelT#
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,
) dict[str, object]#

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 a foo_bar: bool property, the output will use the "fooBar" key (unless use_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,
) str#

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 a foo_bar: bool property, the output will use the "fooBar" key (unless use_api_names=False is passed).

Args: indent: Indentation to use in the JSON output. If None is passed, the output will be compact. Defaults to 2 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 have the default value. exclude_none: Whether to exclude fields that have a value of None. 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],
) nemo_microservices._models.FinalRequestOptions#
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,
) nemo_microservices._models._BaseModelT#

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 like construct_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,
) object#

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],
) 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 of BaseModel

nemo_microservices._models.is_basemodel_type(
type_: type,
) typing_extensions.TypeGuard[type[nemo_microservices._models.BaseModel] | type[GenericModel]]#
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,
) nemo_microservices._models._T#

Strict validation that the given value matches the expected type