Skip to main content

It just provide a pair of pre & post methods around pydantic fields, the rest is up to your imagination

Project description

pypi Downloads Python Versions CI

Pydantic-resolve is a schema based solution for data management.

  1. manage the deep data inside it's schema, instead of visiting if outside by manual traversal.
  2. pydantic-resolve runs a Level Order Traversal (BFS) inside and execute resolve and post during this process.
  3. describe the relationship between data in a way close to ERD (entity relationship diagram)

Install

User of pydantic v2, please use pydantic2-resolve instead.

This lib now supports both pydantic v1 and v2 starts from v1.11.0

pip install pydantic-resolve

Hello world

manage your data inside the schema.

class Tree(BaseModel):
    name: str
    number: int
    description: str = ''
    def resolve_description(self):
        return f"I'm {self.name}, my number is {self.number}"
    children: list['Tree'] = []


tree = dict(
    name='root',
    number=1,
    children=[
        dict(
            name='child1',
            number=2,
            children=[
                dict(
                    name='child1-1',
                    number=3,
                ),
                dict(
                    name='child1-2',
                    number=4,
                ),
            ]
        )
    ]
)

async def main():
    t = Tree.parse_obj(tree)
    t = await Resolver().resolve(t)
    print(t.json(indent=4))

import asyncio
asyncio.run(main())

output

{
  "name": "root",
  "number": 1,
  "description": "I'm root, my number is 1",
  "children": [
    {
      "name": "child1",
      "number": 2,
      "description": "I'm child1, my number is 2",
      "children": [
        {
          "name": "child1-1",
          "number": 3,
          "description": "I'm child1-1, my number is 3",
          "children": []
        },
        {
          "name": "child1-2",
          "number": 4,
          "description": "I'm child1-2, my number is 4",
          "children": []
        }
      ]
    }
  ]
}

Documents

Test and coverage

tox
tox -e coverage
python -m http.server

latest coverage: 98%

Sponsor

If this code helps and you wish to support me

Paypal: https://www.paypal.me/tangkikodo

Discussion

Discord

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

pydantic_resolve-1.11.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

pydantic_resolve-1.11.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_resolve-1.11.0.tar.gz.

File metadata

  • Download URL: pydantic_resolve-1.11.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.4 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for pydantic_resolve-1.11.0.tar.gz
Algorithm Hash digest
SHA256 e9907393048e7df60d943130e29248395495629b9b1f4cd14798ac61bf28e2c8
MD5 997ab56b15d8c9aa354f1b15174d0595
BLAKE2b-256 9186062fa902b909914c5a1695f059326d24cf5a97b9f3e9bd99053a8565a891

See more details on using hashes here.

File details

Details for the file pydantic_resolve-1.11.0-py3-none-any.whl.

File metadata

  • Download URL: pydantic_resolve-1.11.0-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.4 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for pydantic_resolve-1.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b4b24d63e3d573156dd3326508db447d91aa309e356aacc7fe21aaa24b40b9f
MD5 664b7104bd25e30a41f65e4897fded08
BLAKE2b-256 1dcffd4bcf90041148ded0d36ff82397de5b724748b9ed59dbd43af1d6bcc6db

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page