Skip to main content

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

Metadata

Release files for schemey 8.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for schemey 8.0.1
File Size Uploaded
schemey-8.0.1.tar.gz 55.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for schemey 8.0.1
File Interpreter ABI Platform
schemey-8.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 75.3 kB

Release files / schemey-8.0.1.tar.gz

Download URL schemey-8.0.1.tar.gz
Size 55.0 kB
Tags Source
SHA-256 checksum
How to use checksums
73596e35cc6057a079ecf9f406cebcdea0d326692018e5f3516e71924a9a9cde
BLAKE2b-256 checksum
How to use checksums
89859e456345c28db0d58e9525f9bd958f0c370e2d0f35fb860770c2e2a27951
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / schemey-8.0.1-py3-none-any.whl

Download URL schemey-8.0.1-py3-none-any.whl
Size 20.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31e4b9d28cee51257863da35b382e23db019ceebc6661c40ee2aebb4c9c47e1a
BLAKE2b-256 checksum
How to use checksums
7275ef721337f5802085277d382383a1a2434053639c33be1d6c3f274a49e0ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

8.0.1 This release

2 release files

8.0.0

2 release files

7.0.2

2 release files

7.0.1

2 release files

7.0.0

2 release files

6.0.3

2 release files

6.0.2

2 release files

6.0.1

2 release files

6.0.0

2 release files

5.7.0

2 release files

5.6.0

2 release files

5.5.0

2 release files

5.4.3

2 release files

5.4.2

2 release files

5.4.1

2 release files

5.4.0

2 release files

5.3.0

2 release files

5.2.0

2 release files

5.1.1

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.4.0

2 release files

4.3.0

2 release files

4.2.0

2 release files

4.0.0

2 release files

3.5.0

2 release files

3.4.1

2 release files

3.4.0

2 release files

3.3.4

2 release files

3.3.3

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page