pydantic-rng
A simple library for generating random, valid Pydantic models.
This tool helps you quickly create mock data for testing, prototyping, and demonstration purposes by generating random values that conform to your Pydantic model schemas. It supports a wide range of types and validation constraints.
✨ Features
- Type-aware Generation: Generates appropriate data for common Python types (
str,int,float,bool,list,dict,set, etc.). - pydantic Integration: Works seamlessly with Pydantic's
BaseModelfor recursive data generation. - Constraint Support: Respects a wide variety of Pydantic validation constraints from the
annotated_typeslibrary, includingMinLen,MaxLen,Ge,Gt,Le,Lt, andMultipleOf. - Configurable: Customize the behavior of the random generator with global settings for things like numeric and string ranges, and the probability of generating
Nonefor optional fields.
🚀 Installation
Install the package (usually as a dev dependency):
uv add --dev pydantic-rng
Generate Basic Class RNG
from pydantic import BaseModel
from pydantic_rng import PydanticRandom
class User(BaseModel):
user_id: int
name: str
is_active: bool
email: str | None = None
random_user = PydanticRandom().generate(User)
print(random_user.model_dump_json(indent=2))
Or, more usually...
from typing import Annotated
from tqdm.rich import trange # requires `rich` as well
from pydantic import BaseModel, Field
from pydantic_rng import PydanticRandom
N = 1_000_000
class World(BaseModel):
radius: Annotated[float, Field(gt=0, lt=360)]
moons: list[str]
# set seed for consistency across runs
# also configure
rng = PydanticRandom(seed=42).configure_rng(
# max length of moon names
max_sequence_length=10,
)
with open("random-data.jsonl", "w") as f:
for _ in trange(N):
item = generate(World)
f.write(item.model_dump_json() + "\n")
Metadata
Release files for pydantic-rng 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydantic_rng-0.2.0.tar.gz | 4.4 kB | Without provenance | Details for pydantic_rng-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydantic_rng-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pydantic_rng-0.2.0-py3-none-any.whl |
Total release size: 9.9 kB
Release files / pydantic_rng-0.2.0.tar.gz
| Download URL | pydantic_rng-0.2.0.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
37940ed1cb3b26d58a9b36c94124e242cc8074a2467c8ae4f735d3d974fb6b66
|
|
BLAKE2b-256 checksum How to use checksums |
ff788e0fd60b205461b00383603661d996cba350b35d17c2fc183258c09220a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.8.14
|
Release files / pydantic_rng-0.2.0-py3-none-any.whl
| Download URL | pydantic_rng-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d40d7239b5e091ace0108ac1a33357620fc871c9da65f7a1a5b1b8b193423519
|
|
BLAKE2b-256 checksum How to use checksums |
837e3c5c6d74530a1f6889cd7d2d879171930892774b83ffe8b889a43d6016cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.8.14
|
Security for pydantic-rng 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.