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 definitioncreate_postgres_public_schema_transformation(...)
— Helper to generate transformation steps for common Postgres operationsPublicSchemaConfig
— Configuration for public schema (type, transformations)PostgresPublicSchemaConfigTransformation
— Transformation step for PostgresSource
— Source data store slugVersion
— Schema version
Consumer Schema
create_consumer_schema(...)
— Create a consumer schema definitionConsumerSchemaConfig
— Configuration for consumer schema (type, destination, SQL)SourceManifest
— Reference to a public schema in a manifestPublicSchema
— 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 helperssrc/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
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 |
a743dc941de9563c570945f60d510bd3011cc41204de8458e57ce342a94eaeef
|
|
MD5 |
4ad5a87d1365f74ca0d648d0a4bfb4d2
|
|
BLAKE2b-256 |
3c02317b3a9631715613bfd8a211baa567193b8f8ef697305b007668414ec580
|
Provenance
The following attestation bundles were made for rejot_contract-0.2.1.tar.gz
:
Publisher:
python.yml
on rejot-dev/rejot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
rejot_contract-0.2.1.tar.gz
-
Subject digest:
a743dc941de9563c570945f60d510bd3011cc41204de8458e57ce342a94eaeef
- Sigstore transparency entry: 235052893
- Sigstore integration time:
-
Permalink:
rejot-dev/rejot@0e5153fc8066fe7f55207f4d1ca537a974042606
-
Branch / Tag:
refs/tags/v0.2.1
- Owner: https://github.com/rejot-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
python.yml@0e5153fc8066fe7f55207f4d1ca537a974042606
-
Trigger Event:
push
-
Statement type:
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
Algorithm | Hash digest | |
---|---|---|
SHA256 |
d5888d302cbddd3c493997b6e60f736095e7a613865cfdf9c107f37a8a895222
|
|
MD5 |
d0e6926b1408622f20f7334bc265e935
|
|
BLAKE2b-256 |
eab8d543cdb865f8915c7fdd622b9cdd8058735f6cb2d5d05d94fa74ef090a5d
|
Provenance
The following attestation bundles were made for rejot_contract-0.2.1-py3-none-any.whl
:
Publisher:
python.yml
on rejot-dev/rejot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
rejot_contract-0.2.1-py3-none-any.whl
-
Subject digest:
d5888d302cbddd3c493997b6e60f736095e7a613865cfdf9c107f37a8a895222
- Sigstore transparency entry: 235052894
- Sigstore integration time:
-
Permalink:
rejot-dev/rejot@0e5153fc8066fe7f55207f4d1ca537a974042606
-
Branch / Tag:
refs/tags/v0.2.1
- Owner: https://github.com/rejot-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
python.yml@0e5153fc8066fe7f55207f4d1ca537a974042606
-
Trigger Event:
push
-
Statement type: