Skip to main content

ToPrompt

PyPI License Package status Monthly downloads Distribution format Wheel availability Python version Implementation Releases Github Contributors Github Forks Github Issues Github Issues Github Watchers Github Stars Github Repository size Github last commit Github release date Github language count Github commits this month Package status PyUp

Read the documentation!

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 Template strings 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 the PromptConvertible / PromptTypeConvertible protocols
  • 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 BasePrompt objects
  • 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.1

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

Source distribution (sdist)

Source distribution for toprompt 1.0.1
File Size Uploaded Provenance Actions
toprompt-1.0.1.tar.gz 14.7 kB With provenance Details for toprompt-1.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 28.9 kB

Release files / toprompt-1.0.1.tar.gz

Download URL toprompt-1.0.1.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fec06a4a3e609b17dec97c01ceaa3977ba15d727aad8c4959d7da2afaba77cab
BLAKE2b-256 checksum
How to use checksums
2a080a05e3bba034c29bbcaa7bc17120d419ec432ebec0b4ac27832d980866e9
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 22, 2026.

Transparency log

Release files / toprompt-1.0.1-py3-none-any.whl

Download URL toprompt-1.0.1-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e19b3a4722886f3d4359efa7ee1b8d03ce24b6d1baeae1e1f5b45ba4c0891c6f
BLAKE2b-256 checksum
How to use checksums
38ac6eb0cb1283a7319a4dfaa32c1de85b6439062ee0afdc588006627362c993
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 22, 2026.

Transparency log

Security for toprompt 1.0.1

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 toprompt-1.0.1.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 22, 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