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 RegexQuery, RegexBody
from fastapi import FastAPI
app = FastAPI()
@app.get("/test")
async def get_endpoint(my_param: RegexQuery("^foo")):
return my_param
@app.post("/test")
async def post_endpoint(my_param: RegexBody("^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
File details
Details for the file pydantic_python_regex_validator-0.3.4.tar.gz
.
File metadata
- Download URL: pydantic_python_regex_validator-0.3.4.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1042-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cedae1e3dcb2dd95e485039849bbf565f923e47f66d65b19700d81efdf12d75 |
|
MD5 | 968c8c1d5c721c260874286aceca59c1 |
|
BLAKE2b-256 | 391cf80819339731e60963c113df4514d7c4a5853880356a471b797f21bdbf7c |
File details
Details for the file pydantic_python_regex_validator-0.3.4-py3-none-any.whl
.
File metadata
- Download URL: pydantic_python_regex_validator-0.3.4-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1042-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd96f445af37b595b99ca26e826a43874beabc26b6c3cb0cafb2a9d685bfd4c1 |
|
MD5 | a4273887257927c6864824448f4a0f3d |
|
BLAKE2b-256 | 46dc87548ef4764d29437bd5e4af9455bfd483868674051de23b90d80bd8eb3d |