Usage

A data model for quickstatements.

class EntityQualifier(*, type: typing_extensions.Literal[Entity] = 'Entity', predicate: str, target: str)[source]

A qualifier that points to Wikidata entity.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

get_target() str[source]

Get the target wikidata identifier.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'predicate': FieldInfo(annotation=str, required=True, metadata=[_PydanticGeneralMetadata(pattern='^[PQS]\\d+$')]), 'target': FieldInfo(annotation=str, required=True, metadata=[_PydanticGeneralMetadata(pattern='^[PQS]\\d+$')]), 'type': FieldInfo(annotation=Literal['Entity'], required=False, default='Entity')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class DateQualifier(*, type: typing_extensions.Literal[Date] = 'Date', predicate: str, target: str)[source]

A qualifier that points to a date string.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

get_target() str[source]

Get the target date, serialized.

classmethod start_time(target: str | datetime, *, precision: int | None = None) DateQualifier[source]

Get a qualifier for a start time.

classmethod end_time(target: str | datetime, *, precision: int | None = None) DateQualifier[source]

Get a qualifier for an end time.

classmethod retrieved(namespace: typing_extensions.Literal[P, S], precision: int | None = 11) DateQualifier[source]

Get a qualifier for retrieving data now.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'predicate': FieldInfo(annotation=str, required=True, metadata=[_PydanticGeneralMetadata(pattern='^[PQS]\\d+$')]), 'target': FieldInfo(annotation=str, required=True), 'type': FieldInfo(annotation=Literal['Date'], required=False, default='Date')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class TextQualifier(*, type: typing_extensions.Literal[Text] = 'Text', predicate: str, target: str)[source]

A qualifier that points to a string literal.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

get_target() str[source]

Get the target text literal.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'predicate': FieldInfo(annotation=str, required=True, metadata=[_PydanticGeneralMetadata(pattern='^[PQS]\\d+$')]), 'target': FieldInfo(annotation=str, required=True), 'type': FieldInfo(annotation=Literal['Text'], required=False, default='Text')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

Qualifier

A union of the qualifier types

alias of Union[EntityQualifier, DateQualifier, TextQualifier][Union[EntityQualifier, DateQualifier, TextQualifier]]

class CreateLine(*, type: typing_extensions.Literal[Create] = 'Create')[source]

A trivial model representing the CREATE line.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

get_line(sep: str = '|') str[source]

Get the CREATE line.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'type': FieldInfo(annotation=Literal['Create'], required=False, default='Create')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class TextLine(*, subject: str, predicate: str, qualifiers: List[EntityQualifier | DateQualifier | TextQualifier] = None, type: typing_extensions.Literal[Text] = 'Text', target: str)[source]

A line whose target is a Wikidata entity.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

get_target() str[source]

