I can use Venvalid with Pydantic #15
Answered
by
castroofelipee
peterstan077
asked this question in
Q&A
-
|
I can use Venvalid with Pydantic |
Beta Was this translation helpful? Give feedback.
Answered by
castroofelipee
Aug 12, 2025
Replies: 1 comment
-
|
Yes, you can use Venvalid together with Pydantic, but each would have a different role:
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),
“DATABASE_URL”: str_(),
})
# Use the validated values within a Pydantic model
class Settings(BaseModel):
debug: bool
port: int
database_url: str
settings = Settings(**env_config)
print(settings) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
peterstan077
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, you can use Venvalid together with Pydantic, but each would have a different role: