Integrations¶
Edify ships lightweight integration modules that let you drop a compiled
edify.Pattern into the field-validation layers of the frameworks
most Python teams actually use. Each integration is an opt-in extra —
pip install edify never pulls the framework in, and importing an
integration module never imports the framework at module load time. The
first helper call resolves the framework lazily; when the extra is
missing you get a clean edify.errors.integration.MissingIntegrationDependencyError
with the exact install line to run.
Install any one, or all three:
pip install 'edify[pydantic]'
pip install 'edify[fastapi]'
pip install 'edify[django]'
pip install 'edify[all]'
Pydantic¶
Pydantic integration — validate string fields against an edify Pattern.
Requires the pydantic extra: pip install edify[pydantic]. Importing this module
without the framework installed raises ImportError at import time.
Typical usage:
from typing import Annotated
from pydantic import AfterValidator, BaseModel
from edify.integrations.pydantic import pattern_validator
from edify.library import email
class Contact(BaseModel):
address: Annotated[str, AfterValidator(pattern_validator(email))]
- edify.integrations.pydantic.pattern_validator(pattern: Pattern) Callable[[str], str][source]¶
Return a Pydantic-compatible validator callable for
pattern.The returned callable accepts a string and returns it unchanged when the pattern matches; otherwise raises
edify.errors.integration.PatternDidNotMatchError(aValueErrorsubclass) that Pydantic embeds in itsValidationError.- Parameters:
pattern – The
edify.Patternthe field must match anywhere in.
FastAPI¶
FastAPI integration — validate request paths and queries against an edify Pattern.
Requires the fastapi extra: pip install edify[fastapi]. Importing this module
without the framework installed raises ImportError at import time.
- edify.integrations.fastapi.pattern_path(pattern: Pattern, description: str | None = None) Path[source]¶
Return a
fastapi.Pathvalue pinned topattern.- Parameters:
pattern – The
edify.Patterna path parameter must match anywhere in.description – Optional OpenAPI description forwarded to
fastapi.Path().
- edify.integrations.fastapi.pattern_query(pattern: Pattern, default: str | None = None, description: str | None = None) Query[source]¶
Return a
fastapi.Queryvalue pinned topattern.- Parameters:
pattern – The
edify.Patterna query parameter must match anywhere in.default – Optional default value; when None the parameter is required.
description – Optional OpenAPI description forwarded to
fastapi.Query().
Django¶
Django integration — validate model / form fields against an edify Pattern.
Requires the django extra: pip install edify[django]. Django ships no type
information, so the module is loaded through importlib.import_module() and its
one used entry point is described by a local Protocol.
- edify.integrations.django.pattern_validator(pattern: Pattern, message: str | None = None, code: str = 'invalid') _RegexValidator[source]¶
Return a
django.core.validators.RegexValidatorpinned topattern.- Parameters:
pattern – The
edify.Patterna field must match anywhere in.message – The error message the validator raises on rejection. Defaults to a message that reproduces the pattern’s regex string.
code – The Django validation-error code the validator raises on rejection.