Skip to main content

A pydantic schema manager

Project description

pulse-schemas

A Python package for managing user profile schemas using Pydantic.

Features

  • Schema registry to store and retrieve Pydantic models
  • Easily extensible for custom schemas

Installation

pip install pulse-schemas

Usage

This project includes a schema manager (SchemaRegistry) that makes it easy to register, retrieve, and validate Pydantic schemas. A default schema for creating a user profile is already included.

Import the registry

from pulse_schemas.schema import SchemaRegistry

Initialize the registry

registry = SchemaRegistry()

When initialized, the registry automatically registers the built-in schema create_user_profile.

List available schemas

print(registry.list_schemas())
# ['create_user_profile']

Retrieve a schema

ProfileSchema = registry.get_schema("create_user_profile")

Validate data against a schema

data = {
    "demographics": {"age": 28, "biological_sex": "female"},
    "dietary_preferences": ["vegetarian"],
    "allergens": ["peanuts", "milk"],
    "health_conditions": ["hypertension"],
    "goals": ["improve cardio"]
}

profile = ProfileSchema.model_validate(data)
print(profile)

If the data is invalid, Pydantic will raise a ValidationError.

Register custom schemas

You can register new schemas at runtime:

from pydantic import BaseModel

class CustomSchema(BaseModel):
    name: str
    active: bool

registry.register_schema("custom_schema", CustomSchema)
print(registry.list_schemas())
# ['create_user_profile', 'custom_schema']

Now you can retrieve and validate against custom_schema in the same way.

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

pulse_schemas-0.2.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pulse_schemas-0.2.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file pulse_schemas-0.2.0.tar.gz.

File metadata

  • Download URL: pulse_schemas-0.2.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for pulse_schemas-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b618db7bf3d6a010797d41aa98fe3b20edfa3a5f4708c6dc8cb3b42d022d92b3
MD5 0f90b0c06cacfceae02136070b7b3e11
BLAKE2b-256 36f56867df25bac1a85ba32433c899e40dc98f0b0ef9939e7725a52bbc85c4b6

See more details on using hashes here.

File details

Details for the file pulse_schemas-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pulse_schemas-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for pulse_schemas-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c27dc1723b5159c35a487d2c0869fca0033e161016a6714661cdfd0d07c2f68
MD5 c9e71f1df32383a29b03b1221333b5ed
BLAKE2b-256 1ddccd0a19a0c176f1ea3b9dbddd973ce6450002b502f33cfda2a5303ec8fca0

See more details on using hashes here.

Supported by

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