Content Search¶
The following classes are used to search for content in the Bigdata platform:
Search
: Has a method to search for stories given a list of keywords, entities, sources, etc.Document
: Represents a document, holding the information about a single result out of all the results returned by the search.
- class Search[source]¶
Class representing a search, saved or not. It allows you to perform searches in bigdata, getting documents, or get the co-mentions for that search. It also allows you to save, update, delete and share the search.
- class SearchUsage[source]¶
Internal class to hold the usage across a chain of Search objects. Whenever a Search is executed it creates a new Search object that actually performs the execution, this class is used to keep a mutable reference. FIXME: Remove when we get rid of the make_copy methods across the project.
- __init__(usage)¶
- Parameters:
usage (int) –
- Return type:
None
- __init__(api, query, id=None, name='', company_shared_permission=None, initial_usage=None)[source]¶
- Parameters:
api (BigdataConnection) –
query (AdvancedSearchQuery) –
id (Optional[str]) –
name (str) –
company_shared_permission (Optional[SharePermission]) –
initial_usage (Optional[SearchUsage]) –
The permission of this search on the company.
Note that this can’t be changed directly, and is ignored on the
save()
method. To change it, use theshare_with_company()
andunshare_with_company()
methods.
- classmethod from_query(api, query, date_range=None, sortby=SortBy.RELEVANCE, scope=DocumentType.ALL, rerank_threshold=None)[source]¶
Create a search object given a query, a date range, a scope filter and sort by
- Parameters:
api (BigdataConnection) –
query (QueryComponent) –
date_range (AbsoluteDateRange | RollingDateRange | None) –
sortby (SortBy) –
scope (DocumentType) –
rerank_threshold (float | None) –
- Return type:
- property is_saved: bool¶
Returns whether this search is saved or not. Read-only.
- limit_documents(limit)[source]¶
Return the first documents of the search as a generator.
- Parameters:
limit (int) – Provide an int to specify the number of documents to return. Provide a ChunkLimit object to specify the number of chunks to return.
- Returns:
A list of documents.
- Return type:
list[Document]
- run(limit)[source]¶
Return the first documents of the search as a list.
- Parameters:
limit (int) – Provide an int to specify the number of documents to return. Provide a ChunkLimit object to specify the number of chunks to return.
- Returns:
A list of documents.
- Return type:
list[Document]
- save(name)[source]¶
Saves a search.
After it has been saved, the
id
property of the search object will be set.- Parameters:
name (str) –
Shares a search with the whole company.
Note: If the search query contains one or more private watchlists, those will get automatically shared as well.
Makes a shared search (that you own) private
- class SearchResults[source]¶
A search with a limit. It allows you to get the count of documents, and/or get an iterator over the results.
- __init__(search, limit)[source]¶
- Parameters:
search (Search) –
limit (int | ChunkLimit) –
- class SearchResultsIteratorChunks[source]¶
Helper to iterate over the documents in all the pages. Optionally, it can skip the first request and use the first_page parameter.
- __init__(search, limit, first_page)[source]¶
- Parameters:
search (Search) –
limit (ChunkLimit) –
first_page (QueryChunksResponse | None) –
- class SearchResultsIteratorWithDocuments[source]¶
Helper to iterate over the documents in all the pages. Optionally, it can skip the first request and use the first_page parameter.
- pydantic model Document[source]¶
A document object
Show JSON schema
{ "$defs": { "Document": { "description": "A document object", "properties": { "id": { "title": "Id", "type": "string" }, "headline": { "title": "Headline", "type": "string" }, "sentiment": { "title": "Sentiment", "type": "number" }, "document_scope": { "$ref": "#/$defs/DocumentScope" }, "source": { "$ref": "#/$defs/DocumentSource" }, "timestamp": { "format": "date-time", "title": "Timestamp", "type": "string" }, "chunks": { "items": { "$ref": "#/$defs/DocumentChunk" }, "title": "Chunks", "type": "array" }, "language": { "title": "Language", "type": "string" }, "cluster": { "anyOf": [ { "items": { "$ref": "#/$defs/Document" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Cluster" }, "reporting_period": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Reporting Period" }, "document_type": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Document Type" }, "reporting_entities": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Reporting Entities" }, "url": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Url" } }, "required": [ "id", "headline", "sentiment", "document_scope", "source", "timestamp", "chunks", "language" ], "title": "Document", "type": "object" }, "DocumentChunk": { "description": "A chunk of text representing a contextual unit within the document", "properties": { "text": { "title": "Text", "type": "string" }, "chunk": { "title": "Chunk", "type": "integer" }, "entities": { "items": { "$ref": "#/$defs/DocumentSentenceEntity" }, "title": "Entities", "type": "array" }, "sentences": { "items": { "$ref": "#/$defs/DocumentSentence" }, "title": "Sentences", "type": "array" }, "relevance": { "title": "Relevance", "type": "number" }, "sentiment": { "title": "Sentiment", "type": "number" }, "section_metadata": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "title": "Section Metadata" }, "speaker": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Speaker" } }, "required": [ "text", "chunk", "entities", "sentences", "relevance", "sentiment", "section_metadata", "speaker" ], "title": "DocumentChunk", "type": "object" }, "DocumentScope": { "description": "The type of the document.", "enum": [ "news", "filings", "transcripts", "files" ], "title": "DocumentScope", "type": "string" }, "DocumentSentence": { "properties": { "paragraph": { "title": "Paragraph", "type": "integer" }, "sentence": { "title": "Sentence", "type": "integer" } }, "required": [ "paragraph", "sentence" ], "title": "DocumentSentence", "type": "object" }, "DocumentSentenceEntity": { "description": "A detection instance of an entity in a sentence", "properties": { "key": { "title": "Key", "type": "string" }, "start": { "title": "Start", "type": "integer" }, "end": { "title": "End", "type": "integer" }, "query_type": { "$ref": "#/$defs/QueryType" } }, "required": [ "key", "start", "end", "query_type" ], "title": "DocumentSentenceEntity", "type": "object" }, "DocumentSource": { "description": "The source of a document", "properties": { "key": { "title": "Key", "type": "string" }, "name": { "title": "Name", "type": "string" }, "rank": { "title": "Rank", "type": "integer" } }, "required": [ "key", "name", "rank" ], "title": "DocumentSource", "type": "object" }, "QueryType": { "enum": [ "entity", "rp_topic", "source", "language" ], "title": "QueryType", "type": "string" } }, "$ref": "#/$defs/Document" }
- field chunks: list[DocumentChunk] [Required]¶
- field document_scope: DocumentScope [Required]¶
- field document_type: str | None = None¶
- field headline: str [Required]¶
- field id: str [Required]¶
- field language: str [Required]¶
- field reporting_entities: list[str] | None = None¶
- field reporting_period: list[str] | None = None¶
- field sentiment: float [Required]¶
- field source: DocumentSource [Required]¶
- field timestamp: datetime [Required]¶
- field url: str | None = None¶
- classmethod construct(_fields_set=None, **values)¶
- Parameters:
_fields_set (set[str] | None) –
values (Any) –
- Return type:
Self
- copy(*, include=None, exclude=None, update=None, deep=False)¶
Returns a copy of the model.
- !!! warning “Deprecated”
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
`python {test="skip" lint="skip"} data = self.model_dump(include=include, exclude=exclude, round_trip=True) data = {**data, **(update or {})} copied = self.model_validate(data) `
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to include in the copied model.
exclude (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to exclude in the copied model.
update (Dict[str, Any] | None) – Optional dictionary of field-value pairs to override field values in the copied model.
deep (bool) – If True, the values of fields that are Pydantic models will be deep-copied.
- Returns:
A copy of the model with included, excluded and updated fields as specified.
- Return type:
Self
- dict(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False)¶
- Parameters:
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
by_alias (bool) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
- Return type:
Dict[str, Any]
- classmethod from_orm(obj)¶
- Parameters:
obj (Any) –
- Return type:
Self
- classmethod from_response(response, api)[source]¶
- Parameters:
response (ChunkedDocumentResponse) –
api (BigdataConnectionProtocol) –
- Return type:
- json(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=PydanticUndefined, models_as_dict=PydanticUndefined, **dumps_kwargs)¶
- Parameters:
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
by_alias (bool) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
encoder (Callable[[Any], Any] | None) –
models_as_dict (bool) –
dumps_kwargs (Any) –
- Return type:
str
- classmethod model_construct(_fields_set=None, **values)¶
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed.
- !!! note
model_construct() generally respects the model_config.extra setting on the provided model. That is, if model_config.extra == ‘allow’, then all extra passed values are added to the model instance’s __dict__ and __pydantic_extra__ fields. If model_config.extra == ‘ignore’ (the default), then all extra passed values are ignored. Because no validation is performed with a call to model_construct(), having model_config.extra == ‘forbid’ does not result in an error if extra values are passed, but they will be ignored.
- Parameters:
_fields_set (set[str] | None) – A set of field names that were originally explicitly set during instantiation. If provided, this is directly used for the [model_fields_set][pydantic.BaseModel.model_fields_set] attribute. Otherwise, the field names from the values argument will be used.
values (Any) – Trusted or pre-validated data dictionary.
- Returns:
A new instance of the Model class with validated data.
- Return type:
Self
- model_copy(*, update=None, deep=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#model_copy
Returns a copy of the model.
- Parameters:
update (Mapping[str, Any] | None) – Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data.
deep (bool) – Set to True to make a deep copy of the model.
- Returns:
New model instance.
- Return type:
Self
- model_dump(*, mode='python', include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters:
mode (Literal['json', 'python'] | str) – The mode in which to_python should run. If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – A set of fields to include in the output.
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – A set of fields to exclude from the output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool) – Whether to use the field’s alias in the dictionary key if defined.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (bool | Literal['none', 'warn', 'error']) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
- Returns:
A dictionary representation of the model.
- Return type:
dict[str, Any]
- model_dump_json(*, indent=None, include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump_json
Generates a JSON representation of the model using Pydantic’s to_json method.
- Parameters:
indent (int | None) – Indentation to use in the JSON output. If None is passed, the output will be compact.
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – Field(s) to include in the JSON output.
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – Field(s) to exclude from the JSON output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool) – Whether to serialize using field aliases.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (bool | Literal['none', 'warn', 'error']) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
- Returns:
A JSON string representation of the model.
- Return type:
str
- classmethod model_json_schema(by_alias=True, ref_template='#/$defs/{model}', schema_generator=<class 'pydantic.json_schema.GenerateJsonSchema'>, mode='validation')¶
Generates a JSON schema for a model class.
- Parameters:
by_alias (bool) – Whether to use attribute aliases or not.
ref_template (str) – The reference template.
schema_generator (type[GenerateJsonSchema]) – To override the logic used to generate the JSON schema, as a subclass of GenerateJsonSchema with your desired modifications
mode (Literal['validation', 'serialization']) – The mode in which to generate the schema.
- Returns:
The JSON schema for the given model class.
- Return type:
dict[str, Any]
- classmethod model_parametrized_name(params)¶
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
- Parameters:
params (tuple[type[Any], ...]) – Tuple of types of the class. Given a generic class Model with 2 type variables and a concrete model Model[str, int], the value (str, int) would be passed to params.
- Returns:
String representing the new class where params are passed to cls as type variables.
- Raises:
TypeError – Raised when trying to generate concrete names for non-generic models.
- Return type:
str
- model_post_init(context, /)¶
We need to both initialize private attributes and call the user-defined model_post_init method.
- Parameters:
self (BaseModel) –
context (Any) –
- Return type:
None
- classmethod model_rebuild(*, force=False, raise_errors=True, _parent_namespace_depth=2, _types_namespace=None)¶
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
- Parameters:
force (bool) – Whether to force the rebuilding of the model schema, defaults to False.
raise_errors (bool) – Whether to raise errors, defaults to True.
_parent_namespace_depth (int) – The depth level of the parent namespace, defaults to 2.
_types_namespace (MappingNamespace | None) – The types namespace, defaults to None.
- Returns:
Returns None if the schema is already “complete” and rebuilding was not required. If rebuilding _was_ required, returns True if rebuilding was successful, otherwise False.
- Return type:
bool | None
- classmethod model_validate(obj, *, strict=None, from_attributes=None, context=None)¶
Validate a pydantic model instance.
- Parameters:
obj (Any) – The object to validate.
strict (bool | None) – Whether to enforce types strictly.
from_attributes (bool | None) – Whether to extract data from object attributes.
context (Any | None) – Additional context to pass to the validator.
- Raises:
ValidationError – If the object could not be validated.
- Returns:
The validated model instance.
- Return type:
Self
- classmethod model_validate_json(json_data, *, strict=None, context=None)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/json/#json-parsing
Validate the given JSON data against the Pydantic model.
- Parameters:
json_data (str | bytes | bytearray) – The JSON data to validate.
strict (bool | None) – Whether to enforce types strictly.
context (Any | None) – Extra variables to pass to the validator.
- Returns:
The validated Pydantic model.
- Raises:
ValidationError – If json_data is not a JSON string or the object could not be validated.
- Return type:
Self
- classmethod model_validate_strings(obj, *, strict=None, context=None)¶
Validate the given object with string data against the Pydantic model.
- Parameters:
obj (Any) – The object containing string data to validate.
strict (bool | None) – Whether to enforce types strictly.
context (Any | None) – Extra variables to pass to the validator.
- Returns:
The validated Pydantic model.
- Return type:
Self
- classmethod parse_file(path, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)¶
- Parameters:
path (str | Path) –
content_type (str | None) –
encoding (str) –
proto (DeprecatedParseProtocol | None) –
allow_pickle (bool) –
- Return type:
Self
- classmethod parse_obj(obj)¶
- Parameters:
obj (Any) –
- Return type:
Self
- classmethod parse_raw(b, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)¶
- Parameters:
b (str | bytes) –
content_type (str | None) –
encoding (str) –
proto (DeprecatedParseProtocol | None) –
allow_pickle (bool) –
- Return type:
Self
- classmethod schema(by_alias=True, ref_template='#/$defs/{model}')¶
- Parameters:
by_alias (bool) –
ref_template (str) –
- Return type:
Dict[str, Any]
- classmethod schema_json(*, by_alias=True, ref_template='#/$defs/{model}', **dumps_kwargs)¶
- Parameters:
by_alias (bool) –
ref_template (str) –
dumps_kwargs (Any) –
- Return type:
str
- classmethod update_forward_refs(**localns)¶
- Parameters:
localns (Any) –
- Return type:
None
- classmethod validate(value)¶
- Parameters:
value (Any) –
- Return type:
Self
- property model_extra: dict[str, Any] | None¶
Get extra fields set during validation.
- Returns:
A dictionary of extra fields, or None if config.extra is not set to “allow”.
- property model_fields_set: set[str]¶
Returns the set of fields that have been explicitly set on this model instance.
- Returns:
- A set of strings representing the fields that have been set,
i.e. that were not filled from defaults.
- property resolved_reporting_entities¶
- pydantic model Expression[source]¶
Show JSON schema
{ "$defs": { "Expression": { "properties": { "type": { "$ref": "#/$defs/ExpressionTypes" }, "value": { "anyOf": [ { "items": { "anyOf": [ { "type": "string" }, { "type": "number" }, { "$ref": "#/$defs/Expression" } ] }, "type": "array" }, { "type": "string" }, { "type": "number" }, { "$ref": "#/$defs/Expression" } ], "title": "Value" }, "operation": { "anyOf": [ { "$ref": "#/$defs/ExpressionOperation" }, { "type": "null" } ], "default": null } }, "required": [ "type", "value" ], "title": "Expression", "type": "object" }, "ExpressionOperation": { "enum": [ "in", "all", "greater-than", "lower-than", "between" ], "title": "ExpressionOperation", "type": "string" }, "ExpressionTypes": { "enum": [ "and", "content_type", "date", "document", "rp_document_subtype", "entity", "keyword", "language", "not", "or", "reporting_entities", "reporting_period", "section_metadata", "sentiment_range", "similarity", "source", "tags", "rp_topic", "watchlist", "rp_document_version" ], "title": "ExpressionTypes", "type": "string" } }, "$ref": "#/$defs/Expression" }
- Fields:
- field operation: ExpressionOperation | None = None¶
- field type: ExpressionTypes [Required]¶
- field value: list[str | float | Expression] | str | float | Expression [Required]¶
- classmethod new(etype, values)[source]¶
- Parameters:
etype (ExpressionTypes) –
values (list[str] | None) –
- Return type:
- pydantic model FiscalQuarterValidator[source]¶
Show JSON schema
{ "title": "FiscalQuarterValidator", "type": "object", "properties": { "value": { "maximum": 4, "minimum": 1, "title": "Value", "type": "integer" } }, "required": [ "value" ] }
- Fields:
- field value: int [Required]¶
- Constraints:
ge = 1
le = 4
- pydantic model FiscalYearValidator[source]¶
Show JSON schema
{ "title": "FiscalYearValidator", "type": "object", "properties": { "value": { "minimum": 2000, "title": "Value", "type": "integer" } }, "required": [ "value" ] }
- Fields:
- field value: int [Required]¶
- Constraints:
ge = 2000
- pydantic model SearchPaginationByCursor[source]¶
Show JSON schema
{ "title": "SearchPaginationByCursor", "type": "object", "properties": { "limit": { "default": 300, "exclusiveMaximum": 1001, "exclusiveMinimum": 0, "title": "Limit", "type": "integer" }, "cursor": { "default": 1, "exclusiveMinimum": 0, "title": "Cursor", "type": "integer" } } }
- Fields:
- field cursor: int = 1¶
- Constraints:
gt = 0
- field limit: int = 300¶
- Constraints:
gt = 0
lt = 1001
- pydantic model SearchPaginationByOffset[source]¶
Show JSON schema
{ "title": "SearchPaginationByOffset", "type": "object", "properties": { "limit": { "default": 300, "exclusiveMinimum": 0, "title": "Limit", "type": "integer" }, "offset": { "default": 0, "minimum": 0, "title": "Offset", "type": "integer" } } }
- Fields:
- field limit: int = 300¶
- Constraints:
gt = 0
- field offset: int = 0¶
- Constraints:
ge = 0
- pydantic model SentimentRangeValidator[source]¶
Show JSON schema
{ "title": "SentimentRangeValidator", "type": "object", "properties": { "range_start": { "maximum": 1.0, "minimum": -1.0, "title": "Range Start", "type": "number" }, "range_end": { "maximum": 1.0, "minimum": -1.0, "title": "Range End", "type": "number" } }, "required": [ "range_start", "range_end" ] }
- Fields:
- Validators:
validate_range
»all fields
- field range_end: float [Required]¶
- Constraints:
ge = -1
le = 1
- Validated by:
- field range_start: float [Required]¶
- Constraints:
ge = -1
le = 1
- Validated by:
- pydantic model DocumentChunk[source]¶
A chunk of text representing a contextual unit within the document
Show JSON schema
{ "title": "DocumentChunk", "description": "A chunk of text representing a contextual unit within the document", "type": "object", "properties": { "text": { "title": "Text", "type": "string" }, "chunk": { "title": "Chunk", "type": "integer" }, "entities": { "items": { "$ref": "#/$defs/DocumentSentenceEntity" }, "title": "Entities", "type": "array" }, "sentences": { "items": { "$ref": "#/$defs/DocumentSentence" }, "title": "Sentences", "type": "array" }, "relevance": { "title": "Relevance", "type": "number" }, "sentiment": { "title": "Sentiment", "type": "number" }, "section_metadata": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "title": "Section Metadata" }, "speaker": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Speaker" } }, "$defs": { "DocumentSentence": { "properties": { "paragraph": { "title": "Paragraph", "type": "integer" }, "sentence": { "title": "Sentence", "type": "integer" } }, "required": [ "paragraph", "sentence" ], "title": "DocumentSentence", "type": "object" }, "DocumentSentenceEntity": { "description": "A detection instance of an entity in a sentence", "properties": { "key": { "title": "Key", "type": "string" }, "start": { "title": "Start", "type": "integer" }, "end": { "title": "End", "type": "integer" }, "query_type": { "$ref": "#/$defs/QueryType" } }, "required": [ "key", "start", "end", "query_type" ], "title": "DocumentSentenceEntity", "type": "object" }, "QueryType": { "enum": [ "entity", "rp_topic", "source", "language" ], "title": "QueryType", "type": "string" } }, "required": [ "text", "chunk", "entities", "sentences", "relevance", "sentiment", "section_metadata", "speaker" ] }
- Fields:
- field chunk: int [Required]¶
- field entities: list[DocumentSentenceEntity] [Required]¶
- field relevance: float [Required]¶
- field section_metadata: list[str] | None [Required]¶
- field sentences: list[DocumentSentence] [Required]¶
- field sentiment: float [Required]¶
- field speaker: str | None [Required]¶
- field text: str [Required]¶
- classmethod construct(_fields_set=None, **values)¶
- Parameters:
_fields_set (set[str] | None) –
values (Any) –
- Return type:
Self
- copy(*, include=None, exclude=None, update=None, deep=False)¶
Returns a copy of the model.
- !!! warning “Deprecated”
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
`python {test="skip" lint="skip"} data = self.model_dump(include=include, exclude=exclude, round_trip=True) data = {**data, **(update or {})} copied = self.model_validate(data) `
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to include in the copied model.
exclude (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to exclude in the copied model.
update (Dict[str, Any] | None) – Optional dictionary of field-value pairs to override field values in the copied model.
deep (bool) – If True, the values of fields that are Pydantic models will be deep-copied.
- Returns:
A copy of the model with included, excluded and updated fields as specified.
- Return type:
Self
- dict(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False)¶
- Parameters:
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
by_alias (bool) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
- Return type:
Dict[str, Any]
- classmethod from_orm(obj)¶
- Parameters:
obj (Any) –
- Return type:
Self
- json(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=PydanticUndefined, models_as_dict=PydanticUndefined, **dumps_kwargs)¶
- Parameters:
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
by_alias (bool) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
encoder (Callable[[Any], Any] | None) –
models_as_dict (bool) –
dumps_kwargs (Any) –
- Return type:
str
- classmethod model_construct(_fields_set=None, **values)¶
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed.
- !!! note
model_construct() generally respects the model_config.extra setting on the provided model. That is, if model_config.extra == ‘allow’, then all extra passed values are added to the model instance’s __dict__ and __pydantic_extra__ fields. If model_config.extra == ‘ignore’ (the default), then all extra passed values are ignored. Because no validation is performed with a call to model_construct(), having model_config.extra == ‘forbid’ does not result in an error if extra values are passed, but they will be ignored.
- Parameters:
_fields_set (set[str] | None) – A set of field names that were originally explicitly set during instantiation. If provided, this is directly used for the [model_fields_set][pydantic.BaseModel.model_fields_set] attribute. Otherwise, the field names from the values argument will be used.
values (Any) – Trusted or pre-validated data dictionary.
- Returns:
A new instance of the Model class with validated data.
- Return type:
Self
- model_copy(*, update=None, deep=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#model_copy
Returns a copy of the model.
- Parameters:
update (Mapping[str, Any] | None) – Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data.
deep (bool) – Set to True to make a deep copy of the model.
- Returns:
New model instance.
- Return type:
Self
- model_dump(*, mode='python', include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters:
mode (Literal['json', 'python'] | str) – The mode in which to_python should run. If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – A set of fields to include in the output.
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – A set of fields to exclude from the output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool) – Whether to use the field’s alias in the dictionary key if defined.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (bool | Literal['none', 'warn', 'error']) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
- Returns:
A dictionary representation of the model.
- Return type:
dict[str, Any]
- model_dump_json(*, indent=None, include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump_json
Generates a JSON representation of the model using Pydantic’s to_json method.
- Parameters:
indent (int | None) – Indentation to use in the JSON output. If None is passed, the output will be compact.
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – Field(s) to include in the JSON output.
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – Field(s) to exclude from the JSON output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool) – Whether to serialize using field aliases.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (bool | Literal['none', 'warn', 'error']) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
- Returns:
A JSON string representation of the model.
- Return type:
str
- classmethod model_json_schema(by_alias=True, ref_template='#/$defs/{model}', schema_generator=<class 'pydantic.json_schema.GenerateJsonSchema'>, mode='validation')¶
Generates a JSON schema for a model class.
- Parameters:
by_alias (bool) – Whether to use attribute aliases or not.
ref_template (str) – The reference template.
schema_generator (type[GenerateJsonSchema]) – To override the logic used to generate the JSON schema, as a subclass of GenerateJsonSchema with your desired modifications
mode (Literal['validation', 'serialization']) – The mode in which to generate the schema.
- Returns:
The JSON schema for the given model class.
- Return type:
dict[str, Any]
- classmethod model_parametrized_name(params)¶
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
- Parameters:
params (tuple[type[Any], ...]) – Tuple of types of the class. Given a generic class Model with 2 type variables and a concrete model Model[str, int], the value (str, int) would be passed to params.
- Returns:
String representing the new class where params are passed to cls as type variables.
- Raises:
TypeError – Raised when trying to generate concrete names for non-generic models.
- Return type:
str
- model_post_init(context, /)¶
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self (BaseModel) – The BaseModel instance.
context (Any) – The context.
- Return type:
None
- classmethod model_rebuild(*, force=False, raise_errors=True, _parent_namespace_depth=2, _types_namespace=None)¶
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
- Parameters:
force (bool) – Whether to force the rebuilding of the model schema, defaults to False.
raise_errors (bool) – Whether to raise errors, defaults to True.
_parent_namespace_depth (int) – The depth level of the parent namespace, defaults to 2.
_types_namespace (MappingNamespace | None) – The types namespace, defaults to None.
- Returns:
Returns None if the schema is already “complete” and rebuilding was not required. If rebuilding _was_ required, returns True if rebuilding was successful, otherwise False.
- Return type:
bool | None
- classmethod model_validate(obj, *, strict=None, from_attributes=None, context=None)¶
Validate a pydantic model instance.
- Parameters:
obj (Any) – The object to validate.
strict (bool | None) – Whether to enforce types strictly.
from_attributes (bool | None) – Whether to extract data from object attributes.
context (Any | None) – Additional context to pass to the validator.
- Raises:
ValidationError – If the object could not be validated.
- Returns:
The validated model instance.
- Return type:
Self
- classmethod model_validate_json(json_data, *, strict=None, context=None)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/json/#json-parsing
Validate the given JSON data against the Pydantic model.
- Parameters:
json_data (str | bytes | bytearray) – The JSON data to validate.
strict (bool | None) – Whether to enforce types strictly.
context (Any | None) – Extra variables to pass to the validator.
- Returns:
The validated Pydantic model.
- Raises:
ValidationError – If json_data is not a JSON string or the object could not be validated.
- Return type:
Self
- classmethod model_validate_strings(obj, *, strict=None, context=None)¶
Validate the given object with string data against the Pydantic model.
- Parameters:
obj (Any) – The object containing string data to validate.
strict (bool | None) – Whether to enforce types strictly.
context (Any | None) – Extra variables to pass to the validator.
- Returns:
The validated Pydantic model.
- Return type:
Self
- classmethod parse_file(path, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)¶
- Parameters:
path (str | Path) –
content_type (str | None) –
encoding (str) –
proto (DeprecatedParseProtocol | None) –
allow_pickle (bool) –
- Return type:
Self
- classmethod parse_obj(obj)¶
- Parameters:
obj (Any) –
- Return type:
Self
- classmethod parse_raw(b, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)¶
- Parameters:
b (str | bytes) –
content_type (str | None) –
encoding (str) –
proto (DeprecatedParseProtocol | None) –
allow_pickle (bool) –
- Return type:
Self
- classmethod schema(by_alias=True, ref_template='#/$defs/{model}')¶
- Parameters:
by_alias (bool) –
ref_template (str) –
- Return type:
Dict[str, Any]
- classmethod schema_json(*, by_alias=True, ref_template='#/$defs/{model}', **dumps_kwargs)¶
- Parameters:
by_alias (bool) –
ref_template (str) –
dumps_kwargs (Any) –
- Return type:
str
- classmethod update_forward_refs(**localns)¶
- Parameters:
localns (Any) –
- Return type:
None
- classmethod validate(value)¶
- Parameters:
value (Any) –
- Return type:
Self
- property model_extra: dict[str, Any] | None¶
Get extra fields set during validation.
- Returns:
A dictionary of extra fields, or None if config.extra is not set to “allow”.
- property model_fields_set: set[str]¶
Returns the set of fields that have been explicitly set on this model instance.
- Returns:
- A set of strings representing the fields that have been set,
i.e. that were not filled from defaults.
- property resolved_speaker¶
- pydantic model DocumentSentence[source]¶
Show JSON schema
{ "title": "DocumentSentence", "type": "object", "properties": { "paragraph": { "title": "Paragraph", "type": "integer" }, "sentence": { "title": "Sentence", "type": "integer" } }, "required": [ "paragraph", "sentence" ] }
- Fields:
- field paragraph: int [Required]¶
- field sentence: int [Required]¶
- classmethod construct(_fields_set=None, **values)¶
- Parameters:
_fields_set (set[str] | None) –
values (Any) –
- Return type:
Self
- copy(*, include=None, exclude=None, update=None, deep=False)¶
Returns a copy of the model.
- !!! warning “Deprecated”
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
`python {test="skip" lint="skip"} data = self.model_dump(include=include, exclude=exclude, round_trip=True) data = {**data, **(update or {})} copied = self.model_validate(data) `
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to include in the copied model.
exclude (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to exclude in the copied model.
update (Dict[str, Any] | None) – Optional dictionary of field-value pairs to override field values in the copied model.
deep (bool) – If True, the values of fields that are Pydantic models will be deep-copied.
- Returns:
A copy of the model with included, excluded and updated fields as specified.
- Return type:
Self
- dict(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False)¶
- Parameters:
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
by_alias (bool) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
- Return type:
Dict[str, Any]
- classmethod from_orm(obj)¶
- Parameters:
obj (Any) –
- Return type:
Self
- json(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=PydanticUndefined, models_as_dict=PydanticUndefined, **dumps_kwargs)¶
- Parameters:
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
by_alias (bool) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
encoder (Callable[[Any], Any] | None) –
models_as_dict (bool) –
dumps_kwargs (Any) –
- Return type:
str
- classmethod model_construct(_fields_set=None, **values)¶
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed.
- !!! note
model_construct() generally respects the model_config.extra setting on the provided model. That is, if model_config.extra == ‘allow’, then all extra passed values are added to the model instance’s __dict__ and __pydantic_extra__ fields. If model_config.extra == ‘ignore’ (the default), then all extra passed values are ignored. Because no validation is performed with a call to model_construct(), having model_config.extra == ‘forbid’ does not result in an error if extra values are passed, but they will be ignored.
- Parameters:
_fields_set (set[str] | None) – A set of field names that were originally explicitly set during instantiation. If provided, this is directly used for the [model_fields_set][pydantic.BaseModel.model_fields_set] attribute. Otherwise, the field names from the values argument will be used.
values (Any) – Trusted or pre-validated data dictionary.
- Returns:
A new instance of the Model class with validated data.
- Return type:
Self
- model_copy(*, update=None, deep=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#model_copy
Returns a copy of the model.
- Parameters:
update (Mapping[str, Any] | None) – Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data.
deep (bool) – Set to True to make a deep copy of the model.
- Returns:
New model instance.
- Return type:
Self
- model_dump(*, mode='python', include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters:
mode (Literal['json', 'python'] | str) – The mode in which to_python should run. If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – A set of fields to include in the output.
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – A set of fields to exclude from the output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool) – Whether to use the field’s alias in the dictionary key if defined.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (bool | Literal['none', 'warn', 'error']) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
- Returns:
A dictionary representation of the model.
- Return type:
dict[str, Any]
- model_dump_json(*, indent=None, include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump_json
Generates a JSON representation of the model using Pydantic’s to_json method.
- Parameters:
indent (int | None) – Indentation to use in the JSON output. If None is passed, the output will be compact.
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – Field(s) to include in the JSON output.
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – Field(s) to exclude from the JSON output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool) – Whether to serialize using field aliases.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (bool | Literal['none', 'warn', 'error']) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
- Returns:
A JSON string representation of the model.
- Return type:
str
- classmethod model_json_schema(by_alias=True, ref_template='#/$defs/{model}', schema_generator=<class 'pydantic.json_schema.GenerateJsonSchema'>, mode='validation')¶
Generates a JSON schema for a model class.
- Parameters:
by_alias (bool) – Whether to use attribute aliases or not.
ref_template (str) – The reference template.
schema_generator (type[GenerateJsonSchema]) – To override the logic used to generate the JSON schema, as a subclass of GenerateJsonSchema with your desired modifications
mode (Literal['validation', 'serialization']) – The mode in which to generate the schema.
- Returns:
The JSON schema for the given model class.
- Return type:
dict[str, Any]
- classmethod model_parametrized_name(params)¶
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
- Parameters:
params (tuple[type[Any], ...]) – Tuple of types of the class. Given a generic class Model with 2 type variables and a concrete model Model[str, int], the value (str, int) would be passed to params.
- Returns:
String representing the new class where params are passed to cls as type variables.
- Raises:
TypeError – Raised when trying to generate concrete names for non-generic models.
- Return type:
str
- model_post_init(_BaseModel__context)¶
Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.
- Parameters:
_BaseModel__context (Any) –
- Return type:
None
- classmethod model_rebuild(*, force=False, raise_errors=True, _parent_namespace_depth=2, _types_namespace=None)¶
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
- Parameters:
force (bool) – Whether to force the rebuilding of the model schema, defaults to False.
raise_errors (bool) – Whether to raise errors, defaults to True.
_parent_namespace_depth (int) – The depth level of the parent namespace, defaults to 2.
_types_namespace (MappingNamespace | None) – The types namespace, defaults to None.
- Returns:
Returns None if the schema is already “complete” and rebuilding was not required. If rebuilding _was_ required, returns True if rebuilding was successful, otherwise False.
- Return type:
bool | None
- classmethod model_validate(obj, *, strict=None, from_attributes=None, context=None)¶
Validate a pydantic model instance.
- Parameters:
obj (Any) – The object to validate.
strict (bool | None) – Whether to enforce types strictly.
from_attributes (bool | None) – Whether to extract data from object attributes.
context (Any | None) – Additional context to pass to the validator.
- Raises:
ValidationError – If the object could not be validated.
- Returns:
The validated model instance.
- Return type:
Self
- classmethod model_validate_json(json_data, *, strict=None, context=None)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/json/#json-parsing
Validate the given JSON data against the Pydantic model.
- Parameters:
json_data (str | bytes | bytearray) – The JSON data to validate.
strict (bool | None) – Whether to enforce types strictly.
context (Any | None) – Extra variables to pass to the validator.
- Returns:
The validated Pydantic model.
- Raises:
ValidationError – If json_data is not a JSON string or the object could not be validated.
- Return type:
Self
- classmethod model_validate_strings(obj, *, strict=None, context=None)¶
Validate the given object with string data against the Pydantic model.
- Parameters:
obj (Any) – The object containing string data to validate.
strict (bool | None) – Whether to enforce types strictly.
context (Any | None) – Extra variables to pass to the validator.
- Returns:
The validated Pydantic model.
- Return type:
Self
- classmethod parse_file(path, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)¶
- Parameters:
path (str | Path) –
content_type (str | None) –
encoding (str) –
proto (DeprecatedParseProtocol | None) –
allow_pickle (bool) –
- Return type:
Self
- classmethod parse_obj(obj)¶
- Parameters:
obj (Any) –
- Return type:
Self
- classmethod parse_raw(b, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)¶
- Parameters:
b (str | bytes) –
content_type (str | None) –
encoding (str) –
proto (DeprecatedParseProtocol | None) –
allow_pickle (bool) –
- Return type:
Self
- classmethod schema(by_alias=True, ref_template='#/$defs/{model}')¶
- Parameters:
by_alias (bool) –
ref_template (str) –
- Return type:
Dict[str, Any]
- classmethod schema_json(*, by_alias=True, ref_template='#/$defs/{model}', **dumps_kwargs)¶
- Parameters:
by_alias (bool) –
ref_template (str) –
dumps_kwargs (Any) –
- Return type:
str
- classmethod update_forward_refs(**localns)¶
- Parameters:
localns (Any) –
- Return type:
None
- classmethod validate(value)¶
- Parameters:
value (Any) –
- Return type:
Self
- property model_extra: dict[str, Any] | None¶
Get extra fields set during validation.
- Returns:
A dictionary of extra fields, or None if config.extra is not set to “allow”.
- property model_fields_set: set[str]¶
Returns the set of fields that have been explicitly set on this model instance.
- Returns:
- A set of strings representing the fields that have been set,
i.e. that were not filled from defaults.
- pydantic model DocumentSentenceEntity[source]¶
A detection instance of an entity in a sentence
Show JSON schema
{ "title": "DocumentSentenceEntity", "description": "A detection instance of an entity in a sentence", "type": "object", "properties": { "key": { "title": "Key", "type": "string" }, "start": { "title": "Start", "type": "integer" }, "end": { "title": "End", "type": "integer" }, "query_type": { "$ref": "#/$defs/QueryType" } }, "$defs": { "QueryType": { "enum": [ "entity", "rp_topic", "source", "language" ], "title": "QueryType", "type": "string" } }, "required": [ "key", "start", "end", "query_type" ] }
- field end: int [Required]¶
- field key: str [Required]¶
- field query_type: QueryType [Required]¶
- field start: int [Required]¶
- classmethod construct(_fields_set=None, **values)¶
- Parameters:
_fields_set (set[str] | None) –
values (Any) –
- Return type:
Self
- copy(*, include=None, exclude=None, update=None, deep=False)¶
Returns a copy of the model.
- !!! warning “Deprecated”
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
`python {test="skip" lint="skip"} data = self.model_dump(include=include, exclude=exclude, round_trip=True) data = {**data, **(update or {})} copied = self.model_validate(data) `
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to include in the copied model.
exclude (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to exclude in the copied model.
update (Dict[str, Any] | None) – Optional dictionary of field-value pairs to override field values in the copied model.
deep (bool) – If True, the values of fields that are Pydantic models will be deep-copied.
- Returns:
A copy of the model with included, excluded and updated fields as specified.
- Return type:
Self
- dict(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False)¶
- Parameters:
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
by_alias (bool) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
- Return type:
Dict[str, Any]
- classmethod from_orm(obj)¶
- Parameters:
obj (Any) –
- Return type:
Self
- json(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=PydanticUndefined, models_as_dict=PydanticUndefined, **dumps_kwargs)¶
- Parameters:
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
by_alias (bool) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
encoder (Callable[[Any], Any] | None) –
models_as_dict (bool) –
dumps_kwargs (Any) –
- Return type:
str
- classmethod model_construct(_fields_set=None, **values)¶
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed.
- !!! note
model_construct() generally respects the model_config.extra setting on the provided model. That is, if model_config.extra == ‘allow’, then all extra passed values are added to the model instance’s __dict__ and __pydantic_extra__ fields. If model_config.extra == ‘ignore’ (the default), then all extra passed values are ignored. Because no validation is performed with a call to model_construct(), having model_config.extra == ‘forbid’ does not result in an error if extra values are passed, but they will be ignored.
- Parameters:
_fields_set (set[str] | None) – A set of field names that were originally explicitly set during instantiation. If provided, this is directly used for the [model_fields_set][pydantic.BaseModel.model_fields_set] attribute. Otherwise, the field names from the values argument will be used.
values (Any) – Trusted or pre-validated data dictionary.
- Returns:
A new instance of the Model class with validated data.
- Return type:
Self
- model_copy(*, update=None, deep=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#model_copy
Returns a copy of the model.
- Parameters:
update (Mapping[str, Any] | None) – Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data.
deep (bool) – Set to True to make a deep copy of the model.
- Returns:
New model instance.
- Return type:
Self
- model_dump(*, mode='python', include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters:
mode (Literal['json', 'python'] | str) – The mode in which to_python should run. If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – A set of fields to include in the output.
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – A set of fields to exclude from the output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool) – Whether to use the field’s alias in the dictionary key if defined.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (bool | Literal['none', 'warn', 'error']) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
- Returns:
A dictionary representation of the model.
- Return type:
dict[str, Any]
- model_dump_json(*, indent=None, include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump_json
Generates a JSON representation of the model using Pydantic’s to_json method.
- Parameters:
indent (int | None) – Indentation to use in the JSON output. If None is passed, the output will be compact.
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – Field(s) to include in the JSON output.
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – Field(s) to exclude from the JSON output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool) – Whether to serialize using field aliases.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (bool | Literal['none', 'warn', 'error']) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
- Returns:
A JSON string representation of the model.
- Return type:
str
- classmethod model_json_schema(by_alias=True, ref_template='#/$defs/{model}', schema_generator=<class 'pydantic.json_schema.GenerateJsonSchema'>, mode='validation')¶
Generates a JSON schema for a model class.
- Parameters:
by_alias (bool) – Whether to use attribute aliases or not.
ref_template (str) – The reference template.
schema_generator (type[GenerateJsonSchema]) – To override the logic used to generate the JSON schema, as a subclass of GenerateJsonSchema with your desired modifications
mode (Literal['validation', 'serialization']) – The mode in which to generate the schema.
- Returns:
The JSON schema for the given model class.
- Return type:
dict[str, Any]
- classmethod model_parametrized_name(params)¶
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
- Parameters:
params (tuple[type[Any], ...]) – Tuple of types of the class. Given a generic class Model with 2 type variables and a concrete model Model[str, int], the value (str, int) would be passed to params.
- Returns:
String representing the new class where params are passed to cls as type variables.
- Raises:
TypeError – Raised when trying to generate concrete names for non-generic models.
- Return type:
str
- model_post_init(_BaseModel__context)¶
Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.
- Parameters:
_BaseModel__context (Any) –
- Return type:
None
- classmethod model_rebuild(*, force=False, raise_errors=True, _parent_namespace_depth=2, _types_namespace=None)¶
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
- Parameters:
force (bool) – Whether to force the rebuilding of the model schema, defaults to False.
raise_errors (bool) – Whether to raise errors, defaults to True.
_parent_namespace_depth (int) – The depth level of the parent namespace, defaults to 2.
_types_namespace (MappingNamespace | None) – The types namespace, defaults to None.
- Returns:
Returns None if the schema is already “complete” and rebuilding was not required. If rebuilding _was_ required, returns True if rebuilding was successful, otherwise False.
- Return type:
bool | None
- classmethod model_validate(obj, *, strict=None, from_attributes=None, context=None)¶
Validate a pydantic model instance.
- Parameters:
obj (Any) – The object to validate.
strict (bool | None) – Whether to enforce types strictly.
from_attributes (bool | None) – Whether to extract data from object attributes.
context (Any | None) – Additional context to pass to the validator.
- Raises:
ValidationError – If the object could not be validated.
- Returns:
The validated model instance.
- Return type:
Self
- classmethod model_validate_json(json_data, *, strict=None, context=None)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/json/#json-parsing
Validate the given JSON data against the Pydantic model.
- Parameters:
json_data (str | bytes | bytearray) – The JSON data to validate.
strict (bool | None) – Whether to enforce types strictly.
context (Any | None) – Extra variables to pass to the validator.
- Returns:
The validated Pydantic model.
- Raises:
ValidationError – If json_data is not a JSON string or the object could not be validated.
- Return type:
Self
- classmethod model_validate_strings(obj, *, strict=None, context=None)¶
Validate the given object with string data against the Pydantic model.
- Parameters:
obj (Any) – The object containing string data to validate.
strict (bool | None) – Whether to enforce types strictly.
context (Any | None) – Extra variables to pass to the validator.
- Returns:
The validated Pydantic model.
- Return type:
Self
- classmethod parse_file(path, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)¶
- Parameters:
path (str | Path) –
content_type (str | None) –
encoding (str) –
proto (DeprecatedParseProtocol | None) –
allow_pickle (bool) –
- Return type:
Self
- classmethod parse_obj(obj)¶
- Parameters:
obj (Any) –
- Return type:
Self
- classmethod parse_raw(b, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)¶
- Parameters:
b (str | bytes) –
content_type (str | None) –
encoding (str) –
proto (DeprecatedParseProtocol | None) –
allow_pickle (bool) –
- Return type:
Self
- classmethod schema(by_alias=True, ref_template='#/$defs/{model}')¶
- Parameters:
by_alias (bool) –
ref_template (str) –
- Return type:
Dict[str, Any]
- classmethod schema_json(*, by_alias=True, ref_template='#/$defs/{model}', **dumps_kwargs)¶
- Parameters:
by_alias (bool) –
ref_template (str) –
dumps_kwargs (Any) –
- Return type:
str
- classmethod update_forward_refs(**localns)¶
- Parameters:
localns (Any) –
- Return type:
None
- classmethod validate(value)¶
- Parameters:
value (Any) –
- Return type:
Self
- property model_extra: dict[str, Any] | None¶
Get extra fields set during validation.
- Returns:
A dictionary of extra fields, or None if config.extra is not set to “allow”.
- property model_fields_set: set[str]¶
Returns the set of fields that have been explicitly set on this model instance.
- Returns:
- A set of strings representing the fields that have been set,
i.e. that were not filled from defaults.
- pydantic model DocumentSource[source]¶
The source of a document
Show JSON schema
{ "title": "DocumentSource", "description": "The source of a document", "type": "object", "properties": { "key": { "title": "Key", "type": "string" }, "name": { "title": "Name", "type": "string" }, "rank": { "title": "Rank", "type": "integer" } }, "required": [ "key", "name", "rank" ] }
- Fields:
- field key: str [Required]¶
- field name: str [Required]¶
- field rank: int [Required]¶
- classmethod construct(_fields_set=None, **values)¶
- Parameters:
_fields_set (set[str] | None) –
values (Any) –
- Return type:
Self
- copy(*, include=None, exclude=None, update=None, deep=False)¶
Returns a copy of the model.
- !!! warning “Deprecated”
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
`python {test="skip" lint="skip"} data = self.model_dump(include=include, exclude=exclude, round_trip=True) data = {**data, **(update or {})} copied = self.model_validate(data) `
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to include in the copied model.
exclude (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to exclude in the copied model.
update (Dict[str, Any] | None) – Optional dictionary of field-value pairs to override field values in the copied model.
deep (bool) – If True, the values of fields that are Pydantic models will be deep-copied.
- Returns:
A copy of the model with included, excluded and updated fields as specified.
- Return type:
Self
- dict(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False)¶
- Parameters:
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
by_alias (bool) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
- Return type:
Dict[str, Any]
- classmethod from_orm(obj)¶
- Parameters:
obj (Any) –
- Return type:
Self
- json(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=PydanticUndefined, models_as_dict=PydanticUndefined, **dumps_kwargs)¶
- Parameters:
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) –
by_alias (bool) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
encoder (Callable[[Any], Any] | None) –
models_as_dict (bool) –
dumps_kwargs (Any) –
- Return type:
str
- classmethod model_construct(_fields_set=None, **values)¶
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed.
- !!! note
model_construct() generally respects the model_config.extra setting on the provided model. That is, if model_config.extra == ‘allow’, then all extra passed values are added to the model instance’s __dict__ and __pydantic_extra__ fields. If model_config.extra == ‘ignore’ (the default), then all extra passed values are ignored. Because no validation is performed with a call to model_construct(), having model_config.extra == ‘forbid’ does not result in an error if extra values are passed, but they will be ignored.
- Parameters:
_fields_set (set[str] | None) – A set of field names that were originally explicitly set during instantiation. If provided, this is directly used for the [model_fields_set][pydantic.BaseModel.model_fields_set] attribute. Otherwise, the field names from the values argument will be used.
values (Any) – Trusted or pre-validated data dictionary.
- Returns:
A new instance of the Model class with validated data.
- Return type:
Self
- model_copy(*, update=None, deep=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#model_copy
Returns a copy of the model.
- Parameters:
update (Mapping[str, Any] | None) – Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data.
deep (bool) – Set to True to make a deep copy of the model.
- Returns:
New model instance.
- Return type:
Self
- model_dump(*, mode='python', include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters:
mode (Literal['json', 'python'] | str) – The mode in which to_python should run. If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – A set of fields to include in the output.
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – A set of fields to exclude from the output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool) – Whether to use the field’s alias in the dictionary key if defined.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (bool | Literal['none', 'warn', 'error']) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
- Returns:
A dictionary representation of the model.
- Return type:
dict[str, Any]
- model_dump_json(*, indent=None, include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump_json
Generates a JSON representation of the model using Pydantic’s to_json method.
- Parameters:
indent (int | None) – Indentation to use in the JSON output. If None is passed, the output will be compact.
include (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – Field(s) to include in the JSON output.
exclude (Set[int] | Set[str] | Mapping[int, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, Set[int] | Set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – Field(s) to exclude from the JSON output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool) – Whether to serialize using field aliases.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (bool | Literal['none', 'warn', 'error']) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
- Returns:
A JSON string representation of the model.
- Return type:
str
- classmethod model_json_schema(by_alias=True, ref_template='#/$defs/{model}', schema_generator=<class 'pydantic.json_schema.GenerateJsonSchema'>, mode='validation')¶
Generates a JSON schema for a model class.
- Parameters:
by_alias (bool) – Whether to use attribute aliases or not.
ref_template (str) – The reference template.
schema_generator (type[GenerateJsonSchema]) – To override the logic used to generate the JSON schema, as a subclass of GenerateJsonSchema with your desired modifications
mode (Literal['validation', 'serialization']) – The mode in which to generate the schema.
- Returns:
The JSON schema for the given model class.
- Return type:
dict[str, Any]
- classmethod model_parametrized_name(params)¶
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
- Parameters:
params (tuple[type[Any], ...]) – Tuple of types of the class. Given a generic class Model with 2 type variables and a concrete model Model[str, int], the value (str, int) would be passed to params.
- Returns:
String representing the new class where params are passed to cls as type variables.
- Raises:
TypeError – Raised when trying to generate concrete names for non-generic models.
- Return type:
str
- model_post_init(_BaseModel__context)¶
Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.
- Parameters:
_BaseModel__context (Any) –
- Return type:
None
- classmethod model_rebuild(*, force=False, raise_errors=True, _parent_namespace_depth=2, _types_namespace=None)¶
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
- Parameters:
force (bool) – Whether to force the rebuilding of the model schema, defaults to False.
raise_errors (bool) – Whether to raise errors, defaults to True.
_parent_namespace_depth (int) – The depth level of the parent namespace, defaults to 2.
_types_namespace (MappingNamespace | None) – The types namespace, defaults to None.
- Returns:
Returns None if the schema is already “complete” and rebuilding was not required. If rebuilding _was_ required, returns True if rebuilding was successful, otherwise False.
- Return type:
bool | None
- classmethod model_validate(obj, *, strict=None, from_attributes=None, context=None)¶
Validate a pydantic model instance.
- Parameters:
obj (Any) – The object to validate.
strict (bool | None) – Whether to enforce types strictly.
from_attributes (bool | None) – Whether to extract data from object attributes.
context (Any | None) – Additional context to pass to the validator.
- Raises:
ValidationError – If the object could not be validated.
- Returns:
The validated model instance.
- Return type:
Self
- classmethod model_validate_json(json_data, *, strict=None, context=None)¶
Usage docs: https://docs.pydantic.dev/2.10/concepts/json/#json-parsing
Validate the given JSON data against the Pydantic model.
- Parameters:
json_data (str | bytes | bytearray) – The JSON data to validate.
strict (bool | None) – Whether to enforce types strictly.
context (Any | None) – Extra variables to pass to the validator.
- Returns:
The validated Pydantic model.
- Raises:
ValidationError – If json_data is not a JSON string or the object could not be validated.
- Return type:
Self
- classmethod model_validate_strings(obj, *, strict=None, context=None)¶
Validate the given object with string data against the Pydantic model.
- Parameters:
obj (Any) – The object containing string data to validate.
strict (bool | None) – Whether to enforce types strictly.
context (Any | None) – Extra variables to pass to the validator.
- Returns:
The validated Pydantic model.
- Return type:
Self
- classmethod parse_file(path, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)¶
- Parameters:
path (str | Path) –
content_type (str | None) –
encoding (str) –
proto (DeprecatedParseProtocol | None) –
allow_pickle (bool) –
- Return type:
Self
- classmethod parse_obj(obj)¶
- Parameters:
obj (Any) –
- Return type:
Self
- classmethod parse_raw(b, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)¶
- Parameters:
b (str | bytes) –
content_type (str | None) –
encoding (str) –
proto (DeprecatedParseProtocol | None) –
allow_pickle (bool) –
- Return type:
Self
- classmethod schema(by_alias=True, ref_template='#/$defs/{model}')¶
- Parameters:
by_alias (bool) –
ref_template (str) –
- Return type:
Dict[str, Any]
- classmethod schema_json(*, by_alias=True, ref_template='#/$defs/{model}', **dumps_kwargs)¶
- Parameters:
by_alias (bool) –
ref_template (str) –
dumps_kwargs (Any) –
- Return type:
str
- classmethod update_forward_refs(**localns)¶
- Parameters:
localns (Any) –
- Return type:
None
- classmethod validate(value)¶
- Parameters:
value (Any) –
- Return type:
Self
- property model_extra: dict[str, Any] | None¶
Get extra fields set during validation.
- Returns:
A dictionary of extra fields, or None if config.extra is not set to “allow”.
- property model_fields_set: set[str]¶
Returns the set of fields that have been explicitly set on this model instance.
- Returns:
- A set of strings representing the fields that have been set,
i.e. that were not filled from defaults.
- class AbsoluteDateRange[source]¶
A date range with a start and end date
The __init__ method accepts either datetime objects or strings in ISO format:
>>> ran1 = AbsoluteDateRange(datetime(2021, 1, 1), datetime(2021, 1, 2)) >>> ran2 = AbsoluteDateRange("2021-01-01T00:00:00", "2021-01-02T00:00:00") >>> ran1 == ran2 True
You can also use the to_string_tuple method to convert the datetimes to strings:
>>> ran1 AbsoluteDateRange('2021-01-01T00:00:00', '2021-01-02T00:00:00') >>> start, end = ran1.to_string_tuple() >>> start '2021-01-01T00:00:00' >>> end '2021-01-02T00:00:00'
- __init__(start, end)[source]¶
Creates a new AbsoluteDateRange from two datetimes or strings.
- Parameters:
start (datetime | str | None) –
end (datetime | str | None) –
- to_string_tuple()[source]¶
Converts datetimes to strings and returns the tuple
>>> ran = AbsoluteDateRange(datetime(2021, 1, 1), datetime(2021, 1, 2)) >>> ran.to_string_tuple() ('2021-01-01T00:00:00', '2021-01-02T00:00:00')
>>> ran2 = AbsoluteDateRange(None, datetime(2021, 1, 2)) >>> ran2.to_string_tuple() (None, '2021-01-02T00:00:00')
>>> ran3 = AbsoluteDateRange(datetime(2021, 1, 1), None) >>> ran3.to_string_tuple() ('2021-01-01T00:00:00', None)
>>> ran4 = AbsoluteDateRange(*ran.to_string_tuple()) >>> ran == ran4 True
- Return type:
tuple[str | None, str | None]