pydantic-factories


Namepydantic-factories JSON
Version 1.17.1 PyPI version JSON
download
home_pagehttps://github.com/starlite-api/pydantic-factories
SummaryMock data generation for pydantic based models and python dataclasses
upload_time2023-01-15 19:33:19
maintainerNa'aman Hirschfeld
docs_urlNone
authorNa'aman Hirschfeld
requires_python>=3.8,<4.0
licenseMIT
keywords dataclasses factory faker mock pydantic pytest starlite tdd testing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!-- markdownlint-disable -->
<img alt="Starlite logo" src="docs/images/starlite-banner.svg" width="100%" height="auto">
<!-- markdownlint-restore -->

<!-- markdownlint-disable -->
<div align="center">

![PyPI - License](https://img.shields.io/pypi/l/pydantic-factories?color=blue)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pydantic-factories)

[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/Goldziher/pydantic-factories.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Goldziher/pydantic-factories/context:python)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/Goldziher/pydantic-factories.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Goldziher/pydantic-factories/alerts/)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=starlite-api_pydantic-factories&metric=coverage)](https://sonarcloud.io/summary/new_code?id=starlite-api_pydantic-factories)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=starlite-api_pydantic-factories&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=starlite-api_pydantic-factories)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=starlite-api_pydantic-factories&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=starlite-api_pydantic-factories)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=starlite-api_pydantic-factories&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=starlite-api_pydantic-factories)

[![Discord](https://img.shields.io/discord/919193495116337154?color=blue&label=chat%20on%20discord&logo=discord)](https://discord.gg/X3FJqy8d2j)

</div>
<!-- markdownlint-restore -->

# Pydantic-Factories

This library offers powerful mock data generation capabilities for [pydantic](https://github.com/samuelcolvin/pydantic)
based models, `dataclasses` and `TypeDict`s. It can also be used with other libraries that use pydantic as a foundation.

Check out [the documentation 📚](https://starlite-api.github.io/pydantic-factories/).

## Installation

```shell
pip install pydantic-factories
```

## Example

```python
from datetime import date, datetime
from typing import List, Union

from pydantic import BaseModel, UUID4

from pydantic_factories import ModelFactory


class Person(BaseModel):
    id: UUID4
    name: str
    hobbies: List[str]
    age: Union[float, int]
    birthday: Union[datetime, date]


class PersonFactory(ModelFactory):
    __model__ = Person


result = PersonFactory.build()
```

That's it - with almost no work, we are able to create a mock data object fitting the `Person` class model definition.

This is possible because of the typing information available on the pydantic model and model-fields, which are used as a
source of truth for data generation.

The factory parses the information stored in the pydantic model and generates a dictionary of kwargs that are passed to
the `Person` class' init method.

## Features

- ✅ supports both built-in and pydantic types
- ✅ supports pydantic field constraints
- ✅ supports complex field types
- ✅ supports custom model fields
- ✅ supports dataclasses

## Why This Library?

- 💯 powerful
- 💯 extensible
- 💯 simple
- 💯 rigorously tested

## Contributing

This library is open to contributions - in fact we welcome it. [Please see the contribution guide!](CONTRIBUTING.md)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/starlite-api/pydantic-factories",
    "name": "pydantic-factories",
    "maintainer": "Na'aman Hirschfeld",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "nhirschfeld@gmail.com",
    "keywords": "dataclasses,factory,faker,mock,pydantic,pytest,starlite,tdd,testing",
    "author": "Na'aman Hirschfeld",
    "author_email": "nhirschfeld@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d5/b7/d894c8ce5501d0381f71237df543abb2a2421d97fa836fb11bcad07768fd/pydantic_factories-1.17.1.tar.gz",
    "platform": null,
    "description": "<!-- markdownlint-disable -->\n<img alt=\"Starlite logo\" src=\"docs/images/starlite-banner.svg\" width=\"100%\" height=\"auto\">\n<!-- markdownlint-restore -->\n\n<!-- markdownlint-disable -->\n<div align=\"center\">\n\n![PyPI - License](https://img.shields.io/pypi/l/pydantic-factories?color=blue)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pydantic-factories)\n\n[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/Goldziher/pydantic-factories.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Goldziher/pydantic-factories/context:python)\n[![Total alerts](https://img.shields.io/lgtm/alerts/g/Goldziher/pydantic-factories.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Goldziher/pydantic-factories/alerts/)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=starlite-api_pydantic-factories&metric=coverage)](https://sonarcloud.io/summary/new_code?id=starlite-api_pydantic-factories)\n[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=starlite-api_pydantic-factories&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=starlite-api_pydantic-factories)\n[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=starlite-api_pydantic-factories&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=starlite-api_pydantic-factories)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=starlite-api_pydantic-factories&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=starlite-api_pydantic-factories)\n\n[![Discord](https://img.shields.io/discord/919193495116337154?color=blue&label=chat%20on%20discord&logo=discord)](https://discord.gg/X3FJqy8d2j)\n\n</div>\n<!-- markdownlint-restore -->\n\n# Pydantic-Factories\n\nThis library offers powerful mock data generation capabilities for [pydantic](https://github.com/samuelcolvin/pydantic)\nbased models, `dataclasses` and `TypeDict`s. It can also be used with other libraries that use pydantic as a foundation.\n\nCheck out [the documentation \ud83d\udcda](https://starlite-api.github.io/pydantic-factories/).\n\n## Installation\n\n```shell\npip install pydantic-factories\n```\n\n## Example\n\n```python\nfrom datetime import date, datetime\nfrom typing import List, Union\n\nfrom pydantic import BaseModel, UUID4\n\nfrom pydantic_factories import ModelFactory\n\n\nclass Person(BaseModel):\n    id: UUID4\n    name: str\n    hobbies: List[str]\n    age: Union[float, int]\n    birthday: Union[datetime, date]\n\n\nclass PersonFactory(ModelFactory):\n    __model__ = Person\n\n\nresult = PersonFactory.build()\n```\n\nThat's it - with almost no work, we are able to create a mock data object fitting the `Person` class model definition.\n\nThis is possible because of the typing information available on the pydantic model and model-fields, which are used as a\nsource of truth for data generation.\n\nThe factory parses the information stored in the pydantic model and generates a dictionary of kwargs that are passed to\nthe `Person` class' init method.\n\n## Features\n\n- \u2705 supports both built-in and pydantic types\n- \u2705 supports pydantic field constraints\n- \u2705 supports complex field types\n- \u2705 supports custom model fields\n- \u2705 supports dataclasses\n\n## Why This Library?\n\n- \ud83d\udcaf powerful\n- \ud83d\udcaf extensible\n- \ud83d\udcaf simple\n- \ud83d\udcaf rigorously tested\n\n## Contributing\n\nThis library is open to contributions - in fact we welcome it. [Please see the contribution guide!](CONTRIBUTING.md)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Mock data generation for pydantic based models and python dataclasses",
    "version": "1.17.1",
    "split_keywords": [
        "dataclasses",
        "factory",
        "faker",
        "mock",
        "pydantic",
        "pytest",
        "starlite",
        "tdd",
        "testing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b4138ceec8cf0e44e3d00c5dad6d0ecbf51f1f2ce31e5197b75a7f4d82c90d78",
                "md5": "06445947fd65c06231a53f985b9bef90",
                "sha256": "05c0b143540f54d9dd9d0d500b7b146ff29e0c1cd4bb5f2ed99c60842ff1d5e6"
            },
            "downloads": -1,
            "filename": "pydantic_factories-1.17.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "06445947fd65c06231a53f985b9bef90",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 31792,
            "upload_time": "2023-01-15T19:33:18",
            "upload_time_iso_8601": "2023-01-15T19:33:18.476472Z",
            "url": "https://files.pythonhosted.org/packages/b4/13/8ceec8cf0e44e3d00c5dad6d0ecbf51f1f2ce31e5197b75a7f4d82c90d78/pydantic_factories-1.17.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d5b7d894c8ce5501d0381f71237df543abb2a2421d97fa836fb11bcad07768fd",
                "md5": "2434d907a05599238cc76e80f58c99e9",
                "sha256": "85848136cd768894dc5b6e3ffaf49753c7627c545ef05ff096ff616071cd59ff"
            },
            "downloads": -1,
            "filename": "pydantic_factories-1.17.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2434d907a05599238cc76e80f58c99e9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 25696,
            "upload_time": "2023-01-15T19:33:19",
            "upload_time_iso_8601": "2023-01-15T19:33:19.900065Z",
            "url": "https://files.pythonhosted.org/packages/d5/b7/d894c8ce5501d0381f71237df543abb2a2421d97fa836fb11bcad07768fd/pydantic_factories-1.17.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-15 19:33:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "starlite-api",
    "github_project": "pydantic-factories",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pydantic-factories"
}
        
Elapsed time: 0.17172s