Skip to main content

Generate pydantic models using prompts

Project description

Promptantic

An interactive CLI tool for populating Pydantic models using prompt-toolkit.

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 PyUp

Read the documentation!

Features

  • Interactive prompts for populating Pydantic models
  • Rich formatting and syntax highlighting
  • Type-aware input with validation
  • Autocompletion for paths, timezones, and custom values
  • Support for all common Python and Pydantic types
  • Nested model support
  • Union type handling via selection dialogs
  • Sequence input (lists, sets, tuples)
  • Customizable styling

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"[^@]+@[^@]+\.[^@]+")

# Create and use the generator
generator = ModelGenerator()
person = await generator.apopulate(Person)
print(person)

Supported Types

Basic Types

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

Complex Types

  • list, set, tuple (with nested type support)
  • Union types (with interactive type selection)
  • Nested Pydantic models

Special Types

  • Path (with path autocompletion)
  • UUID
  • SecretStr (masked input)
  • datetime, date, time, timedelta
  • ZoneInfo (with timezone autocompletion)
  • IPv4Address, IPv6Address, IPv4Network, IPv6Network
  • Email addresses (with validation)
  • URLs (with validation)

Advanced Usage

Custom Completions

from pydantic import BaseModel, Field
from pathlib import Path

class Config(BaseModel):
    environment: str = Field(
        description="Select environment",
        completions=["development", "staging", "production"]
    )
    config_path: Path = Field(description="Path to config file")  # Has path completion

Nested Models

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

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

# Will prompt for all fields recursively
person = await ModelGenerator().apopulate(Person)

Union Types

class Student(BaseModel):
    student_id: int

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

class Person(BaseModel):
    name: str
    role: Student | Teacher  # Will show selection dialog

# Will prompt for type selection before filling fields
person = await ModelGenerator().apopulate(Person)

Styling

from prompt_toolkit.styles import Style
from promptantic import ModelGenerator

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

generator = ModelGenerator(style=custom_style)

Options

generator = ModelGenerator(
    show_progress=True,        # Show field progress
    allow_back=True,          # Allow going back to previous fields
    retry_on_validation_error=True  # Retry on validation errors
)

Error Handling

from promptantic import ModelGenerator, PromptanticError

try:
    result = await ModelGenerator().apopulate(MyModel)
except KeyboardInterrupt:
    print("Operation cancelled by user")
except PromptanticError as e:
    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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

promptantic-0.6.1.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

promptantic-0.6.1-py3-none-any.whl (33.9 kB view details)

Uploaded Python 3

File details

Details for the file promptantic-0.6.1.tar.gz.

File metadata

  • Download URL: promptantic-0.6.1.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for promptantic-0.6.1.tar.gz
Algorithm Hash digest
SHA256 2d8bbcf5264523026337e80db9b744efa73f988e3bf8a0ecb6cef8efaecb9eb7
MD5 6e05ef8230c000774e066796cbcc00ce
BLAKE2b-256 3bf7306839b7508f5218f94c990ef86b4b8c1f47e8a343cc8bf712e70e732608

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptantic-0.6.1.tar.gz:

Publisher: build.yml on phil65/promptantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file promptantic-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: promptantic-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 33.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for promptantic-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 33d898fecf209a1103f7753f73a5c48064211d82517500fc578c75d02b64eb78
MD5 1ea292af401874cbbf770884c1b90e54
BLAKE2b-256 adc52005f036699aad983d8441a2b4d8f4e618bef3efb479731aa6b4c437d3a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptantic-0.6.1-py3-none-any.whl:

Publisher: build.yml on phil65/promptantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page