Skip to main content

Promptantic

Fill Pydantic models interactively in the terminal. promptantic walks a model's fields and shows a type-aware prompt-toolkit prompt for each one, with completion, validation and retry.

PyPI License Package status Monthly downloads Distribution format Wheel availability Python version Implementation Releases Github Contributors Github Discussions 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

Read the documentation!

Features

  • One prompt per field, driven by the field's type, description and default
  • Validation with retry on invalid input
  • Autocompletion for paths, timezones, import strings and custom value lists
  • Nested models, sequences and mappings
  • Union types via a selection dialog
  • Fields can be skipped (skip_prompt) and use their default
  • Extensible: register your own handler for any type
  • Customizable styling
  • ModelCreator: define a new model class interactively

Installation

pip install promptantic

Quick Start

from pydantic import BaseModel, Field

from promptantic import ModelGenerator


class Person(BaseModel):
    name: str = Field(description="Person's full name")
    age: int = Field(description="Age in years", gt=0)
    email: str = Field(description="Email address", pattern=r"[^@]+@[^@]+\.[^@]+")


generator = ModelGenerator()
person = generator.populate(Person)  # or: await generator.apopulate(Person)
print(person)

populate / apopulate accept a model class or an instance; values that were explicitly set on an instance are offered as defaults.

Supported Types

Basic Types

  • str, int, float, bool, decimal.Decimal, fractions.Fraction, None
  • Constrained types (e.g., constr, conint)
  • Enum classes
  • Literal types

Complex Types

  • list, set, tuple, dict (with nested type support)
  • collections.Counter, deque, defaultdict
  • Union types (with interactive type selection)
  • Nested Pydantic models

Special Types

  • pathlib.Path (with path autocompletion)
  • UUID
  • SecretStr (masked input)
  • datetime, date, time, timedelta
  • ZoneInfo (with timezone autocompletion)
  • IPv4Address, IPv6Address, IPv4Network, IPv6Network
  • re.Pattern
  • pydantic.ImportString and types.ModuleType (with import path autocompletion)

Advanced Usage

Field options

Per-field behaviour is configured via json_schema_extra:

from pathlib import Path

from pydantic import BaseModel, Field

from promptantic import SKIP_PROMPT_KEY


class Config(BaseModel):
    environment: str = Field(
        description="Select environment",
        json_schema_extra={"completions": ["development", "staging", "production"]},
    )
    config_path: Path = Field(
        description="Path to config file",
        json_schema_extra={"must_exist": True, "file_only": True},
    )
    internal_id: str = Field(default="auto", json_schema_extra={SKIP_PROMPT_KEY: True})
  • completions: completion values for str fields
  • must_exist, file_only, dir_only: path validation
  • skip_prompt (SKIP_PROMPT_KEY): don't prompt, use the default / default factory

Nested Models

from pydantic import BaseModel, Field

from promptantic import ModelGenerator


class Address(BaseModel):
    street: str = Field(description="Street name")
    city: str = Field(description="City name")


class Person(BaseModel):
    name: str = Field(description="Full name")
    address: Address = Field(description="Person's address")


# Prompts for all fields recursively
person = ModelGenerator().populate(Person)

Union Types

from pydantic import BaseModel

from promptantic import ModelGenerator


class Student(BaseModel):
    student_id: int


class Teacher(BaseModel):
    teacher_id: str
    subject: str


class Person(BaseModel):
    name: str
    role: Student | Teacher  # Shows a selection dialog


person = ModelGenerator().populate(Person)

Styling and options

from prompt_toolkit.styles import Style

from promptantic import ModelGenerator


custom_style = Style.from_dict({
    "field-name": "bold #00aa00",
    "field-description": "italic #888888",
    "default-value": "#666666",
    "error": "bold #ff0000",
})

generator = ModelGenerator(
    style=custom_style,  # merged with the default style
    show_progress=True,  # print "Field i/n" before each field
    retry_on_validation_error=True,  # ask again instead of raising
)

Custom type handlers

from typing import Any

from prompt_toolkit import PromptSession

from promptantic import ModelGenerator
from promptantic.handlers.base import BaseHandler


class Point:
    def __init__(self, x: float, y: float) -> None:
        self.x, self.y = x, y


class PointHandler(BaseHandler[Point]):
    async def handle(
        self,
        field_name: str,
        field_type: type[Point],
        description: str | None = None,
        default: Any = None,
        **options: Any,
    ) -> Point:
        text = await PromptSession().prompt_async(f"{field_name} (x,y): ")
        x, y = text.split(",")
        return Point(float(x), float(y))


generator = ModelGenerator()
generator.register_handler(Point, PointHandler(generator))

Creating models interactively

import asyncio

from promptantic import ModelCreator


# Prompts for a model name, then fields (name, type, metadata) until Ctrl-D
model_cls = asyncio.run(ModelCreator().acreate())
instance = asyncio.run(ModelCreator().acreate_instance())  # create and populate

Error Handling

from promptantic import ModelGenerator, PromptanticError

try:
    result = ModelGenerator().populate(MyModel)
except KeyboardInterrupt:
    print("Operation cancelled by user")
except PromptanticError as e:  # e.g. NoHandlerError for unsupported field types
    print(f"Error: {e}")

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Credits

Built with prompt-toolkit and Pydantic.

Metadata

Release files for promptantic 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 promptantic 1.0.1
File Size Uploaded Provenance Actions
promptantic-1.0.1.tar.gz 30.9 kB With provenance Details for promptantic-1.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 67.0 kB

Release files / promptantic-1.0.1.tar.gz

Download URL promptantic-1.0.1.tar.gz
Size 30.9 kB
Tags Source
SHA-256 checksum
How to use checksums
97c17e7af9770bd25910bcb5aea91916f355f44115d071a17d4fc33f1eab4a41
BLAKE2b-256 checksum
How to use checksums
2067539c5873150e68f3916569a4b9c1ef14bf1f170a30d29680a64f1e1c4915
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 / promptantic-1.0.1-py3-none-any.whl

Download URL promptantic-1.0.1-py3-none-any.whl
Size 36.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b4a3e1297090656cd02529a5ff3c299115a19c28b103758acc4b082d45dbfb2
BLAKE2b-256 checksum
How to use checksums
89fef8c7698ce2f111dfd7255b957c1562279308cecb5f93df4560533fbdf73f
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 promptantic 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 promptantic-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