Get the text literal line.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'predicate': FieldInfo(annotation=str, required=True, description='        The predicate can be one of two things:\n\n        1. A Wikidata predicate, which starts with an upper case letter P, followed by a sequence of digits\n        2. A combination of a single letter command code and an ISO639 language code.\n           The single letter command codes can be:\n           - ``L`` for label\n           - ``A`` for alias (i.e., synonym)\n           - ``D`` for description\n\n           See Wikidata documentation at https://www.wikidata.org/w/index.php?title=Help:QuickStatements&section=6#Adding_labels,_aliases,_descriptions_and_sitelinks\n\n        To do: add support for sitelinks.\n        ', metadata=[_PydanticGeneralMetadata(pattern='^(P\\d+)|([ADL](NL.|aa|ab|abe|abq|abs|ace|acm|adx|ady|aeb|af|agq|ajp|ak|akl|akz|aln|als|alt|ami|an|anp|aoc|apc|ar|arn|arq|ary|as|ase|ast|atj|av|awa|ay|az|azb|ba|ban|bar|bat-smg|bbc|bcl|bdr|be|bej|bfq|bg|bh|bho|bi|bjn|bla|bm|bnn|bnt-mpi|bpy|brx|bsa|bss|btm|bto|bug|bxr|bxr|byq|bzg|bzs|ca|cak|cal|ccp|cdo|ce|ceb|ch|chn|cho|chr|chy|ckb|ckt|ckv|clc|cnh|co|cop|cpx|cr|crh|crl|crs|cs|csb|ctg|cv|cy|da|dag|dar|de|de-at|de-ch|din|diq|dru|dsb|dtp|dty|dua|dz|ee|efi|egl|el|el|eml|en|en-ca|es|esu|et|ett|ext|eya|fa-af|ff|fi|fit|fiu-vro|fj|fkv|fo|fon|fos|fr|frc|fro|frr|fuf|fur|fy|ga|gaa|gag|gan|gcf|gcr|gd|gez|gil|gl|glk|gmh|gn|goh|gom|gor|gpe|grc|gsw|gsw-fr|gu|guc|guw|gv|ha|hai|hak|haw|hbo|hif|hil|ho|hoc|hrx|hsb|ht|hu|hu-formal|hyw|hz|id|ig|ii|ik|ilo|inc-ohi|inh|is|it|iu|jam|jax|jv|jv-x-bms|ka|kaa|kab|kae|kbd|kbg|kbp|kcg|kg|kha|khg|khw|ki|kiu|kjg|kjh|kjp|kk|kk-cn|kk-kz|kk-tr|kl|km|ko|koi|koy|krc|kri|krj|krl|krx|ksh|ksw|ku|ku|kum|kut|kv|kvr|kw|ky|la|lad|lag|lb|lbe|lez|lg|li|lij|liv|lki|lkt|lld|lmo|ln|lo|loz|lrc|lt|ltg|lus|luz|lv|lvk|lzz|map-bms|mfe|mg|mh|mhr|mi|mic|min|mk|ml|mn|mnc|mni|mnw|mo|moe|mr|mrh|mrj|mt|mui|mus|mwl|mwv|myv|mzn|na|nah|nan|nap|nb|nds|ne|new|nia|niu|nl|nn|no|nod|nog|nqo|nr|nrf-gg|nrf-je|nrm|nsk|nso|nui|nv|nxm|ny|oc|oj|olo|om|ood|or|os|osa|otk|ovd|pag|pam|pap|pcd|pdc|pdt|peo|pfl|pi|pih|pis|pjt|pko|pl|pms|pmy|pnt|ppu|ps|pt|pwn|pyu|qu|quc|qug|rar|rcf|rgn|rif|rki|rkt|rm|rmc|rmf|rmy|rn|ro|ru|rue|rup|ruq|rw|rwr|ryu|sa|sah|sat|sc|scn|sco|sdc|sdh|se|sei|ses|sg|sh|shi|shn|shy|sid|sjd|sje|sjm|sjt|sju|sk|sl|sli|sm|sma|smn|sms|sn|so|sou|sq|srn|srq|ss|ssf|st|sth|stq|sty|su|sv|sw|sxr|syc|syl|szl|szy|ta|tay|tce|tcy|te|tet|tg|th|ti|tk|tl|tli|tly|tn|tpi|tr|tru|trv|ts|tsg|tsk|tsu|tt|ttm|tum|tup|tvl|tvn|tw|ty|tyv|tzm|udm|uk|umu|und|uun|uz|uzs|vec|vep|vi|vls|vmf|vot|vro|wa|wal|war|wbl|wen|wls|wo|wuu|wya|wym|xal|xh|xmf|xnb|xpu|xsy|yai|yap|yav|ydg|yec|yi|yo|yoi|yrk|yrl|yue|za|zea|zgh|zh-hk|zh-min-nan|zh-mo|zh-tw|zh-yue|zh-yue|zu|zun))$')]), 'qualifiers': FieldInfo(annotation=List[Annotated[Union[quickstatements_client.model.EntityQualifier, quickstatements_client.model.DateQualifier, quickstatements_client.model.TextQualifier], FieldInfo(annotation=NoneType, required=True, discriminator='type')]], required=False, default_factory=list), 'subject': FieldInfo(annotation=str, required=True, metadata=[_PydanticGeneralMetadata(pattern='^(LAST)|(Q\\d+)$')]), 'target': FieldInfo(annotation=str, required=True), 'type': FieldInfo(annotation=Literal['Text'], required=False, default='Text')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class EntityLine(*, subject: str, predicate: str, qualifiers: List[EntityQualifier | DateQualifier | TextQualifier] = None, type: typing_extensions.Literal[Entity] = 'Entity', target: str)[source]

