Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

Substrate Python SDK

PyPI version

Substrate is a powerful SDK for building with AI, with batteries included: language models, image generation, built-in vector storage, sandboxed code execution, and more. To use Substrate, you simply connect tasks, and then run the workflow. With this simple approach, we can create AI systems (from RAG, to agents, to multi-modal generative experiences) by simply describing the computation, with zero additional abstractions.

Substrate is also a workflow execution and inference engine, optimized for running compound AI workloads. Wiring together multiple inference APIs is inherently slow – whether you do it yourself, or use a framework like LangChain. Substrate lets you ditch the framework, write less code, and run compound AI fast.

Documentation

If you're just getting started, head to docs.substrate.run.

For a detailed API reference covering the nodes available on Substrate, see substrate.run/nodes.

Installation

# install from PyPI
pip install substrate

Usage

from substrate import Substrate, ComputeText, sb

Initialize the Substrate client.

substrate = Substrate(api_key=SUBSTRATE_API_KEY)

Generate a story using the ComputeText node.

story = ComputeText(prompt="tell me a story")

Summarize the output of the story node using another ComputeText node. Because story has not yet been run, we use sb.concat to work with its future output.

summary = ComputeText(prompt=sb.concat("summarize this story in one sentence: ", story.future.text))

Run the graph chaining storysummary by passing the terminal node to substrate.run.

response = substrate.run(story, summary)

(To run the graph asynchronously, simply use async_run and await.)

response = await substrate.async_run(story, summary)

Get the output of the summary node by passing it to response.get.

summary_out = response.get(summary)
print(summary_out.text)
# Princess Lily, a kind-hearted young princess, discovers a book of spells and uses it to grant her family and kingdom happiness.

Examples

To run the above example as a notebook, navigate to the examples/notebooks directory and run:

make ensure                         # install dependencies
poetry run marimo edit basic.py     # run the notebook

Many more examples are included in the /examples directory.

Release files for substrate 220240617.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for substrate 220240617.1.8
File Size Uploaded
substrate-220240617.1.8.tar.gz 38.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for substrate 220240617.1.8
File Interpreter ABI Platform
substrate-220240617.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 82.6 kB

Release files / substrate-220240617.1.8.tar.gz

Download URL substrate-220240617.1.8.tar.gz
Size 38.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9a79ef9c4514287451dd9c0897d8ad4196ab84057e05abb6685d778b16cea356
BLAKE2b-256 checksum
How to use checksums
316ea42203ef79f98d79e69def5ebfc02bf4dd294c9a41ff685eae9fc09af642
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.13

Release files / substrate-220240617.1.8-py3-none-any.whl

Download URL substrate-220240617.1.8-py3-none-any.whl
Size 43.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a569cddecea801c844656d2bfc195b4295b805968a425b0b7037ed8f180dda9e
BLAKE2b-256 checksum
How to use checksums
4a17c3e2c77c0421309d6b12a93bf7c88f1badc335f22ad1457d800b8176301a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.13

Release history Release notifications | RSS feed

This release

220240617.1.8 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page