# Fauxdantic
A library for generating fake Pydantic models for testing. Fauxdantic makes it easy to create realistic test data for your Pydantic models. Pairs well with testing of fastapi endpoints.
## Installation
```bash
poetry add fauxdantic
```
## Features
- Generate fake data for any Pydantic model
- Support for nested models
- Support for common Python types:
- Basic types (str, int, float, bool)
- Optional types
- Lists
- Dicts
- UUIDs
- Datetimes
- Enums
- Customizable values through keyword arguments
- Generate dictionaries of fake data without creating model instances
## Usage
### Basic Usage
```python
from pydantic import BaseModel
from fauxdantic import faux, faux_dict
class User(BaseModel):
name: str
age: int
email: str
is_active: bool
# Generate a fake user
fake_user = faux(User)
print(fake_user)
# Output: name='Smith' age=2045 email='smith@example.com' is_active=True
# Generate a dictionary of fake values
fake_dict = faux_dict(User)
print(fake_dict)
# Output: {'name': 'Smith', 'age': 2045, 'email': 'smith@example.com', 'is_active': True}
```
### Nested Models
```python
from pydantic import BaseModel
from fauxdantic import faux, faux_dict
class Address(BaseModel):
street: str
city: str
zip_code: str
class User(BaseModel):
name: str
age: int
address: Address
# Generate a fake user with nested address
fake_user = faux(User)
print(fake_user)
# Output: name='Smith' age=2045 address=Address(street='123 Main St', city='Anytown', zip_code='12345')
# Generate a dictionary with nested address
fake_dict = faux_dict(User)
print(fake_dict)
# Output: {'name': 'Smith', 'age': 2045, 'address': {'street': '123 Main St', 'city': 'Anytown', 'zip_code': '12345'}}
```
### Optional Fields
```python
from typing import Optional
from pydantic import BaseModel
from fauxdantic import faux, faux_dict
class User(BaseModel):
name: str
age: Optional[int]
email: Optional[str]
# Generate a fake user with optional fields
fake_user = faux(User)
print(fake_user)
# Output: name='Smith' age=None email='smith@example.com'
# Generate a dictionary with optional fields
fake_dict = faux_dict(User)
print(fake_dict)
# Output: {'name': 'Smith', 'age': None, 'email': 'smith@example.com'}
```
### Lists and Dicts
```python
from typing import List, Dict
from pydantic import BaseModel
from fauxdantic import faux, faux_dict
class User(BaseModel):
name: str
tags: List[str]
preferences: Dict[str, str]
# Generate a fake user with lists and dicts
fake_user = faux(User)
print(fake_user)
# Output: name='Smith' tags=['tag1', 'tag2'] preferences={'key1': 'value1', 'key2': 'value2'}
# Generate a dictionary with lists and dicts
fake_dict = faux_dict(User)
print(fake_dict)
# Output: {'name': 'Smith', 'tags': ['tag1', 'tag2'], 'preferences': {'key1': 'value1', 'key2': 'value2'}}
```
### Custom Values
```python
from pydantic import BaseModel
from fauxdantic import faux, faux_dict
class User(BaseModel):
name: str
age: int
email: str
# Generate a fake user with custom values
fake_user = faux(User, name="John Doe", age=30)
print(fake_user)
# Output: name='John Doe' age=30 email='smith@example.com'
# Generate a dictionary with custom values
fake_dict = faux_dict(User, name="John Doe", age=30)
print(fake_dict)
# Output: {'name': 'John Doe', 'age': 30, 'email': 'smith@example.com'}
```
### Unique String Generation
Fauxdantic supports generating truly unique string values using the `<unique>` pattern. This is useful for creating unique identifiers, route numbers, or any field that requires uniqueness.
```python
from typing import Optional
from pydantic import BaseModel, Field
from fauxdantic import faux
class Bus(BaseModel):
route_number: Optional[str] = Field(None, max_length=50)
# Generate buses with unique route numbers
bus1 = faux(Bus, route_number="SW<unique>")
bus2 = faux(Bus, route_number="SW<unique>")
bus3 = faux(Bus, route_number="EXPRESS<unique>")
print(bus1.route_number) # SW1753986564318970_793119f2
print(bus2.route_number) # SW1753986564319017_f33460cc
print(bus3.route_number) # EXPRESS1753986564319059_9f1de0da
```
#### Examples with Different Constraints
```python
class ShortBus(BaseModel):
route_number: Optional[str] = Field(None, max_length=10)
class MediumBus(BaseModel):
route_number: Optional[str] = Field(None, max_length=15)
class LongBus(BaseModel):
route_number: Optional[str] = Field(None, max_length=50)
# Different constraint lengths
short_bus = faux(ShortBus, route_number="SW<unique>") # SWf2830b (9 chars)
medium_bus = faux(MediumBus, route_number="SW<unique>") # SW208936f1 (11 chars)
long_bus = faux(LongBus, route_number="SW<unique>") # SW1753986564318970_793119f2 (28 chars)
```
### Enums
```python
from enum import Enum
from pydantic import BaseModel
from fauxdantic import faux, faux_dict
class UserRole(str, Enum):
ADMIN = "admin"
USER = "user"
GUEST = "guest"
class User(BaseModel):
name: str
role: UserRole
# Generate a fake user with enum
fake_user = faux(User)
print(fake_user)
# Output: name='Smith' role=<UserRole.ADMIN: 'admin'>
# Generate a dictionary with enum
fake_dict = faux_dict(User)
print(fake_dict)
# Output: {'name': 'Smith', 'role': 'admin'}
```
## Development
```bash
# Install dependencies
poetry install
# Run tests
poetry run pytest
# Format code
poetry run black .
poetry run isort .
# Type checking
poetry run mypy .
```
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License - see the LICENSE file for details.
Raw data
{
"_id": null,
"home_page": "https://github.com/jdungan/fauxdantic",
"name": "fauxdantic",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "pydantic, testing, faker, fake-data",
"author": "John A. Dungan",
"author_email": "johnadungan@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/a5/47/bbe00e718e6d159439e160791ad3d6687cd0d680ecc296c21ea6d12cf1f9/fauxdantic-0.1.11.tar.gz",
"platform": null,
"description": "# Fauxdantic\n\nA library for generating fake Pydantic models for testing. Fauxdantic makes it easy to create realistic test data for your Pydantic models. Pairs well with testing of fastapi endpoints.\n\n## Installation\n\n```bash\npoetry add fauxdantic\n```\n\n## Features\n\n- Generate fake data for any Pydantic model\n- Support for nested models\n- Support for common Python types:\n - Basic types (str, int, float, bool)\n - Optional types\n - Lists\n - Dicts\n - UUIDs\n - Datetimes\n - Enums\n- Customizable values through keyword arguments\n- Generate dictionaries of fake data without creating model instances\n\n## Usage\n\n### Basic Usage\n\n```python\nfrom pydantic import BaseModel\nfrom fauxdantic import faux, faux_dict\n\nclass User(BaseModel):\n name: str\n age: int\n email: str\n is_active: bool\n\n# Generate a fake user\nfake_user = faux(User)\nprint(fake_user)\n# Output: name='Smith' age=2045 email='smith@example.com' is_active=True\n\n# Generate a dictionary of fake values\nfake_dict = faux_dict(User)\nprint(fake_dict)\n# Output: {'name': 'Smith', 'age': 2045, 'email': 'smith@example.com', 'is_active': True}\n```\n\n### Nested Models\n\n```python\nfrom pydantic import BaseModel\nfrom fauxdantic import faux, faux_dict\n\nclass Address(BaseModel):\n street: str\n city: str\n zip_code: str\n\nclass User(BaseModel):\n name: str\n age: int\n address: Address\n\n# Generate a fake user with nested address\nfake_user = faux(User)\nprint(fake_user)\n# Output: name='Smith' age=2045 address=Address(street='123 Main St', city='Anytown', zip_code='12345')\n\n# Generate a dictionary with nested address\nfake_dict = faux_dict(User)\nprint(fake_dict)\n# Output: {'name': 'Smith', 'age': 2045, 'address': {'street': '123 Main St', 'city': 'Anytown', 'zip_code': '12345'}}\n```\n\n### Optional Fields\n\n```python\nfrom typing import Optional\nfrom pydantic import BaseModel\nfrom fauxdantic import faux, faux_dict\n\nclass User(BaseModel):\n name: str\n age: Optional[int]\n email: Optional[str]\n\n# Generate a fake user with optional fields\nfake_user = faux(User)\nprint(fake_user)\n# Output: name='Smith' age=None email='smith@example.com'\n\n# Generate a dictionary with optional fields\nfake_dict = faux_dict(User)\nprint(fake_dict)\n# Output: {'name': 'Smith', 'age': None, 'email': 'smith@example.com'}\n```\n\n### Lists and Dicts\n\n```python\nfrom typing import List, Dict\nfrom pydantic import BaseModel\nfrom fauxdantic import faux, faux_dict\n\nclass User(BaseModel):\n name: str\n tags: List[str]\n preferences: Dict[str, str]\n\n# Generate a fake user with lists and dicts\nfake_user = faux(User)\nprint(fake_user)\n# Output: name='Smith' tags=['tag1', 'tag2'] preferences={'key1': 'value1', 'key2': 'value2'}\n\n# Generate a dictionary with lists and dicts\nfake_dict = faux_dict(User)\nprint(fake_dict)\n# Output: {'name': 'Smith', 'tags': ['tag1', 'tag2'], 'preferences': {'key1': 'value1', 'key2': 'value2'}}\n```\n\n### Custom Values\n\n```python\nfrom pydantic import BaseModel\nfrom fauxdantic import faux, faux_dict\n\nclass User(BaseModel):\n name: str\n age: int\n email: str\n\n# Generate a fake user with custom values\nfake_user = faux(User, name=\"John Doe\", age=30)\nprint(fake_user)\n# Output: name='John Doe' age=30 email='smith@example.com'\n\n# Generate a dictionary with custom values\nfake_dict = faux_dict(User, name=\"John Doe\", age=30)\nprint(fake_dict)\n# Output: {'name': 'John Doe', 'age': 30, 'email': 'smith@example.com'}\n```\n\n### Unique String Generation\n\nFauxdantic supports generating truly unique string values using the `<unique>` pattern. This is useful for creating unique identifiers, route numbers, or any field that requires uniqueness.\n\n```python\nfrom typing import Optional\nfrom pydantic import BaseModel, Field\nfrom fauxdantic import faux\n\nclass Bus(BaseModel):\n route_number: Optional[str] = Field(None, max_length=50)\n\n# Generate buses with unique route numbers\nbus1 = faux(Bus, route_number=\"SW<unique>\")\nbus2 = faux(Bus, route_number=\"SW<unique>\")\nbus3 = faux(Bus, route_number=\"EXPRESS<unique>\")\n\nprint(bus1.route_number) # SW1753986564318970_793119f2\nprint(bus2.route_number) # SW1753986564319017_f33460cc\nprint(bus3.route_number) # EXPRESS1753986564319059_9f1de0da\n```\n\n#### Examples with Different Constraints\n\n```python\nclass ShortBus(BaseModel):\n route_number: Optional[str] = Field(None, max_length=10)\n\nclass MediumBus(BaseModel):\n route_number: Optional[str] = Field(None, max_length=15)\n\nclass LongBus(BaseModel):\n route_number: Optional[str] = Field(None, max_length=50)\n\n# Different constraint lengths\nshort_bus = faux(ShortBus, route_number=\"SW<unique>\") # SWf2830b (9 chars)\nmedium_bus = faux(MediumBus, route_number=\"SW<unique>\") # SW208936f1 (11 chars)\nlong_bus = faux(LongBus, route_number=\"SW<unique>\") # SW1753986564318970_793119f2 (28 chars)\n```\n\n### Enums\n\n```python\nfrom enum import Enum\nfrom pydantic import BaseModel\nfrom fauxdantic import faux, faux_dict\n\nclass UserRole(str, Enum):\n ADMIN = \"admin\"\n USER = \"user\"\n GUEST = \"guest\"\n\nclass User(BaseModel):\n name: str\n role: UserRole\n\n# Generate a fake user with enum\nfake_user = faux(User)\nprint(fake_user)\n# Output: name='Smith' role=<UserRole.ADMIN: 'admin'>\n\n# Generate a dictionary with enum\nfake_dict = faux_dict(User)\nprint(fake_dict)\n# Output: {'name': 'Smith', 'role': 'admin'}\n```\n\n## Development\n\n```bash\n# Install dependencies\npoetry install\n\n# Run tests\npoetry run pytest\n\n# Format code\npoetry run black .\npoetry run isort .\n\n# Type checking\npoetry run mypy .\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details. ",
"bugtrack_url": null,
"license": "MIT",
"summary": "A library for generating fake Pydantic models for testing and development purposes",
"version": "0.1.11",
"project_urls": {
"Documentation": "https://github.com/jdungan/fauxdantic#readme",
"Homepage": "https://github.com/jdungan/fauxdantic",
"Repository": "https://github.com/jdungan/fauxdantic"
},
"split_keywords": [
"pydantic",
" testing",
" faker",
" fake-data"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c7cf05b62f75d523b9863fbd7a0053a65fbd63e1fbfe64d9a34a04585ece7a00",
"md5": "1e09ef39868165583cea8edfe7b1e9ff",
"sha256": "fff47ce1dec968a8c03f3042083a5a5bc35a73705dcc47ebcc36f8626d1d513e"
},
"downloads": -1,
"filename": "fauxdantic-0.1.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1e09ef39868165583cea8edfe7b1e9ff",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 7789,
"upload_time": "2025-08-01T20:24:18",
"upload_time_iso_8601": "2025-08-01T20:24:18.753293Z",
"url": "https://files.pythonhosted.org/packages/c7/cf/05b62f75d523b9863fbd7a0053a65fbd63e1fbfe64d9a34a04585ece7a00/fauxdantic-0.1.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a547bbe00e718e6d159439e160791ad3d6687cd0d680ecc296c21ea6d12cf1f9",
"md5": "211ef348060ddf8ce56e5d1a1232310e",
"sha256": "f87fdc0fe1388e20f9fd306ea90cdb5f958456d175f8005f337b229821041a3b"
},
"downloads": -1,
"filename": "fauxdantic-0.1.11.tar.gz",
"has_sig": false,
"md5_digest": "211ef348060ddf8ce56e5d1a1232310e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 7299,
"upload_time": "2025-08-01T20:24:19",
"upload_time_iso_8601": "2025-08-01T20:24:19.822668Z",
"url": "https://files.pythonhosted.org/packages/a5/47/bbe00e718e6d159439e160791ad3d6687cd0d680ecc296c21ea6d12cf1f9/fauxdantic-0.1.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-01 20:24:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jdungan",
"github_project": "fauxdantic",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "fauxdantic"
}