Skip to main content

Convention over configuration Object Schemas for python

Project description

Schemey - Json Schemas for Python.

This project allows for generation of json schemas based on python classes, or python classes based on json schemas. It also allows for generation of validated dataclasses, where setters cannot violate the invariants established in a schema.

It uses the fantastic JSON Schema library for python. (Though older versions did not.)

The general idea is that the framework should not insist on any particular data structure or paradigm - it is designed to be extensible, and out of the box support is provided for iterable types, dataclasses, enums, timestamps and primitives.

Serialization is provided using marshy.

Current test coverage is at 100%

Why did you build this?

There were gaps in the functionality of existing solutions (Like pydantic) that made using them untenable for my use cases.

Installation

pip install schemey

Concepts

  • A Schema contains a link between a JSON Schema and a Python Type
  • A Validator is used to validate python objects using a schema
  • A SchemaContext is used to generate python objects for json schemas / vice versa
  • A SchemaFactory is used to plug new translation rules into a SchemaContext (more below)

Examples

Hello World

This demonstrates generating a validator for a dataclass.

Validated Dataclass

This demonstrates generating a validated dataclass

Validated Fields

This demonstrates adding custom validation rules to dataclass fields

Custom Class Validations

This demonstrates adding fully custom marshalling and validations for a class

Custom JSON Schema Validations

This demonstrates creating custom json schema validations for things not natively supported by json schema. For example, checking a date against the current time, or that a property of an object is less than another property of that object.

Beginning with a JSON Schema

This demonstrates starting with a json schema and generating python dataclasses from it.

Configuring the Context itself

Schemey uses Injecty for configuration. The default configuration is here

For example, for a project named no_more_uuids, I may add a file injecty_config_no_more_uuids/__init__.py:

from schemey.factory.schema_factory_abc import SchemaFactoryABC
from schemey.factory.uuid_factory import UuidFactory

priority = 120  # Applied after default


def configure(context):
    context.deregister_impl(SchemaFactoryABC, UuidFactory)

Installing local development dependencies

python setup.py install easy_install "schemey[dev]"

Release Procedure

status

The typical process here is:

  • Create a PR with changes. Merge these to main (The Quality workflows make sure that your PR meets the styling, linting, and code coverage standards).
  • New releases created in github are automatically uploaded to pypi

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

schemey-7.0.2.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

schemey-7.0.2-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file schemey-7.0.2.tar.gz.

File metadata

  • Download URL: schemey-7.0.2.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for schemey-7.0.2.tar.gz
Algorithm Hash digest
SHA256 41bb897f7113adb54d11d4e081bd5ca517dcce5d06c6884fab15f2f86f32b273
MD5 fb4fff83850d5563cb31043f9d7502d7
BLAKE2b-256 2279799d8fa486083906bc2f85a2da1031c2caac22c598dffb23049d3609ce6b

See more details on using hashes here.

File details

Details for the file schemey-7.0.2-py3-none-any.whl.

File metadata

  • Download URL: schemey-7.0.2-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for schemey-7.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dbd6fbdc3bc8c9a075032d51199f2c4b98e9440e4f3d0843244efa8b9f7304ca
MD5 3727160d4b427c1c525a4575997fb312
BLAKE2b-256 a25e3be3dfd31df3738a2164b2ce3249d64e1746f949f57cc65d72d5c1fa275b

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