Welcome to wolframalpha documentation!

class wolframalpha.Assumption

Bases: wolframalpha.Document

property text
class wolframalpha.Client(app_id)

Bases: object

Wolfram|Alpha v2.0 client

Basic usage is pretty simple. Get your App ID at https://products.wolframalpha.com/api/. Create the client with your App ID:

>>> app_id = getfixture('API_key')
>>> client = Client(app_id)

Send a query, which returns Results objects:

>>> res = client.query('temperature in Washington, DC on October 3, 2012')

Result objects have pods (a Pod is an answer group from Wolfram Alpha):

>>> for pod in res.pods:
...     pass  # do_something_with(pod)

Pod objects have subpods (a Subpod is a specific response with the plaintext reply and some additional info):

>>> for pod in res.pods:
...     for sub in pod.subpods:
...         print(sub.plaintext)
temperature | Washington, District of Columbia
Wednesday, October 3, 2012
(70 to 81) °F (average: 75 °F)
...

To query simply for the pods that have ‘Result’ titles or are marked as ‘primary’ using Result.results:

>>> print(next(res.results).text)
(70 to 81) °F (average: 75 °F)
(Wednesday, October 3, 2012)

All objects returned are dictionary subclasses, so to find out which attributes Wolfram|Alpha has supplied, simply invoke .keys() on the object. Attributes formed from XML attributes can be accessed with or without their “@” prefix (added by xmltodict).

classmethod from_env()

Create a client with a key discovered from the keyring or environment variable. Raises an exception if no key is found.

query(input, params=(), **kwargs)

Query Wolfram|Alpha using the v2.0 API

Allows for arbitrary parameters to be passed in the query. For example, to pass assumptions:

>>> client = Client(getfixture('API_key'))
>>> res = client.query(input='pi', assumption='*C.pi-_*NamedConstant-')

To pass multiple assumptions, pass multiple items as params:

>>> params = (
...     ('assumption', '*C.pi-_*NamedConstant-'),
...     ('assumption', 'DateOrder_**Day.Month.Year--'),
... )
>>> res = client.query(input='pi', params=params)

For more details on Assumptions, see https://products.wolframalpha.com/api/documentation.html#6

class wolframalpha.Document

Bases: dict

children: Tuple[str, ] = ()
classmethod make(path, key, value)
class wolframalpha.ErrorHandler(*args, **kwargs)

Bases: object

class wolframalpha.Image

Bases: wolframalpha.Document

Holds information about an image included with an answer.

key = 'img'
class wolframalpha.Pod(*args, **kwargs)

Bases: wolframalpha.ErrorHandler, wolframalpha.Document

Groups answers and information contextualizing those answers.

children: Tuple[str, ] = ('subpods',)
property primary
property text
property texts

The text from each subpod in this pod as a list.

class wolframalpha.Result(*args, **kwargs)

Bases: wolframalpha.ErrorHandler, wolframalpha.Document

Handles processing the response for the programmer.

children: Tuple[str, ] = ('pods', 'assumptions', 'warnings')
property details

A simplified set of answer text by title.

property info

The pods, assumptions, and warnings of this result.

key = 'queryresult'
property results

The pods that hold the response to a simple, discrete query.

class wolframalpha.Subpod

Bases: wolframalpha.Document

Holds a specific answer or additional information relevant to said answer.

class wolframalpha.Warning

Bases: wolframalpha.Document

wolframalpha.identity(x)
wolframalpha.xml_bool(str_val)
>>> xml_bool('true')
True
>>> xml_bool('false')
False

Indices and tables