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.1.1.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.1.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pulse_schemas-0.1.1.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.1.1.tar.gz
Algorithm Hash digest
SHA256 2cc6bc1c9eed097feba2ade2d8e4e2626ad92bbe985f0dd85188e013a4b27308
MD5 64baee19e989634e0968b682b445d039
BLAKE2b-256 fed5065184116eec006a8d160d1add26d0828648084721fcba4517d2755212dc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pulse_schemas-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9202095f8f2159899b77b31cb69905e3c25b295704431d2c1209e0739053821f
MD5 5523c8fbb0620a80eb1591fdf1a6249a
BLAKE2b-256 9f71fcbd98359d6eb2fa997dea4e275e65a765eeabc90ed2060947260367c389

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