Skip to main content

dmesh SDK

Project description

dmesh-sdk

License Python Support

A native asynchronous SDK, provided as a part of dmesh-core for managing open data product and open contract standards. dmesh-sdk provides the core abstractions and persistence layers needed to implement the Open Data Mesh standard.

🚀 Key Features

  • Async First: Built from the ground up for high-performance asynchronous operations using asyncio and psycopg3.
  • Idempotent Operations: Safely publish and update data products and contracts.
  • Validation: Built-in JSON Schema validation for Data Product and Data Contract specifications.
  • Pluggable Architecture: Easily switch between storage backends (In-memory for testing, PostgreSQL for production).
  • Factory-based Initialization: Simplified setup for complex repository configurations.

📦 Installation

pip install dmesh-sdk

🛠️ Quick Start

In-Memory persistency

import asyncio
from dmesh.sdk import AsyncSDK, RepositoryFactory

async def main():
    # Initialize an In-Memory repository for testing
    factory = RepositoryFactory().create(db_type="memory")
    
    # Use the SDK as an asynchronous context manager
    async with AsyncSDK(factory) as sdk:
        # Register a data product (idempotent)
        dp_spec = {
            "domain": "finance",
            "name": "ledger"
        }

        dp = await sdk.put_data_product(dp_spec)
        stored_dp = await sdk.get_data_product(dp['id'])
        print(f"Registered Data Product ID: {stored_dp['id']}")
        print(f"Data Product: {stored_dp}")
        dc_spec = {}
        dc = await sdk.put_data_contract(dc_spec, stored_dp['id'])
        stored_dc = await sdk.get_data_contract(dc['id'])
        print(f"Registered Data Contract ID: {stored_dc['id']}")
        print(f"Data Contract: {stored_dc}")

if __name__ == "__main__":
    asyncio.run(main())    
Registered Data Product ID: ba781283-1f14-5db2-a3f3-ce330da2c6dd
Data Product: {'domain': 'finance', 'name': 'ledger', 'apiVersion': 'v1.0.0', 'kind': 'DataProduct', 'version': 'v1.0.0', 'status': 'draft', 'id': 'ba781283-1f14-5db2-a3f3-ce330da2c6dd'}
Registered Data Contract ID: b9ee4bd2-205d-5eb8-8e13-1f9ee1f6ea26
Data Contract: {'id': 'b9ee4bd2-205d-5eb8-8e13-1f9ee1f6ea26', 'apiVersion': 'v3.1.0', 'kind': 'DataContract', 'version': 'v1.0.0', 'status': 'draft', 'dataProduct': 'ledger', 'domain': 'finance'}

Postgres persistency

To use the PostgreSQL backend, you need a running database.

Option 1: Fast Docker Run (Simplest)

Run a standalone Postgres instance:

docker run --name dmesh-postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres -e POSTGRES_DB=postgres -p 5432:5432 -d postgres:16

Option 2: Docker Compose (Monorepo)

If you have the full dmesh-core repository, you can use the included docker-compose.yml:

docker-compose up -d db

Configuration

Before running the code below, ensure your environment variables are set (either in a .env file or exported in your shell):

DMESH_DB__HOST=localhost
DMESH_DB__PORT=5432
DMESH_DB__USER=postgres
DMESH_DB__PASSWORD=postgres
DMESH_DB__NAME=postgres
import asyncio
import selectors
from dmesh.sdk import AsyncSDK, RepositoryFactory, get_settings

async def main():
    # Load settings from config service
    settings = get_settings()

    # Initialize an In-Memory repository for testing
    factory = RepositoryFactory().create_from_settings(db_type="postgres", settings=settings)
    
    # Use the SDK as an asynchronous context manager
    async with AsyncSDK(factory) as sdk:
        # Register a data product (idempotent)
        dp_spec = {
            "domain": "finance",
            "name": "ledger"
        }

        dp = await sdk.put_data_product(dp_spec)
        stored_dp = await sdk.get_data_product(dp['id'])
        print(f"Registered Data Product ID: {stored_dp['id']}")
        print(f"Data Product: {stored_dp}")
        dc_spec = {}
        dc = await sdk.put_data_contract(dc_spec, stored_dp['id'])
        stored_dc = await sdk.get_data_contract(dc['id'])
        print(f"Registered Data Contract ID: {stored_dc['id']}")
        print(f"Data Contract: {stored_dc}")

if __name__ == "__main__":
    # Ensure correct loop factory for Windows if needed, though run() usually handles it
    asyncio.run(main(), loop_factory=lambda: asyncio.SelectorEventLoop(selectors.SelectSelector()))

📖 Related Projects

  • dmesh-cli: Command-line interface for managing your data mesh.
  • dmesh-api: REST API (FastAPI based) server for data mesh orchestration.
  • dmesh-viewer: Web-based interface for data mesh visualization.

📄 License

This project is licensed under the Apache 2.0 License. See the LICENSE file for details.

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

dmesh_sdk-0.1.0.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

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

dmesh_sdk-0.1.0-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file dmesh_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: dmesh_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dmesh_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 83e5f6c93a3873d06788c2f71a9c66f5f44a795b919751893f0ae311ca68178c
MD5 3cac4e2f779acc8b5be2ded9965e71c1
BLAKE2b-256 9cab03a3c908141cef5912dbc424fe736dde44c828c03de56dfdd5179c57a323

See more details on using hashes here.

File details

Details for the file dmesh_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dmesh_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dmesh_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f7db584a02d444856f7ccbd9a59a8bb2e78e68d1eb5b4e7aea8dd860ef4205f4
MD5 7021c5a24a34aa139e6f59b42bf45d6e
BLAKE2b-256 3f9f77ab5c6a05f9e825b8f4c0a21cc5cc7bedf3151cd9bd9e4d8091aa2536e2

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