Skip to main content

pyenvalid

Beautiful validation errors for pydantic-settings.

The Problem

When using pydantic-settings with required environment variables, missing or invalid values produce cryptic errors:

from pydantic_settings import BaseSettings

class Settings(BaseSettings):
    database_url: str
    api_key: str
    port: int = 8080

settings = Settings()  # Raises ValidationError if DATABASE_URL or API_KEY not set
pydantic_core._pydantic_core.ValidationError: 2 validation errors for Settings
database_url
  Field required [type=missing, input_value={}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
api_key
  Field required [type=missing, input_value={}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing

This error is confusing because:

  • It doesn't mention environment variables in a friendly way
  • The input_value={} is misleading (it's not a dict, it's your environment)
  • Hard to quickly see which variables need to be set

The Solution

pyenvalid wraps validation and provides clear, actionable error messages:

┌──────────────────────────────────────────────────────────────────────────┐
│ CONFIGURATION ERROR                                                      │
├──────────────────────────────────────────────────────────────────────────┤
│                                                                          │
│ The following environment variables have issues:                         │
│                                                                          │
│   ✗ DATABASE_URL (missing)                                               │
│   ✗ API_KEY (missing)                                                    │
│                                                                          │
├──────────────────────────────────────────────────────────────────────────┤
│ Set these in your .env file or environment                               │
└──────────────────────────────────────────────────────────────────────────┘

Installation

pip install pyenvalid

Or with uv:

uv add pyenvalid

Usage

from pydantic_settings import BaseSettings
from pyenvalid import validate_settings

class Settings(BaseSettings):
    database_url: str
    api_key: str
    port: int = 8080

settings = validate_settings(Settings)

That's it. If DATABASE_URL or API_KEY are missing, you get the nice error box instead of pydantic's raw error.

With .env file

from pydantic_settings import BaseSettings, SettingsConfigDict
from pyenvalid import validate_settings

class Settings(BaseSettings):
    model_config = SettingsConfigDict(env_file=".env")

    secret_key: str
    database_url: str

settings = validate_settings(Settings)

Custom error messages

from pyenvalid import ConfigurationError, validate_settings

try:
    settings = validate_settings(Settings)
except ConfigurationError as e:
    raise ConfigurationError(
        e.errors,
        title="DATABASE ERROR",
        hint="Check your .env.local file",
    ) from None

Handling errors programmatically

from pyenvalid import ConfigurationError, validate_settings

try:
    settings = validate_settings(Settings)
except ConfigurationError as e:
    print(e.errors)  # [('database_url', 'missing'), ('api_key', 'missing')]
    print(e.missing_fields)  # ['database_url', 'api_key']

Error Types

The error type shown is the raw pydantic error type:

Error Meaning
missing Required field not set
int_parsing Value can't be parsed as integer
bool_parsing Value can't be parsed as boolean
literal_error Value not in allowed options
url_parsing Invalid URL format

License

MIT

Metadata

Release files for pyenvalid 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyenvalid 0.1.0
File Size Uploaded Provenance Actions
pyenvalid-0.1.0.tar.gz 5.0 kB With provenance Details for pyenvalid-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyenvalid 0.1.0
File Interpreter ABI Platform Actions
pyenvalid-0.1.0-py3-none-any.whl Python 3 none any Details for pyenvalid-0.1.0-py3-none-any.whl

Total release size: 8.1 kB

Release files / pyenvalid-0.1.0.tar.gz

Download URL pyenvalid-0.1.0.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
fbd774a949ed418592f895b5e9e9c45f1ee265dd20fbecb9660e07564897fd5b
BLAKE2b-256 checksum
How to use checksums
3a0b48e8c1248e336fd2405553bcd9327dbe8a93c86e2c37faf3057f9beb1e25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2025.

Transparency log

Release files / pyenvalid-0.1.0-py3-none-any.whl

Download URL pyenvalid-0.1.0-py3-none-any.whl
Size 3.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ed57e2a76a5bf45ded48f2d6b3ae5d60e16fac16928bbda6bdbb26ff0e03c66
BLAKE2b-256 checksum
How to use checksums
418c5e808ebcc912f6a5fd37b05fcaa1756601a0bc7ef30d6980602006f799fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2025.

Transparency log

Security for pyenvalid 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyenvalid-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page