Spotantic Models Reference

Spotantic models

class APICallModel(*, request: RequestModelT, response: ResponseT, data: DataModelT_co)

Bases: BaseModel, Generic[RequestModelT, ResponseT, DataModelT_co]

Generic container model representing an API call.

data: DataModelT_co

Represents associated or derived data.

request: RequestModelT

Represents the request.

response: ResponseT

Represents the response.

class EntityHeadersModel(*, content_type: str | None = None, content_length: int | None = None, content_encoding: str | None = None, content_language: str | None = None)

Bases: BaseModel

Model representing common HTTP entity headers.

content_encoding: str | None

Encoding transformations applied to the entity body (e.g., gzip).

content_language: str | None

Natural language(s) of the intended audience for the entity body (e.g., en).

content_length: int | None

Size of the entity body in bytes.

content_type: str | None

Media type of the entity body (e.g., application/json).

class RequestHeadersModel(*, content_type: str | None = None, content_length: int | None = None, content_encoding: str | None = None, content_language: str | None = None)

Bases: EntityHeadersModel

Model representing HTTP request headers.

Inherits common entity headers and can be extended with additional request-specific headers.

class RequestModel(*, required_scopes: set[AuthScope] = <factory>, url: HttpUrl | None = None, endpoint: str | None = None, method_type: HTTPMethod, headers: RequestHeadersModel = <factory>, params: ParamsModelT | None = None, body: BodyModelT | None = None)

Bases: BaseModel, Generic

Model representing a complete Spotify API request.

Encapsulates all information needed to make an HTTP request to the Spotify API: the endpoint URL, HTTP method, headers, query parameters, and request body.

get_url_from_endpoint() RequestModel

Populate url from endpoint if not explicitly provided.

This validator runs after model initialization. If url is already set, it is left unchanged. Otherwise, the URL is constructed by joining the configured API base URL with the provided endpoint.

Returns:

The validated model instance with url populated.

Raises:

ValueError – If neither url nor endpoint is provided.

body: BodyModelT | None

Body model for the request.

endpoint: str | None

Endpoint associated with the request.

headers: RequestHeadersModel

Headers for the request.

method_type: HTTPMethod

HTTP method for the request.

params: ParamsModelT | None

Params model for the request.

required_scopes: set[AuthScope]

Required authorization scopes for the request.

url: HttpUrl | None

Request URL. If specified, the endpoint value is ignored.