Skip to main content

ReJot contracts for Python

Project description

ReJot Python Contracts

This directory contains the Python variant for defining and working with ReJot public and consumer schemas. It is intended for use in projects that need to define data contracts and transformations for use with the ReJot platform. For the latest documentation, see the ReJot Python Contracts.

Features

  • Define public schemas for data publication (e.g., from a Postgres table)
  • Define consumer schemas for data consumption and transformation
  • Pydantic-based schema definitions for type safety
  • Simple API for schema creation and validation

Installation

Requires Python 3.9 or higher.

pip install rejot-contract

Usage

from pydantic import BaseModel
from rejot_contract.public_schema import (
    create_public_schema, PublicSchemaConfig, PostgresPublicSchemaConfigTransformation, Source, Version, create_postgres_public_schema_transformation
)
from rejot_contract.consumer_schema import (
    create_consumer_schema, ConsumerSchemaConfig, SourceManifest, PublicSchema
)

class Account(BaseModel):
    id: int
    email: str
    name: str

# Use the helper to create transformations for insertOrUpdate
transformations = create_postgres_public_schema_transformation(
    operation="insertOrUpdate",
    table="account",
    sql="SELECT id, email, name FROM account WHERE id = :id",
)

# Define a public schema
public = create_public_schema(
    public_schema_name="public-account",
    source=Source(dataStoreSlug="default-postgres"),
    output_schema=Account, # Or a JSON schema dict
    version=Version(major=1, minor=0),
    config=PublicSchemaConfig(
        publicSchemaType="postgres",
        transformations=transformations,
    ),
)

# Define a consumer schema
consumer = create_consumer_schema(
    "consume-public-account",
    source=SourceManifest(
        manifestSlug="@rejot/",
        publicSchema=PublicSchema(
            name="public-account",
            majorVersion=1,
        ),
    ),
    config=ConsumerSchemaConfig(
        consumerSchemaType="postgres",
        destinationDataStoreSlug="default-postgres",
        sql="INSERT INTO users_destination (id, full_name) VALUES (:id, :email || ' ' || :name) ON CONFLICT (id) DO UPDATE SET full_name = :email || ' ' || :name",
        deleteSql="DELETE FROM users_destination WHERE id = :id",
    ),
)

API Reference

Public Schema

  • create_public_schema(...) — Create a public schema definition
  • create_postgres_public_schema_transformation(...) — Helper to generate transformation steps for common Postgres operations
  • PublicSchemaConfig — Configuration for public schema (type, transformations)
  • PostgresPublicSchemaConfigTransformation — Transformation step for Postgres
  • Source — Source data store slug
  • Version — Schema version

Consumer Schema

  • create_consumer_schema(...) — Create a consumer schema definition
  • ConsumerSchemaConfig — Configuration for consumer schema (type, destination, SQL)
  • SourceManifest — Reference to a public schema in a manifest
  • PublicSchema — Reference to a public schema

create_postgres_public_schema_transformation

Helper to generate transformation steps for common Postgres operations.

Signature:

def create_postgres_public_schema_transformation(
    operation: Literal["insertOrUpdate", "delete"],
    table: str,
    sql: str
) -> List[PostgresPublicSchemaConfigTransformation]
  • For insertOrUpdate, returns both insert and update transformations.
  • For delete, returns a delete transformation.
  • Raises ValueError for invalid operations.

Example:

transformations = create_postgres_public_schema_transformation(
    operation="insertOrUpdate",
    table="account",
    sql="SELECT id, email, name FROM account WHERE id = :id",
)

Project Structure

  • src/rejot_contract/public_schema.py — Public schema definitions and helpers
  • src/rejot_contract/consumer_schema.py — Consumer schema definitions and helpers

License

Apache 2.0 — see LICENSE

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

rejot_contract-0.2.1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

rejot_contract-0.2.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file rejot_contract-0.2.1.tar.gz.

File metadata

  • Download URL: rejot_contract-0.2.1.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rejot_contract-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a743dc941de9563c570945f60d510bd3011cc41204de8458e57ce342a94eaeef
MD5 4ad5a87d1365f74ca0d648d0a4bfb4d2
BLAKE2b-256 3c02317b3a9631715613bfd8a211baa567193b8f8ef697305b007668414ec580

See more details on using hashes here.

Provenance

The following attestation bundles were made for rejot_contract-0.2.1.tar.gz:

Publisher: python.yml on rejot-dev/rejot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rejot_contract-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: rejot_contract-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rejot_contract-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d5888d302cbddd3c493997b6e60f736095e7a613865cfdf9c107f37a8a895222
MD5 d0e6926b1408622f20f7334bc265e935
BLAKE2b-256 eab8d543cdb865f8915c7fdd622b9cdd8058735f6cb2d5d05d94fa74ef090a5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for rejot_contract-0.2.1-py3-none-any.whl:

Publisher: python.yml on rejot-dev/rejot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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