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_ENDPOINTorRELAYMESH_API_BASE_URLRELAYMESH_API_KEYRELAYMESH_TENANT_ID
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file relaymesh-0.0.21.tar.gz.
File metadata
- Download URL: relaymesh-0.0.21.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e415d895f5e765ade5fcc1b5e52dff307ba5a4374008a0bd37666d2b8f3da6a4
|
|
| MD5 |
2b0385ad0859eed7a657810dc2e0bad0
|
|
| BLAKE2b-256 |
4713bf16a61caecb604b36988727548d48ad1dac1b6da9b4a116ddc2620bba35
|
File details
Details for the file relaymesh-0.0.21-py3-none-any.whl.
File metadata
- Download URL: relaymesh-0.0.21-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d253e46ab80087e028e4538114d0a19d059bf4e26129d5d2a7ab68d2c8cd98c4
|
|
| MD5 |
c2efa6f42491ebf4e87ec4f052d687b0
|
|
| BLAKE2b-256 |
dd5dae2c64b9463062299d0400a64466e03ab38c7834fa26373ec2b0aab89472
|