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.2.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.2-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: meshd-2026.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 893708b23eaf591c204585f04ccacc6e1156d564a816f11cc095a85201e1fd68
MD5 06a0730a1ee52d93c02ab5b055c283e2
BLAKE2b-256 e673640136f2949e2e026d7dc1155bb219e7f8bac9a69b117a490a1ef61a7573

See more details on using hashes here.

Provenance

The following attestation bundles were made for meshd-2026.0.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: meshd-2026.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7f89ae1d9a520c591850ae4b3c2c35f3fa742ff540b14e9feaf5d62edb00f9ee
MD5 8e221ae313ff08e99f575ca57c6362ab
BLAKE2b-256 cb745c595c90d4a236a7a2af5560cb0cbb6795b0347c8fdd9bd3efea21498b37

See more details on using hashes here.

Provenance

The following attestation bundles were made for meshd-2026.0.2-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