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
Built Distribution
Close
Hashes for pydantic_python_regex_validator-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0f404f8287b605e598efd7affe13abb6bbbe4c82d28ef95c7fe983e24d88f3b |
|
MD5 | bd428415e0ec86e20c841807d8dd0b3f |
|
BLAKE2b-256 | 695eabffa9e2f260d616a923b6e6417316b3220edd91417b534ef2d9474a3943 |
Close
Hashes for pydantic_python_regex_validator-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3d38b8f178448852b2d5ba681137f11ed0f0d54a1f5da569b3050372c67391b |
|
MD5 | 80714eb18ca00d6f935bc36c5a66b7c6 |
|
BLAKE2b-256 | c1a9fbd32f27635450d9f0cf00b4cb52e1f37a66100a07ac07d706c56c8f2d6f |