promptantic
Class info¶
Re-exported classes¶
| Class | Module | Description |
|---|---|---|
| FieldSpec | promptantic.model_spec | One field of a model being designed. |
| FormCancelledError | promptantic.form.target | The user closed the form without submitting it. |
| FormTarget | promptantic.form.target | The schema a form is built from, and how its result is validated. |
| FormValidationError | promptantic.form.target | The finished value doesn't validate. |
| ModelCreator | promptantic.creator | Ask for a model's name and fields, and build the pydantic class. |
| ModelGenerator | promptantic.generator | Fill a pydantic model interactively; prefer :func:promptantic.fill. |
| ModelSpec | promptantic.model_spec | A model being designed: its name, description and fields. |
| PromptanticError | promptantic.exceptions | Base exception for promptantic. |
🛈 DocStrings¶
Promptantic: main package.
Generate pydantic models using prompts.
FieldSpec
¶
Bases: BaseModel
One field of a model being designed.
Source code in src/promptantic/model_spec.py
json_schema
¶
The field as a JSON Schema property.
Source code in src/promptantic/model_spec.py
FormCancelledError
¶
FormTarget
dataclass
¶
The schema a form is built from, and how its result is validated.
Source code in src/promptantic/form/target.py
validate
¶
The validated result (a model instance for Python types).
Raises:
| Type | Description |
|---|---|
FormValidationError
|
With every issue found, not only the first. |
FormValidationError
¶
Bases: ValueError
The finished value doesn't validate.
Source code in src/promptantic/form/target.py
ModelCreator
¶
Ask for a model's name and fields, and build the pydantic class.
Source code in src/promptantic/creator.py
acreate
async
¶
acreate(
model_name: str | None = None, base_classes: tuple[type[BaseModel], ...] = (BaseModel,)
) -> type[BaseModel]
A new pydantic class, designed in a form.
Raises:
| Type | Description |
|---|---|
FormCancelledError
|
The user cancelled. |
Source code in src/promptantic/creator.py
acreate_instance
async
¶
acreate_instance(
model_name: str | None = None,
base_classes: tuple[type[BaseModel], ...] = (BaseModel,),
populator: ModelGenerator | None = None,
) -> BaseModel
Design a model, then fill an instance of it.
Source code in src/promptantic/creator.py
ModelGenerator
¶
Fill a pydantic model interactively; prefer :func:promptantic.fill.
The constructor's options (style, show_progress, ...) belonged to the old
prompt-per-type implementation and are accepted but ignored.
Source code in src/promptantic/generator.py
ModelSpec
¶
Bases: BaseModel
A model being designed: its name, description and fields.
Source code in src/promptantic/model_spec.py
json_schema
¶
The model as a JSON Schema object.
model_class
¶
A pydantic class for the spec (nested objects become nested classes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
type[BaseModel] | tuple[type[Any], ...]
|
The base class, or several (a tuple, as for |
BaseModel
|
Source code in src/promptantic/model_spec.py
PromptanticError
¶
fill
async
¶
fill(
target: type[T] | FormTarget[T],
*,
title: str | None = None,
initial: Mapping[str, Any] | None = None,
ui: UI = "auto",
) -> T
fill(
target: type[Any] | FormTarget[Any] | Mapping[str, Any],
*,
title: str | None = None,
initial: Mapping[str, Any] | None = None,
ui: UI = "auto",
) -> Any
Ask the user to fill a form and return the validated result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
type[Any] | FormTarget[Any] | Mapping[str, Any]
|
A JSON Schema (gives a dict), or a Python type such as a pydantic model or dataclass (gives an instance). |
required |
title
|
str | None
|
Heading of the form (default: the schema's title). |
None
|
initial
|
Mapping[str, Any] | None
|
Starting values (default: the schema's defaults). |
None
|
ui
|
UI
|
|
'auto'
|
Raises:
| Type | Description |
|---|---|
FormCancelledError
|
The user cancelled. |
Source code in src/promptantic/api.py
target_for
¶
target_for(target: type[T]) -> FormTarget[T]
target_for(target: Mapping[str, Any]) -> FormTarget[dict[str, Any]]
target_for(target: type[Any] | Mapping[str, Any]) -> FormTarget[Any]
The form target for a JSON Schema (as a mapping) or a Python type.