Skip to content
Discussion options

You must be logged in to vote

Yes, you can use Venvalid together with Pydantic, but each would have a different role:

  • Venvalid comes in first, validating the environment variables right at the start of the application, ensuring that they are present, well formatted, and within the restrictions (types, allowed, etc.).
  • Pydantic comes in later, validating data from requests, files, or other dynamic sources at runtime.
from venvalid import str_, int_, bool_, venvalid
from venvalid.dotenv import load_env_file
from pydantic import BaseModel

# Load variables from .env
load_env_file(“.env”)

# Validate with Venvalid before running the app
env_config = venvalid({
    “DEBUG”: bool_(default=False),
    “PORT”: int_(default=8000

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by peterstan077
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants