Skip to main content

A small mesh package for Fastapi

Project description

Mesh - A Distributed Data Structure

Mesh - Distributed Data Structure for FastAPI Servers


Usage

from meshd.node import Node

app = FastAPI()
node = Node(
    name=NAME, # Assign a name to this server
    app=app,   # The Fastapi application to hook into
    action_on_conflict="merge" # Default action for conflict management
)

...

# To join to a cluster
await node.join([url])   # Add the joining url
await node.sync_up()     # Sync up the data
await asyncio.sleep(...) # Wait a few seconds for the sync up to finish

...

# Fetch current data
internal_data = node.data.to_dict()

Example Code

import socket
import asyncio
import contextlib

from fastapi import FastAPI
from meshd.node import Node

NAME = socket.gethostname()

@contextlib.asynccontextmanager
async def lifespan(app: FastAPI):
    # Startup
    # Put some data during startup
    await node.put_data({f"__node_{NAME.lower()}__": {"name": NAME, ...}})

    yield

    # Shutdown
    # Remove the data during shutdown
    await node.pop_data(f"__node_{NAME}__")
    await node.sync_up()
    await asyncio.sleep(SLEEP)


app = FastAPI(title=f"Test Server {NAME}", lifespan=lifespan)
node = Node(name=NAME, app=app, action_on_conflict="merge")


@app.get("/")
async def root():
    internal_data = node.data.to_dict()
    return {"name": NAME, "status": "running", "internal_data": internal_data}


@app.get("/join")
async def join(url: str):
    await node.join([url])
    await node.sync_up()
    await asyncio.sleep(SLEEP)

    internal_data = node.data.to_dict()
    return {"name": NAME, "status": "running", "internal_data": internal_data}

Local Dev Installation

$ /usr/bin/env /usr/bin/python3 -m pip install --break-system-packages -e .

Example Simulation

$ docker compose up

Roadmap

  • Basic Mesh communication
  • Packaging as a python package
  • Documenting the basic usage code
  • Hosting the documentation to be visible
  • Adding callbacks to data change
  • Video illustration of the state synchronization
  • Adding auto-instrumentation
  • Adding more examples

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

meshd-2026.0.1.tar.gz (34.2 kB view details)

Uploaded Source

Built Distribution

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

meshd-2026.0.1-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file meshd-2026.0.1.tar.gz.

File metadata

  • Download URL: meshd-2026.0.1.tar.gz
  • Upload date:
  • Size: 34.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for meshd-2026.0.1.tar.gz
Algorithm Hash digest
SHA256 efea0e4451f00c6a0bfbac934ae3f55388bcdffc2981e90ded96e88bee9e1fd1
MD5 63ba53ffcc6512d66b233e7fe5da4b8a
BLAKE2b-256 c58c8d6aea696853df30ad2e360a17f695ea18cc5e1b8cdac224767cd9610a57

See more details on using hashes here.

Provenance

The following attestation bundles were made for meshd-2026.0.1.tar.gz:

Publisher: python-publish.yml on arnavdas88/mesh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file meshd-2026.0.1-py3-none-any.whl.

File metadata

  • Download URL: meshd-2026.0.1-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for meshd-2026.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 83ea300905afee94d3969361a7d06a575a03126e77e5375c0bf99651fa56344e
MD5 4c9fb3d6eb863153cd26f984df5e4bbc
BLAKE2b-256 0de1068ca4781185153858d1bef03ca0da4ae827fdbd33b409a92cd475bcfb95

See more details on using hashes here.

Provenance

The following attestation bundles were made for meshd-2026.0.1-py3-none-any.whl:

Publisher: python-publish.yml on arnavdas88/mesh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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