A line whose target is a string literal.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'predicate': FieldInfo(annotation=str, required=True, description='        The predicate can be one of two things:\n\n        1. A Wikidata predicate, which starts with an upper case letter P, followed by a sequence of digits\n        2. A combination of a single letter command code and an ISO639 language code.\n           The single letter command codes can be:\n           - ``L`` for label\n           - ``A`` for alias (i.e., synonym)\n           - ``D`` for description\n\n           See Wikidata documentation at https://www.wikidata.org/w/index.php?title=Help:QuickStatements&section=6#Adding_labels,_aliases,_descriptions_and_sitelinks\n\n        To do: add support for sitelinks.\n        ', metadata=[_PydanticGeneralMetadata(pattern='^(P\\d+)|([ADL](NL.|aa|ab|abe|abq|abs|ace|acm|adx|ady|aeb|af|agq|ajp|ak|akl|akz|aln|als|alt|ami|an|anp|aoc|apc|ar|arn|arq|ary|as|ase|ast|atj|av|awa|ay|az|azb|ba|ban|bar|bat-smg|bbc|bcl|bdr|be|bej|bfq|bg|bh|bho|bi|bjn|bla|bm|bnn|bnt-mpi|bpy|brx|bsa|bss|btm|bto|bug|bxr|bxr|byq|bzg|bzs|ca|cak|cal|ccp|cdo|ce|ceb|ch|chn|cho|chr|chy|ckb|ckt|ckv|clc|cnh|co|cop|cpx|cr|crh|crl|crs|cs|csb|ctg|cv|cy|da|dag|dar|de|de-at|de-ch|din|diq|dru|dsb|dtp|dty|dua|dz|ee|efi|egl|el|el|eml|en|en-ca|es|esu|et|ett|ext|eya|fa-af|ff|fi|fit|fiu-vro|fj|fkv|fo|fon|fos|fr|frc|fro|frr|fuf|fur|fy|ga|gaa|gag|gan|gcf|gcr|gd|gez|gil|gl|glk|gmh|gn|goh|gom|gor|gpe|grc|gsw|gsw-fr|gu|guc|guw|gv|ha|hai|hak|haw|hbo|hif|hil|ho|hoc|hrx|hsb|ht|hu|hu-formal|hyw|hz|id|ig|ii|ik|ilo|inc-ohi|inh|is|it|iu|jam|jax|jv|jv-x-bms|ka|kaa|kab|kae|kbd|kbg|kbp|kcg|kg|kha|khg|khw|ki|kiu|kjg|kjh|kjp|kk|kk-cn|kk-kz|kk-tr|kl|km|ko|koi|koy|krc|kri|krj|krl|krx|ksh|ksw|ku|ku|kum|kut|kv|kvr|kw|ky|la|lad|lag|lb|lbe|lez|lg|li|lij|liv|lki|lkt|lld|lmo|ln|lo|loz|lrc|lt|ltg|lus|luz|lv|lvk|lzz|map-bms|mfe|mg|mh|mhr|mi|mic|min|mk|ml|mn|mnc|mni|mnw|mo|moe|mr|mrh|mrj|mt|mui|mus|mwl|mwv|myv|mzn|na|nah|nan|nap|nb|nds|ne|new|nia|niu|nl|nn|no|nod|nog|nqo|nr|nrf-gg|nrf-je|nrm|nsk|nso|nui|nv|nxm|ny|oc|oj|olo|om|ood|or|os|osa|otk|ovd|pag|pam|pap|pcd|pdc|pdt|peo|pfl|pi|pih|pis|pjt|pko|pl|pms|pmy|pnt|ppu|ps|pt|pwn|pyu|qu|quc|qug|rar|rcf|rgn|rif|rki|rkt|rm|rmc|rmf|rmy|rn|ro|ru|rue|rup|ruq|rw|rwr|ryu|sa|sah|sat|sc|scn|sco|sdc|sdh|se|sei|ses|sg|sh|shi|shn|shy|sid|sjd|sje|sjm|sjt|sju|sk|sl|sli|sm|sma|smn|sms|sn|so|sou|sq|srn|srq|ss|ssf|st|sth|stq|sty|su|sv|sw|sxr|syc|syl|szl|szy|ta|tay|tce|tcy|te|tet|tg|th|ti|tk|tl|tli|tly|tn|tpi|tr|tru|trv|ts|tsg|tsk|tsu|tt|ttm|tum|tup|tvl|tvn|tw|ty|tyv|tzm|udm|uk|umu|und|uun|uz|uzs|vec|vep|vi|vls|vmf|vot|vro|wa|wal|war|wbl|wen|wls|wo|wuu|wya|wym|xal|xh|xmf|xnb|xpu|xsy|yai|yap|yav|ydg|yec|yi|yo|yoi|yrk|yrl|yue|za|zea|zgh|zh-hk|zh-min-nan|zh-mo|zh-tw|zh-yue|zh-yue|zu|zun))$')]), 'qualifiers': FieldInfo(annotation=List[Annotated[Union[quickstatements_client.model.EntityQualifier, quickstatements_client.model.DateQualifier, quickstatements_client.model.TextQualifier], FieldInfo(annotation=NoneType, required=True, discriminator='type')]], required=False, default_factory=list), 'subject': FieldInfo(annotation=str, required=True, metadata=[_PydanticGeneralMetadata(pattern='^(LAST)|(Q\\d+)$')]), 'target': FieldInfo(annotation=str, required=True, metadata=[_PydanticGeneralMetadata(pattern='^Q\\d+$')]), 'type': FieldInfo(annotation=Literal['Entity'], required=False, default='Entity')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

