Generate randomized instances of pydantic classes for testing
Project description
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 generate
class User(BaseModel):
user_id: int
name: str
is_active: bool
email: str | None
random_user = 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 generate
N = 1_000_000
class World(BaseModel):
radius: Annotated[float, Field(gt=0, lt=360)]
with open("random-data.jsonl", "w") as f:
for _ in trange(N):
item = generate(World)
f.write(item.model_dump_json() + "\n")
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_rng-0.1.4.tar.gz.
File metadata
- Download URL: pydantic_rng-0.1.4.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17bafdc18805cdbcf61d7ff4bd22a371815486c25ebc693e23c2714a822171e2
|
|
| MD5 |
b464dfbd0342a2989ef9bf3a39cace6f
|
|
| BLAKE2b-256 |
08c309e0f5bb30b17add9249bf7cc9fc088364a4fe299bbfb31666725d934874
|
File details
Details for the file pydantic_rng-0.1.4-py3-none-any.whl.
File metadata
- Download URL: pydantic_rng-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d66a0d484535de72ed7e25f92bd3a1ae143022e96b1771289622d323e90bec1e
|
|
| MD5 |
1ea2c1169c70a3cae50c43de8ef13c1b
|
|
| BLAKE2b-256 |
f693db0369c684d307d259eaf56063441b61ec0543926210c7958bed9200f555
|