Skip to main content

The Smarter Python SDK

A project of The Smarter Project Release codecov Latest Release PyPI Python License: AGPL v3 Docs

smarter-api is the official Python SDK of the Smarter platform. It is to Smarter what the openai package is to the OpenAI api: one pip install gives your Python software typed, complete access to your own Smarter installation, whether it runs on your laptop or on Kubernetes.

Use it to build custom software that is tightly integrated with your Smarter resources and functionality, without customizing or forking the Smarter backend: a web application that chats with your LLMClients, a CI job that applies your manifests, a data pipeline that loads documents into a vectorstore, or a service that calls your MCP servers' tools.

from smarter import Smarter

client = Smarter()  # SMARTER_API_KEY, or the smarter cli's ~/.smarter/config.yaml

llmclient = client.llm_clients.find("customer_support")
response = client.llm_clients.prompt(llmclient.id, "Where is my order #1234?")
print(response.text)

Documentation: https://docs.smarter-python.smarter.sh/

smarter-python is part of The Smarter Project.

Smarter Python SDK or Smarter CLI?

Both manage the same resources through the same api. The difference is how you use them:

smarter-python (this package) smarter-cli
A Python library that you import into your own software. A program that you install on your computer.
client.manifests.apply("guardrail.yaml") smarter apply -f guardrail.yaml
Returns typed Pydantic models, and raises typed exceptions. Prints JSON or YAML in a terminal window.
For applications, services, notebooks, tests and automation. For people at a keyboard, and shell scripts.

The SDK reads the cli's configuration file, so if you have run smarter configure, the SDK needs no other setup.

At a Glance

  • Every resource kind, through the same manifest api as the cli: apply, validate, get, describe, delete, deploy, undeploy and logs, for LLMClients, Plugins, Guardrails, MCPClients, Vectorstores, LLMHosts, Secrets, Custom Domains, Accounts, Users, and every other kind.
  • Prompts and conversations: prompt an LLMClient, hold a multi-turn chat that keeps its session, and stream a prompt's progress (its LLM requests, tool calls and MCP calls) as it runs.
  • Resource actions: evaluate a Guardrail, call an MCP server's tools, add documents to and search a vectorstore, plan and deploy an LLMHost, discover open-weight models, and call an LLM provider through a Proxy.
  • The platform's own Pydantic models: a typed model of every SAM manifest kind (e.g. SAMLLMClient), the Smarter Chat api contract (e.g. PromptChatApiConfig), the Smarter Journal contract, and the Django-React integration contract, kept in step with the platform by tests.
  • Production behavior: retries with backoff, timeouts, typed exceptions, logging that never prints your api key, and a py.typed package for your type checker.

Quickstart

pip install smarter-api

Point the SDK at your platform with environment variables, or pass them as arguments to Smarter(...):

export SMARTER_API_KEY="your 64-character Smarter api key"
export SMARTER_BASE_URL="https://platform.example.com"   # or http://localhost:9357

Manifests

from smarter import Smarter

client = Smarter()

client.manifests.apply("pii-redactor.yaml")                    # create or update
manifest = client.guardrails.describe("pii_redactor")          # read it back
guardrail = manifest.to_sam()                                  # as a typed SAMGuardrail
print(guardrail.spec.config.action)
client.guardrails.delete("pii_redactor")

Chat

chat = client.llm_clients.chat(llmclient.id)
print(chat.send("What is 2 to the 10th power?").text)
print(chat.send("And divided by 4?").text)

with chat.stream("Now take its square root.") as stream:
    for event in stream:
        print("...", event.message)     # e.g. "Calling tool calculator"
    print(stream.response.text)

client.llm_clients.config(llmclient.id) returns the chat configuration that a session starts with. It has what a chat needs, and only the counts of the LLMClient's plugins and extensions. Pass verbose=True for the complete configuration, with their lists and the session's tool calls.

Errors

from smarter import NotFoundError, SmarterError

try:
    client.manifests.describe("LLMClient", "no_such_client")
except NotFoundError as e:
    print(e.status_code, e.message, e.error_class)
except SmarterError as e:
    print("something else went wrong:", e)

Documentation

The SDK's documentation is at https://docs.smarter-python.smarter.sh/: the user guide, the api reference generated from its docstrings, and its architecture decision records. The platform's own documentation is at docs.smarter.sh.

Requirements

Python 3.10 or later, and a Smarter platform to connect to. See the Quick Start Guide to run one on your laptop.

Development

make                # list every command
make init           # create venv/ from requirements/local.txt, install the package and the git hooks
make test           # the unit tests, which never reach a platform
make coverage       # the unit tests, with a coverage report
SMARTER_BASE_URL=http://localhost:9357 SMARTER_API_KEY=... make test-live
make lint           # run the pre-commit hooks on every file
make sphinx-build   # build the Sphinx docs into docs/build/html
make sphinx-publish # publish them to docs.smarter-python.smarter.sh
make build          # build the sdist and wheel, and check them
make python-requirements  # recompile the pinned requirements/*.txt

CI runs the hooks, the unit tests on every supported Python version, the docs build and a package build, on every pull request, and on every push to main, alpha and beta as the first step of the Release workflow. Coverage is reported to Codecov. When CI passes, the Release workflow releases with semantic-release, from the conventional commit messages, and publishes to PyPI from main (or to TestPyPI from alpha and beta). make release-dry-run shows the next version.

The agent skills in skills/ describe how this repository is developed, tested and documented, for people and for AI coding agents.

Support

Please report bugs to the GitHub Issues Page for this project.

Contributing

Please see the CONTRIBUTING.

Metadata

Release files for smarter-api 0.5.4

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

Source distribution (sdist)

Source distribution for smarter-api 0.5.4
File Size Uploaded Provenance Actions
smarter_api-0.5.4.tar.gz 287.3 kB With provenance Details for smarter_api-0.5.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for smarter-api 0.5.4
File Interpreter ABI Platform Actions
smarter_api-0.5.4-py3-none-any.whl Python 3 none any Details for smarter_api-0.5.4-py3-none-any.whl

Total release size: 447.4 kB

Release files / smarter_api-0.5.4.tar.gz

Download URL smarter_api-0.5.4.tar.gz
Size 287.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fe0b77c4c16bca549b42efdd731dd8c0e9c06c09c53fefaea3d078780e5befc6
BLAKE2b-256 checksum
How to use checksums
68ed83bb4673bb75c94df3e0bd1d9d16b8685a6ea78467b845c5315ec8e7d9d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / smarter_api-0.5.4-py3-none-any.whl

Download URL smarter_api-0.5.4-py3-none-any.whl
Size 160.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6003961e32422602d3fab3d16cf6bfbe535c02def53ecd0e269d1f74e1519d22
BLAKE2b-256 checksum
How to use checksums
657d48b0f3ed71a919e97d8e04a30c46ad344cb3db8ae11bb20c7b64884daa97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Security for smarter-api 0.5.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for smarter_api-0.5.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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