Usage

A data model for quickstatements.

class CreateLine(*, type: 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_config = {}

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

class DateLine(*, subject: ~typing.Annotated[str, _PydanticGeneralMetadata(pattern='^(LAST)|(Q\\d+)$')], predicate: ~typing.Annotated[str, _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: list[~typing.Annotated[~quickstatements_client.model.EntityQualifier | ~quickstatements_client.model.DateQualifier | ~quickstatements_client.model.TextQualifier, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] = <factory>, type: ~typing.Literal['Date'] = 'Date', target: ~datetime.datetime | ~datetime.date, precision: int | None = None)[source]

A line whose target is a date/datetime.

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 date literal line.

model_config = {}

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

class DateQualifier(*, type: Literal['Date'] = 'Date', predicate: Annotated[str, _PydanticGeneralMetadata(pattern='^[PQS]\\d+$')], 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 point_in_time(target: str | datetime | date, *, precision: int | None = None) DateQualifier[source]

Get a qualifier for a point in time.

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

Get a qualifier for a start time.

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

Get a qualifier for an end time.

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

Get a qualifier for retrieving data now.

model_config = {}

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

class EntityLine(*, subject: ~typing.Annotated[str, _PydanticGeneralMetadata(pattern='^(LAST)|(Q\\d+)$')], predicate: ~typing.Annotated[str, _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: list[~typing.Annotated[~quickstatements_client.model.EntityQualifier | ~quickstatements_client.model.DateQualifier | ~quickstatements_client.model.TextQualifier, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] = <factory>, type: ~typing.Literal['Entity'] = 'Entity', target: ~typing.Annotated[str, _PydanticGeneralMetadata(pattern='^Q\\d+$')])[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_config = {}

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

class EntityQualifier(*, type: Literal['Entity'] = 'Entity', predicate: Annotated[str, _PydanticGeneralMetadata(pattern='^[PQS]\\d+$')], target: Annotated[str, _PydanticGeneralMetadata(pattern='^[PQS]\\d+$')])[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_config = {}

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

Line

A union of the line types

alias of Annotated[CreateLine | EntityLine | TextLine | DateLine, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)]

Qualifier

A union of the qualifier types

alias of Annotated[EntityQualifier | DateQualifier | TextQualifier, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)]

class TextLine(*, subject: ~typing.Annotated[str, _PydanticGeneralMetadata(pattern='^(LAST)|(Q\\d+)$')], predicate: ~typing.Annotated[str, _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: list[~typing.Annotated[~quickstatements_client.model.EntityQualifier | ~quickstatements_client.model.DateQualifier | ~quickstatements_client.model.TextQualifier, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] = <factory>, type: ~typing.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_config = {}

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

class TextQualifier(*, type: Literal['Text'] = 'Text', predicate: Annotated[str, _PydanticGeneralMetadata(pattern='^[PQS]\\d+$')], 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_config = {}

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

lines_to_new_tab(lines: Iterable[Annotated[CreateLine | EntityLine | TextLine | DateLine, FieldInfo(annotation=NoneType, required=True, discriminator='type')]]) 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())

lines_to_url(lines: Iterable[Annotated[CreateLine | EntityLine | TextLine | DateLine, FieldInfo(annotation=NoneType, required=True, discriminator='type')]]) str[source]

Prepare a URL for V1 of QuickStatements.

render_lines(lines: Iterable[Annotated[CreateLine | EntityLine | TextLine | DateLine, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], sep: str = '|', newline: str = '||') str[source]

Prepare QuickStatements line objects for sending to the API.

A client to the QuickStatements API.

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: 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_config = {}

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

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: Iterable[Annotated[CreateLine | EntityLine | TextLine | DateLine, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], batch_name: str | None = None, timeout: None | int | float | tuple[float | int, float | int] = None) Response[source]

Post a batch of QuickStatements with an optional name.

get_batch_info(batch_id: int, *, timeout: None | int | float | tuple[float | int, float | int] = None) BatchInfo[source]

Get information about a QuickStatements batch.

Parameters:
  • batch_id – The QuickStatements batch ID.

  • timeout – Number of seconds before timeout. Defaults to 10 seconds.

Returns:

An object containing information about the batch

For example, see https://quickstatements.toolforge.org/api.php?action=get_batch_info&batch=235284. Identifiers for recent batches can be found at https://quickstatements.toolforge.org/#/batches.

static open_new_tab(lines: Iterable[Annotated[CreateLine | EntityLine | TextLine | DateLine, FieldInfo(annotation=NoneType, required=True, discriminator='type')]]) bool[source]

Open a web browser on the host system.

class Response(*, status: str, batch_id: str | int | 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_config = {}

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

post_lines(lines: Iterable[Annotated[CreateLine | EntityLine | TextLine | DateLine, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, batch_name: str | None = None, timeout: None | int | float | tuple[float | int, float | int] = None) Response[source]

Post lines to the QuickStatements using the default client.

Parameters:
  • lines – The QuickStatement lines to post

  • batch_name – The name of the batch

  • timeout – The timeout in seconds (defaults to 300)

Returns:

The response from the QuickStatements API