Skip to main content

Adds support for Pydantic Models in Copier templates

Project description

Copier Pydantic

pypi version

Jinja2 extensions for Copier that enable using Pydantic Models for validation and within templates

Installation

With pip:

pip install copier-pydantic

With uv:

uv tool install copier --with copier-pydantic

With pipx:

pipx install copier
pipx inject copier copier-pydantic

Usage with Copier

In your copier template configuration:

# Add the jinja extensions
_jinja_extensions:
  - copier_pydantic.MultilineValidation
  - copier_pydantic.PydanticExtension

# and exclude the model.py file from your template
_exclude:
  - models.py
# or use the best practice of having the template in a sub directory
_subdirectory: template

So your template will look something like this

📁 template_root
├── 📄 models.py
├── 📄 copier.yml
└── 📁 template
    ├── 📄 {{_copier_conf.answers_file}}.jinja
    └── 📄 ...

With models.py containing your Pydantic BaseModel's like this

from pydantic import BaseModel

class DatabaseConfig(BaseModel):
    db_host: str
    db_port: int

you can then use your model to validate the question input like this

validated_example:
  type: yaml
  multiline: true
  default: |
    db_host: 'localhost'
    db_port: 5432
  validator: "{{ validated_example | validate_as(DatabaseConfig) }}"

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

copier_pydantic-0.1.4.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

copier_pydantic-0.1.4-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file copier_pydantic-0.1.4.tar.gz.

File metadata

  • Download URL: copier_pydantic-0.1.4.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for copier_pydantic-0.1.4.tar.gz
Algorithm Hash digest
SHA256 04779401f016a139a111a2f8404eeb0a2cbf125a6784d71e29c767ea07b67f0b
MD5 1fc34d19076768d45f9debedd63cb492
BLAKE2b-256 6af506074b2ae42aaefbb17eb0cb3f490e8ab9c8fdbb86ea3e3076765944a60f

See more details on using hashes here.

File details

Details for the file copier_pydantic-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: copier_pydantic-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for copier_pydantic-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 95fb460f61339540c0056d77b972ba1876c647e1a50506f3e341d35eeb27d56a
MD5 3fd7d96bb1ccf3c2b9a022b5d010788d
BLAKE2b-256 4b7b86ae829c9301fe7be0e2ee2f6adb189fceb1a195487ecc3b0360c1406a47

See more details on using hashes here.

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