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.2

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.2
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)

Table of built distributions (wheels) for toprompt 1.0.2
File Interpreter ABI Platform Actions
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 log

Release 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 log

Security 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.

Select from 2 files

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 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