Wolfram|Alpha API Client

5.1.3 · active · verified Thu Apr 16

The `wolframalpha` library is a Python client for the Wolfram|Alpha 2.0 API, enabling Python programs to submit natural language queries to the Wolfram|Alpha computational knowledge engine and retrieve structured results. As of April 2026, the current version is 5.1.3, and the project maintains an active release cadence with regular minor and patch updates.

Common errors

Warnings

Install

Imports

Quickstart

To get started, you need an App ID from the Wolfram|Alpha Developer Portal. This ID is used to authenticate your requests. The example demonstrates how to initialize the client, send a basic query, and extract the text result. It also shows how to retrieve an image URL if the result includes one. It's recommended to store your App ID in an environment variable for security.

import wolframalpha
import os

# Get your App ID from the Wolfram|Alpha Developer Portal
# (developer.wolframalpha.com/portal/myapps)
APP_ID = os.environ.get('WOLFRAM_ALPHA_APPID', 'YOUR_WOLFRAM_ALPHA_APP_ID')

if APP_ID == 'YOUR_WOLFRAM_ALPHA_APP_ID' or not APP_ID:
    print("Error: WOLFRAM_ALPHA_APPID environment variable not set or placeholder used.")
    print("Please obtain an App ID from developer.wolframalpha.com/portal/myapps and set it.")
else:
    try:
        client = wolframalpha.Client(APP_ID)
        # Send a query
        res = client.query('What is the capital of France?')

        # Print the plaintext result from the first pod
        # The API returns results in 'pods', often with multiple subpods
        # Iterating `res.results` is a common way to get answers.
        print(f"Wolfram|Alpha says: {next(res.results).text}")

        # Example of getting an image result (if available in a pod)
        res_img = client.query('Plot sin(x)')
        for pod in res_img.pods:
            for sub in pod.subpods:
                if sub.img:
                    print(f"Image URL for '{pod.title}': {sub.img.src}")

    except Exception as e:
        print(f"An error occurred: {e}")
        print("Ensure your App ID is correct and you haven't exceeded query limits.")

view raw JSON →