Skip to main content

Relaymesh worker SDK

Project description

relaymesh Python Worker SDK

The Python worker SDK mirrors the Go/TypeScript worker interfaces and connects to the relaymesh control plane for rules, drivers, event logs, and SCM credentials.

Install

pip install relaymesh

No additional packages are required.

Quick Start

import signal
import threading

from relaymesh.listener import Listener
from relaymesh.scm_client_provider import NewRemoteSCMClientProvider
from relaymesh.worker import (
    New,
    WithClientProvider,
    WithConcurrency,
    WithEndpoint,
    WithListener,
)

stop = threading.Event()

def shutdown(_signum, _frame):
    stop.set()

signal.signal(signal.SIGINT, shutdown)
signal.signal(signal.SIGTERM, shutdown)

wk = New(
    WithEndpoint("http://localhost:8080"),
    WithClientProvider(NewRemoteSCMClientProvider()),
    WithConcurrency(4),
    WithListener(Listener()),
)

def handle(ctx, evt):
    installation_id = evt.metadata.get("installation_id", "")
    print(f"topic={evt.topic} provider={evt.provider} type={evt.type} installation={installation_id}")
    if evt.payload:
        print(f"payload bytes={len(evt.payload)}")

wk.HandleRule("85101e9f-3bcf-4ed0-b561-750c270ef6c3", handle)

wk.Run(stop)

Handler Signature

Handlers can accept either (event) or (ctx, event):

def handle(evt):
    print(evt.provider, evt.type)

def handle_with_ctx(ctx, evt):
    print(ctx.request_id, evt.topic)

Using SCM Clients (GitHub/GitLab/Bitbucket)

from relaymesh.scm_client_provider import BitbucketClient, GitHubClient, GitLabClient

def handler(ctx, evt):
    provider = (evt.provider or "").lower()
    if provider == "github":
        client = GitHubClient(evt)
    elif provider == "gitlab":
        client = GitLabClient(evt)
    elif provider == "bitbucket":
        client = BitbucketClient(evt)
    else:
        client = None

    if client:
        user = client.request_json("GET", "/user")
        print(user)

Retry, concurrency, and status updates

  • Set retry behavior with WithRetryCount(n).
  • Set in-flight processing with WithConcurrency(n).
  • Use WithListener(...) to log lifecycle callbacks and status outcomes.
  • Worker status updates are automatic: success on clean return, failed on raised exception.

OAuth2 mode

Use mode="client_credentials" for worker OAuth2 token flow.

from relaymesh.oauth2 import OAuth2Config
from relaymesh.worker import WithOAuth2Config

wk = New(
    WithOAuth2Config(
        OAuth2Config(
            enabled=True,
            mode="client_credentials",
            client_id="your-client-id",
            client_secret="your-client-secret",
            token_url="https://issuer.example.com/oauth/token",
            scopes=["relaymesh.read", "relaymesh.write"],
        )
    )
)

Environment Variables

The worker will read defaults from:

  • RELAYMESH_ENDPOINT or RELAYMESH_API_BASE_URL
  • RELAYMESH_API_KEY
  • RELAYMESH_TENANT_ID

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

relaymesh-0.0.20.tar.gz (49.7 kB view details)

Uploaded Source

Built Distribution

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

relaymesh-0.0.20-py3-none-any.whl (53.0 kB view details)

Uploaded Python 3

File details

Details for the file relaymesh-0.0.20.tar.gz.

File metadata

  • Download URL: relaymesh-0.0.20.tar.gz
  • Upload date:
  • Size: 49.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for relaymesh-0.0.20.tar.gz
Algorithm Hash digest
SHA256 d5251618c19127c65c3c71bb90c150b4c0b7b54ce35748c1691eb043db634fcb
MD5 a5b7d25235a0c5a73f94959c9eaa82c2
BLAKE2b-256 7e954a15e8d1cad7913a1dbedc90b69d7a975985bab37a089dce768eadef0f43

See more details on using hashes here.

File details

Details for the file relaymesh-0.0.20-py3-none-any.whl.

File metadata

  • Download URL: relaymesh-0.0.20-py3-none-any.whl
  • Upload date:
  • Size: 53.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for relaymesh-0.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 281457b0c3cab6f57dcee758e36e4c939bf6f0ed9c5810b995e1be633f7518fd
MD5 1a1865ac1e2e6c4c538d13101a8469e7
BLAKE2b-256 268ae91459c2dc1a89e6941e32f3bdba83e5becff221c86edf3c62ba027b56ff

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