Line

A union of the line types

alias of Union[CreateLine, EntityLine, TextLine][Union[CreateLine, EntityLine, TextLine]]

render_lines(lines: Iterable[CreateLine | EntityLine | TextLine], sep: str = '|', newline: str = '||') str[source]

Prepare QuickStatements line objects for sending to the API.

lines_to_url(lines: Iterable[CreateLine | EntityLine | TextLine]) str[source]

Prepare a URL for V1 of QuickStatements.

lines_to_new_tab(lines: Iterable[CreateLine | EntityLine | TextLine]) bool[source]

Open a web browser on the host system.

Parameters:

lines – QuickStatements lines

Returns:

If a web browser was successfully invoked (via webbrowser.open())

A client to the QuickStatements API.

class QuickStatementsClient(*, base_url: str | None = None, token: str | None = None, username: str | None = None)[source]

A client to the QuickStatements API.

Initialize the QuickStatements API client.

Parameters:
  • base_url – The base URL of the QuickStatements instance

  • token – The token for the QuickStatements API. Get one from https://tools.wmflabs.org/quickstatements/#/user. Loads from pystow.get_config().

  • username – The username associated with the token for the QuickStatements API. Loads from pystow.get_config().

post(lines: Sequence[CreateLine | EntityLine | TextLine], batch_name: str | None = None) Response[source]

Post a batch of QuickStatements with an optional name.

static open_new_tab(lines: Sequence[CreateLine | EntityLine | TextLine])[source]

Open a web browser on the host system.

class Post(*, username: str, token: str, data: str, batchname: str | None = None, compress: int = 0, action: str = 'import', submit: int = 1, site: str = 'wikidata', format: typing_extensions.Literal[v1, csv] = 'v1')[source]

A data model representing the parameters sent to begin a batch in the QuickStatements API.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'action': FieldInfo(annotation=str, required=False, default='import'), 'batchname': FieldInfo(annotation=Union[str, NoneType], required=False), 'compress': FieldInfo(annotation=int, required=False, default=0, description='[optional; deactivates compression of CREATE and following LAST commands]'), 'data': FieldInfo(annotation=str, required=True), 'format': FieldInfo(annotation=Literal['v1', 'csv'], required=False, default='v1'), 'site': FieldInfo(annotation=str, required=False, default='wikidata'), 'submit': FieldInfo(annotation=int, required=False, default=1), 'token': FieldInfo(annotation=str, required=True), 'username': FieldInfo(annotation=str, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class Response(*, status: str, batch_id: str | None = None)[source]

A data model for the response returned by the QuickStatements API.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

property batch_url: str

Get the URL for the batch.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'batch_id': FieldInfo(annotation=Union[str, NoneType], required=False), 'status': FieldInfo(annotation=str, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.