Messaging utilities for dojo applications
Project description
Dojo Messaging
why?
-
enables us to use higher compression ratio algorithms like zstandard
-
uses aiohttp under the hood for client-side, and fastapi for server side
-
uses AsyncRetrying from tenacity, and asyncio.BoundedSemaphore by default for controlling batching & concurrency
-
fully typed, so you can simply access your Synapse's fields directly from
response.body -
dedicated function for batch sending to target URLs
-
explicitly raise HTTPExceptions in code where server logic will propagate to client
-
decoupling traditional HTTP status codes from protocol level status codes (e.g. blacklisted requests return "200 OK" but with an "error" message field)
-
server (typically miner)
- must call serve_synapse with both
async def handler(fastapi.Request, pydantic.BaseModel) - must initialise
- must call serve_synapse with both
-
client (typically validator)
Example Usage
from http import HTTPStatus
from aiohttp import ClientSession, TCPConnector
from pydantic import BaseModel, Field
from typing import Any
from dojo_messaging import Client
# retry logic handled under the hood
class ExampleModel(BaseModel):
field: bool = Field(default=False, description="Example field")
async def main():
# provide a session is optional, or use the convenience function
client = Client(
hotkey="your hotkey", # used for signing and verification,
session=ClientSession(
connector=TCPConnector(
limit=100
) # specify your own session, connector, etc. as needed
),
)
example_model = ExampleModel()
# any other kwargs may be propagated to the underlying POST request using aiohttp
kwargs: dict[str, Any] = {}
response = await client.send(
"http://ip:port",
model=example_model,
timeout_sec=12,
max_retries=10,
max_wait_sec=100,
**kwargs,
)
# check for errors
if response.error:
# check for response.error that comes from server side
print(f"Error received from server: {response.error}")
if response.exception:
# check for response.exception that comes from client side
print(f"Exception occurred {response.exception}")
if response.client_response and response.client_response.status != HTTPStatus.OK:
# access fields from ExampleModel directly
print(f"Received {response.body.field=}")
# dedicated batch_send method
# use an asyncio semaphore for concurrency & batch control
# if semaphore isn't provided, asyncio.gather is called
responses = await client.batch_send(
urls=["http://ip:port"] * 5, models=[ExampleModel()] * 5
)
for response in responses:
# access fields as needed...
# check for errors
if response.error:
# check for response.error that comes from server side
print(f"Error received from server: {response.error}")
if response.exception:
# check for response.exception that comes from client side
print(f"Exception occurred {response.exception}")
if (
response.client_response
and response.client_response.status != HTTPStatus.OK
):
# access fields from ExampleModel directly
print(f"Received {response.body.field=}")
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 dojo_messaging-1.0.14.tar.gz.
File metadata
- Download URL: dojo_messaging-1.0.14.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0838ead1c7874044274084a6449e35a511dca1205c28c387c9809e9c56834fc1
|
|
| MD5 |
bfd46aa32ed3c924e25b996e4bfa2d8a
|
|
| BLAKE2b-256 |
0592d386f461c7f30b218c7709738428264de13faf1c7dc7508dff4fed37a2f6
|
Provenance
The following attestation bundles were made for dojo_messaging-1.0.14.tar.gz:
Publisher:
release.yml on tensorplex-labs/dojo-messaging
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dojo_messaging-1.0.14.tar.gz -
Subject digest:
0838ead1c7874044274084a6449e35a511dca1205c28c387c9809e9c56834fc1 - Sigstore transparency entry: 239991444
- Sigstore integration time:
-
Permalink:
tensorplex-labs/dojo-messaging@4d2d4b3611fd7b5a746ef855a48b93661f0c5d3b -
Branch / Tag:
refs/heads/staging - Owner: https://github.com/tensorplex-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4d2d4b3611fd7b5a746ef855a48b93661f0c5d3b -
Trigger Event:
push
-
Statement type:
File details
Details for the file dojo_messaging-1.0.14-py3-none-any.whl.
File metadata
- Download URL: dojo_messaging-1.0.14-py3-none-any.whl
- Upload date:
- Size: 15.1 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 |
f216873fb5ffcf90374975890f907b624fa320ffc4eb99b6b19253577632bd8f
|
|
| MD5 |
721bf590320a8d6dc50ab4f8e80116fd
|
|
| BLAKE2b-256 |
45f9854fee7629a395470cc27cdf3122115a1fe313315eea3278a864c4612526
|
Provenance
The following attestation bundles were made for dojo_messaging-1.0.14-py3-none-any.whl:
Publisher:
release.yml on tensorplex-labs/dojo-messaging
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dojo_messaging-1.0.14-py3-none-any.whl -
Subject digest:
f216873fb5ffcf90374975890f907b624fa320ffc4eb99b6b19253577632bd8f - Sigstore transparency entry: 239991462
- Sigstore integration time:
-
Permalink:
tensorplex-labs/dojo-messaging@4d2d4b3611fd7b5a746ef855a48b93661f0c5d3b -
Branch / Tag:
refs/heads/staging - Owner: https://github.com/tensorplex-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4d2d4b3611fd7b5a746ef855a48b93661f0c5d3b -
Trigger Event:
push
-
Statement type: