ToPrompt
Convert Python objects into LLM-friendly text. toprompt provides one async function,
to_prompt(), that turns dataclasses, pydantic models, database schemas, CLI apps,
FastAPI apps and more into readable descriptions you can drop into a prompt.
Installation
pip install toprompt
Quickstart
import asyncio
from dataclasses import dataclass
from toprompt import Template, to_prompt
@dataclass
class User:
"""A registered user."""
name: str
age: int
class Weather:
def __prompt__(self) -> str:
return "Sunny, 23 degrees"
async def main() -> None:
print(await to_prompt(User("Alice", 30)))
# User:
# A registered user.
#
# - name = 'Alice' (<class 'str'>)
# - age = 30 (<class 'int'>)
print(await to_prompt({"user": User("Bob", 25), "weather": Weather()}))
# Jinja2 templating is opt-in
template = Template("Hello {{ agent.name }}!")
print(await to_prompt(template, template_mode="explicit", name="Bot")) # Hello Bot!
asyncio.run(main())
Supported objects
- Strings (returned as-is) and
Templatestrings rendered with Jinja2 (template_mode="explicit", or"all"to template every string) - Custom objects implementing
__prompt__()or a__prompt_type__()classmethod (sync or async), see thePromptConvertible/PromptTypeConvertibleprotocols - Structured objects via fieldz: dataclasses, pydantic models, attrs classes, msgspec structs, ...
- SQLModel table classes and instances (table schema plus current values)
- SQLite connections (
sqlite3.Connection): tables, columns, keys and indexes - CLI apps:
argparse.ArgumentParser, click commands/groups, typer apps, cleo and cappa (via clinspector) - FastAPI apps: endpoints, parameters, request and response schemas
- llmling
BasePromptobjects datetime(ISO format) and compiled regex patterns- Containers (
dict,list,tuple), converted recursively - Callables and coroutines: called/awaited, and the result is converted
Framework integrations are optional: toprompt only uses them if they are installed.
Metadata
Release files for toprompt 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| toprompt-1.0.2.tar.gz | 15.3 kB | With provenance | Details for toprompt-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| toprompt-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for toprompt-1.0.2-py3-none-any.whl |
Total release size: 29.9 kB
Release files / toprompt-1.0.2.tar.gz
| Download URL | toprompt-1.0.2.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f7916c4ab8363084e002a39c0a980a5d6767479a62e8f5754034408552fea3b
|
|
BLAKE2b-256 checksum How to use checksums |
bee28b33f20b52a46585214999d9a4d1c24993bf6c9980deeac402fb4e7475b4
|
| 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 Nov 26, 2026.
Transparency logRelease files / toprompt-1.0.2-py3-none-any.whl
| Download URL | toprompt-1.0.2-py3-none-any.whl |
|---|---|
| Size | 14.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d2c86ba17c4e92a7fd22ee56db95c50ea23175c315e40f628a136e42d212c03d
|
|
BLAKE2b-256 checksum How to use checksums |
ba45f63869f41930e1ffc3ccee3870c2e2a5e2147e1c85914d0f5d2aed936b60
|
| 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 Nov 26, 2026.
Transparency logSecurity for toprompt 1.0.2
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.
Attestation for toprompt-1.0.2.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 Nov 26, 2026.
Transparency logA 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.