Substrate Python SDK
Project description
Substrate Python SDK
The Substrate Python SDK is the recommended way to interact with the Substrate API from any Python application.
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 story
→ summary
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for substrate-220240617.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93950da6c7dde6edefa8799f5ae03e287cc4c12743943051255ba448b86c4b8e |
|
MD5 | 1afc490f596de1c0079ccab926215e15 |
|
BLAKE2b-256 | 18e7117d7115bb1d0a13fca0dcdf2813696db2e4e561e592602b0f92cbdb2e60 |