Skip to main content

A regex validator for pydantic, using python regex.

Project description

A regex parser for Pydantic, using pythons regex validator.

Since pydantic V2, pydantics regex validator has some limitations. It cannot do look arounds. There is some documenation on how to get around this. This package simplifies things for developers

We provide the class, Regex, which can be used.

Usage in Pydantic

To use simply do:

from pydantic_python_regex_validator import Regex
from pydantic import BaseModel
from typing import Annotated

class MyModel(BaseModel):
    my_field: Annotated[str, Regex(r'^foo')]

This will then have field, my_field, which will have the regex constraint ^foo

Usage in FastAPI

This can also be used with fastapi.

from pydantic_python_regex_validator import Regex
from fastapi import FastAPI, Query
from typing import Annotated

app = FastAPI()

@app.get("/test")
async def endpoint(my_param: Annotated[str, Query(), Regex(r"^foo")]):
    return my_param

This then has an endpoint at /test which takes a param, my_param, which has the regex constraint ^foo

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

pydantic_python_regex_validator-0.3.2.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file pydantic_python_regex_validator-0.3.2.tar.gz.

File metadata

File hashes

Hashes for pydantic_python_regex_validator-0.3.2.tar.gz
Algorithm Hash digest
SHA256 cc2080d4747945af8086e64aa3296120974f9f402a5a8d5d5cdbd59109df66a9
MD5 bf459fb9c304ee1fcb46fcc62fbd9328
BLAKE2b-256 e4223abb1471966fb991cffbb2048bebe3aad34214dea08b983ba03f7ce7eda8

See more details on using hashes here.

File details

Details for the file pydantic_python_regex_validator-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_python_regex_validator-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f28fcf9a472478d67ff9dc2641bf1177736517d7cb5c62b641104d99b28073f3
MD5 ff06e0622f7c6ebf8035b3d58041342c
BLAKE2b-256 a9d96861333f04c436d83a7e02579ce407f3a7fd9123bff866f4cf8daef6e316

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