promptantic


Namepromptantic JSON
Version 0.6.0 PyPI version JSON
download
home_pageNone
SummaryGenerate pydantic models using prompts
upload_time2025-10-06 20:31:38
maintainerNone
docs_urlNone
authorPhilipp Temminghoff
requires_python>=3.12
licenseMIT License Copyright (c) 2024, Philipp Temminghoff Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Promptantic

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

[![PyPI License](https://img.shields.io/pypi/l/promptantic.svg)](https://pypi.org/project/promptantic/)
[![Package status](https://img.shields.io/pypi/status/promptantic.svg)](https://pypi.org/project/promptantic/)
[![Monthly downloads](https://img.shields.io/pypi/dm/promptantic.svg)](https://pypi.org/project/promptantic/)
[![Distribution format](https://img.shields.io/pypi/format/promptantic.svg)](https://pypi.org/project/promptantic/)
[![Wheel availability](https://img.shields.io/pypi/wheel/promptantic.svg)](https://pypi.org/project/promptantic/)
[![Python version](https://img.shields.io/pypi/pyversions/promptantic.svg)](https://pypi.org/project/promptantic/)
[![Implementation](https://img.shields.io/pypi/implementation/promptantic.svg)](https://pypi.org/project/promptantic/)
[![Releases](https://img.shields.io/github/downloads/phil65/promptantic/total.svg)](https://github.com/phil65/promptantic/releases)
[![Github Contributors](https://img.shields.io/github/contributors/phil65/promptantic)](https://github.com/phil65/promptantic/graphs/contributors)
[![Github Discussions](https://img.shields.io/github/discussions/phil65/promptantic)](https://github.com/phil65/promptantic/discussions)
[![Github Forks](https://img.shields.io/github/forks/phil65/promptantic)](https://github.com/phil65/promptantic/forks)
[![Github Issues](https://img.shields.io/github/issues/phil65/promptantic)](https://github.com/phil65/promptantic/issues)
[![Github Issues](https://img.shields.io/github/issues-pr/phil65/promptantic)](https://github.com/phil65/promptantic/pulls)
[![Github Watchers](https://img.shields.io/github/watchers/phil65/promptantic)](https://github.com/phil65/promptantic/watchers)
[![Github Stars](https://img.shields.io/github/stars/phil65/promptantic)](https://github.com/phil65/promptantic/stars)
[![Github Repository size](https://img.shields.io/github/repo-size/phil65/promptantic)](https://github.com/phil65/promptantic)
[![Github last commit](https://img.shields.io/github/last-commit/phil65/promptantic)](https://github.com/phil65/promptantic/commits)
[![Github release date](https://img.shields.io/github/release-date/phil65/promptantic)](https://github.com/phil65/promptantic/releases)
[![Github language count](https://img.shields.io/github/languages/count/phil65/promptantic)](https://github.com/phil65/promptantic)
[![Github commits this month](https://img.shields.io/github/commit-activity/m/phil65/promptantic)](https://github.com/phil65/promptantic)
[![Package status](https://codecov.io/gh/phil65/promptantic/branch/main/graph/badge.svg)](https://codecov.io/gh/phil65/promptantic/)
[![PyUp](https://pyup.io/repos/github/phil65/promptantic/shield.svg)](https://pyup.io/repos/github/phil65/promptantic/)

[Read the documentation!](https://phil65.github.io/promptantic/)


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

```bash
pip install promptantic
```

## Quick Start

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

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

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

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

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

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

```python
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](https://github.com/prompt-toolkit/python-prompt-toolkit) and [Pydantic](https://github.com/pydantic/pydantic).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "promptantic",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": null,
    "author": "Philipp Temminghoff",
    "author_email": "Philipp Temminghoff <philipptemminghoff@googlemail.com>",
    "download_url": "https://files.pythonhosted.org/packages/30/4d/09d8c83f3600c13835844123204260450597cd6381ec835f0e1d2cedd34d/promptantic-0.6.0.tar.gz",
    "platform": null,
    "description": "# Promptantic\n\nAn interactive CLI tool for populating Pydantic models using prompt-toolkit.\n\n[![PyPI License](https://img.shields.io/pypi/l/promptantic.svg)](https://pypi.org/project/promptantic/)\n[![Package status](https://img.shields.io/pypi/status/promptantic.svg)](https://pypi.org/project/promptantic/)\n[![Monthly downloads](https://img.shields.io/pypi/dm/promptantic.svg)](https://pypi.org/project/promptantic/)\n[![Distribution format](https://img.shields.io/pypi/format/promptantic.svg)](https://pypi.org/project/promptantic/)\n[![Wheel availability](https://img.shields.io/pypi/wheel/promptantic.svg)](https://pypi.org/project/promptantic/)\n[![Python version](https://img.shields.io/pypi/pyversions/promptantic.svg)](https://pypi.org/project/promptantic/)\n[![Implementation](https://img.shields.io/pypi/implementation/promptantic.svg)](https://pypi.org/project/promptantic/)\n[![Releases](https://img.shields.io/github/downloads/phil65/promptantic/total.svg)](https://github.com/phil65/promptantic/releases)\n[![Github Contributors](https://img.shields.io/github/contributors/phil65/promptantic)](https://github.com/phil65/promptantic/graphs/contributors)\n[![Github Discussions](https://img.shields.io/github/discussions/phil65/promptantic)](https://github.com/phil65/promptantic/discussions)\n[![Github Forks](https://img.shields.io/github/forks/phil65/promptantic)](https://github.com/phil65/promptantic/forks)\n[![Github Issues](https://img.shields.io/github/issues/phil65/promptantic)](https://github.com/phil65/promptantic/issues)\n[![Github Issues](https://img.shields.io/github/issues-pr/phil65/promptantic)](https://github.com/phil65/promptantic/pulls)\n[![Github Watchers](https://img.shields.io/github/watchers/phil65/promptantic)](https://github.com/phil65/promptantic/watchers)\n[![Github Stars](https://img.shields.io/github/stars/phil65/promptantic)](https://github.com/phil65/promptantic/stars)\n[![Github Repository size](https://img.shields.io/github/repo-size/phil65/promptantic)](https://github.com/phil65/promptantic)\n[![Github last commit](https://img.shields.io/github/last-commit/phil65/promptantic)](https://github.com/phil65/promptantic/commits)\n[![Github release date](https://img.shields.io/github/release-date/phil65/promptantic)](https://github.com/phil65/promptantic/releases)\n[![Github language count](https://img.shields.io/github/languages/count/phil65/promptantic)](https://github.com/phil65/promptantic)\n[![Github commits this month](https://img.shields.io/github/commit-activity/m/phil65/promptantic)](https://github.com/phil65/promptantic)\n[![Package status](https://codecov.io/gh/phil65/promptantic/branch/main/graph/badge.svg)](https://codecov.io/gh/phil65/promptantic/)\n[![PyUp](https://pyup.io/repos/github/phil65/promptantic/shield.svg)](https://pyup.io/repos/github/phil65/promptantic/)\n\n[Read the documentation!](https://phil65.github.io/promptantic/)\n\n\n## Features\n\n- Interactive prompts for populating Pydantic models\n- Rich formatting and syntax highlighting\n- Type-aware input with validation\n- Autocompletion for paths, timezones, and custom values\n- Support for all common Python and Pydantic types\n- Nested model support\n- Union type handling via selection dialogs\n- Sequence input (lists, sets, tuples)\n- Customizable styling\n\n## Installation\n\n```bash\npip install promptantic\n```\n\n## Quick Start\n\n```python\nfrom pydantic import BaseModel, Field\nfrom promptantic import ModelGenerator\n\nclass Person(BaseModel):\n    name: str = Field(description=\"Person's full name\")\n    age: int = Field(description=\"Age in years\", gt=0)\n    email: str = Field(description=\"Email address\", pattern=r\"[^@]+@[^@]+\\.[^@]+\")\n\n# Create and use the generator\ngenerator = ModelGenerator()\nperson = await generator.apopulate(Person)\nprint(person)\n```\n\n## Supported Types\n\n### Basic Types\n- `str`, `int`, `float`, `bool`, `decimal.Decimal`\n- Constrained types (e.g., `constr`, `conint`)\n- `Enum` classes\n- `Literal` types\n\n### Complex Types\n- `list`, `set`, `tuple` (with nested type support)\n- `Union` types (with interactive type selection)\n- Nested Pydantic models\n\n### Special Types\n- `Path` (with path autocompletion)\n- `UUID`\n- `SecretStr` (masked input)\n- `datetime`, `date`, `time`, `timedelta`\n- `ZoneInfo` (with timezone autocompletion)\n- `IPv4Address`, `IPv6Address`, `IPv4Network`, `IPv6Network`\n- Email addresses (with validation)\n- URLs (with validation)\n\n## Advanced Usage\n\n### Custom Completions\n\n```python\nfrom pydantic import BaseModel, Field\nfrom pathlib import Path\n\nclass Config(BaseModel):\n    environment: str = Field(\n        description=\"Select environment\",\n        completions=[\"development\", \"staging\", \"production\"]\n    )\n    config_path: Path = Field(description=\"Path to config file\")  # Has path completion\n```\n\n### Nested Models\n\n```python\nclass Address(BaseModel):\n    street: str = Field(description=\"Street name\")\n    city: str = Field(description=\"City name\")\n    country: str = Field(description=\"Country name\")\n\nclass Person(BaseModel):\n    name: str = Field(description=\"Full name\")\n    address: Address = Field(description=\"Person's address\")\n\n# Will prompt for all fields recursively\nperson = await ModelGenerator().apopulate(Person)\n```\n\n### Union Types\n\n```python\nclass Student(BaseModel):\n    student_id: int\n\nclass Teacher(BaseModel):\n    teacher_id: str\n    subject: str\n\nclass Person(BaseModel):\n    name: str\n    role: Student | Teacher  # Will show selection dialog\n\n# Will prompt for type selection before filling fields\nperson = await ModelGenerator().apopulate(Person)\n```\n\n### Styling\n\n```python\nfrom prompt_toolkit.styles import Style\nfrom promptantic import ModelGenerator\n\ncustom_style = Style.from_dict({\n    \"field-name\": \"bold #00aa00\",  # Green bold\n    \"field-description\": \"italic #888888\",  # Gray italic\n    \"error\": \"bold #ff0000\",  # Red bold\n})\n\ngenerator = ModelGenerator(style=custom_style)\n```\n\n### Options\n\n```python\ngenerator = ModelGenerator(\n    show_progress=True,        # Show field progress\n    allow_back=True,          # Allow going back to previous fields\n    retry_on_validation_error=True  # Retry on validation errors\n)\n```\n\n## Error Handling\n\n```python\nfrom promptantic import ModelGenerator, PromptanticError\n\ntry:\n    result = await ModelGenerator().apopulate(MyModel)\nexcept KeyboardInterrupt:\n    print(\"Operation cancelled by user\")\nexcept PromptanticError as e:\n    print(f\"Error: {e}\")\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## Credits\n\nBuilt with [prompt-toolkit](https://github.com/prompt-toolkit/python-prompt-toolkit) and [Pydantic](https://github.com/pydantic/pydantic).\n",
    "bugtrack_url": null,
    "license": "MIT License\n         \n         Copyright (c) 2024, Philipp Temminghoff\n         \n         Permission is hereby granted, free of charge, to any person obtaining a copy\n         of this software and associated documentation files (the \"Software\"), to deal\n         in the Software without restriction, including without limitation the rights\n         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n         copies of the Software, and to permit persons to whom the Software is\n         furnished to do so, subject to the following conditions:\n         \n         The above copyright notice and this permission notice shall be included in all\n         copies or substantial portions of the Software.\n         \n         THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n         SOFTWARE.\n         ",
    "summary": "Generate pydantic models using prompts",
    "version": "0.6.0",
    "project_urls": {
        "Code coverage": "https://app.codecov.io/gh/phil65/promptantic",
        "Discussions": "https://github.com/phil65/promptantic/discussions",
        "Documentation": "https://phil65.github.io/promptantic/",
        "Issues": "https://github.com/phil65/promptantic/issues",
        "Source": "https://github.com/phil65/promptantic"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5bb96a74d842b589ffd0f80077d4a6fad7628a9c2509ddedc834ee608444ad84",
                "md5": "a427f74c1843054227a67ec882328ac2",
                "sha256": "884931fb1ac0aa43afeddfd0a970883d5734ffa2fad0180f115b85978f5b536a"
            },
            "downloads": -1,
            "filename": "promptantic-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a427f74c1843054227a67ec882328ac2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 33945,
            "upload_time": "2025-10-06T20:31:36",
            "upload_time_iso_8601": "2025-10-06T20:31:36.945616Z",
            "url": "https://files.pythonhosted.org/packages/5b/b9/6a74d842b589ffd0f80077d4a6fad7628a9c2509ddedc834ee608444ad84/promptantic-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "304d09d8c83f3600c13835844123204260450597cd6381ec835f0e1d2cedd34d",
                "md5": "204923a4a9433a1ba7fd57cac4414f7b",
                "sha256": "aa19c0ab56a97b3a11bc80ed6250216cb6a0c79122cbd75716c9558c2100fb6b"
            },
            "downloads": -1,
            "filename": "promptantic-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "204923a4a9433a1ba7fd57cac4414f7b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 24742,
            "upload_time": "2025-10-06T20:31:38",
            "upload_time_iso_8601": "2025-10-06T20:31:38.498265Z",
            "url": "https://files.pythonhosted.org/packages/30/4d/09d8c83f3600c13835844123204260450597cd6381ec835f0e1d2cedd34d/promptantic-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-06 20:31:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "phil65",
    "github_project": "promptantic",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "promptantic"
}
        
Elapsed time: 1.68297s