Skip to main content

an implementation of JSON:api using pydantic

Project description

pydantic-jsonapi

Build Status PyPi Link

an implementation of JSON:api using pydantic for validation

from pydantic_jsonapi import JsonApiModel
from pydantic import BaseModel

class Item(BaseModel):
    name: str
    quantity: int
    price: float

ItemRequest, ItemResponse = JsonApiModel('item', Item)

# request validation
request = {
    'data': {
        'type': 'item',
        'attributes': {
            'name': 'apple',
            'quantity': 10,
            'price': 1.20,
        },
    }
}
ItemRequest(**request)

#response validation
response = {
    'data': {
        'id': 'abc123',
        'type': 'item',
        'attributes': {
            'name': 'apple',
            'quantity': 10,
            'price': 1.20,
        },
        'relationships': {
            'store': {
                'links': {
                    'related': '/stores/123'
                }
            }
        }
    },
    'links': {
        'self': '/item/abc123'
    }
}
ItemResponse(**response)

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_jsonapi-0.11.0.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file pydantic_jsonapi-0.11.0.tar.gz.

File metadata

  • Download URL: pydantic_jsonapi-0.11.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.1

File hashes

Hashes for pydantic_jsonapi-0.11.0.tar.gz
Algorithm Hash digest
SHA256 c0c72d7543017121e49a41ee7e36224ba1cc3627be5efac048e3b81425e623a8
MD5 a0c513ad5be44551c2e430ea25163976
BLAKE2b-256 0c08688ff0a722796c7671576cc6c1936f64302f5d20356631947dcd7b88b141

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