Skip to main content

A Python wrapper for the Wikifunctions function call API

Project description

Wikifunctions python library

This library allows you to interface with the Wikifunctions API in your Python code. Wikifunctions is a project of more than 3,800 community-created and community-maintained functions. You can find a list of these on the catalogue.

Installation

pip install wikifunctions

Usage examples

import wikifunctions as wf
result = wf.call("Z801", "echo")["Z22K1"]
print(result)

This code will print "echo", because Z801 is the echo function.

Building ZObjects

Wikifunctions requires strict JSON structures for its arguments. This library includes helper functions to make building these native types much easier in Python:

import wikifunctions as wf

result = wf.call("Z801", wf.ZNaturalNumber(4))["Z22K1"]
print(result["Z13518K1"])

This code will print "4." To see a full list of ZObject building functions and their parameters, see below.

Disclaimers

  • Community-Maintained: Wikifunctions is completely community-created and maintained. The author of this project does not control the underlying logic of functions. Users should check that the functions work as expected before using them, and be aware that anyone with functioneer rights on the Wiki may modify the underlying logic.
  • External Processing & Privacy: Using this package means sending content over to servers operated by the Wikimedia Foundation for execution. An internet connection is required to utilize the package, and the author of this project has no control over the reliability of WMF services. Users should not send sensitive data through the wrapper.

Functions

  • call(function: str, *args): uses the api to call the function with the specified arguments.
  • ZObject(type: str, **properties): creates an object with the specified type and properties. All of the other object builders rely on this function but add abstraction. Z1.
  • ZFunctionCall(function: str, *arguments): works similarly to call, but instead creates the relevant function call without sending it to the Wikifunctions API. This is useful for nesting calls. Z7.
  • ZReference(item: str): creates a reference to a specific item by its ZID. Z9.
  • ZMonolingualText(language: str, content: str): creates a monolingual text from the ZID of a natural language and string content. Z11.
  • ZBoolean(value: bool): creates a WF boolean from a Python boolean. Z40.
  • ZNaturalNumber(num: int): creates a natural number. Will take the absolute value if given a negative number. Z13518.
  • ZHTMLFragment(content: str): wraps a string in an HTML fragment. Z89.
  • ZSign(num: int): given a number, returns the sign of that number (e.g. negative for -1). Z16659.
  • ZInteger(num: int): converts a python int to a WF integer. Z16683.
  • Wikidata references (ZWikidataItemReference, ZWikidataPropertyReference, ZWikidataLexemeFormReference, ZWikidataLexemeReference, ZWikidataLexemeSenseReference): create the relevant reference type given a string representing their ID. Z6091-Z6096.
  • ZRationalNumber(numerator: int, denominator: int): creates a WF rational number from a numerator and denominator. Z19677.
  • ZKleenean(number: int): creates a Kleenean based on a number. 1 = True, 0 = Maybe, -1 = False. Z22112.

License

This project is licensed under the Apache License 2.0.

Source code and issues

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wikifunctions-0.2.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wikifunctions-0.2.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file wikifunctions-0.2.1.tar.gz.

File metadata

  • Download URL: wikifunctions-0.2.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for wikifunctions-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f00453d92895fb9c5a3f531e9f7d06dbbecdc28e36b155e553fd7b468407ab17
MD5 51c25853223808b7005d7f89f32d540c
BLAKE2b-256 4e419077cc71c7e79c471ce462011af4156f2bc8deb7fa8a0b3dc62a5393a2e9

See more details on using hashes here.

File details

Details for the file wikifunctions-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: wikifunctions-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for wikifunctions-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 990fe5bc6240213eaa71d017b2a7a09260888fec2b66478776ebb52f049a9894
MD5 92a3b0cfe8c72717ccce07fe6d64a1ac
BLAKE2b-256 024433ce1ada792fe45a99412e72bba2849613c4085524288d395c8ef18bf902

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page