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.3.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.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: copier_pydantic-0.1.3.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","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.3.tar.gz
Algorithm Hash digest
SHA256 cb4929252627a3f759ee38810b5a6ef965ececa2681088eb72264a90fe491664
MD5 0c12e3ed96da984f0a724383c9df9396
BLAKE2b-256 69013e71eea2eaa08b0f835f42218f82398402d3305b67945abdc00118c10c47

See more details on using hashes here.

File details

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

File metadata

  • Download URL: copier_pydantic-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8db44529dbd1a1cb4179349f44872836209dac6347c2c6ff637643f59c6f96fd
MD5 c2afcbb4db7895f9abc2852321d60f77
BLAKE2b-256 de6e8194bc2febf8a9d85f625e2afe1b8c893d4fafd911e1101c8c700883b2d7

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