Skip to main content

A powerfull and flexible framework for designing async socket based data streaming and distribution systems, with automated parsing, dynamic data store and high-level control hooks.

Project description

data-place

A powerful and flexible framework for designing async socket based data streaming and distribution systems, with automated parsing, dynamic data store and high-level control hooks.

Installation

pip install data-place

example

  • integrates with dataclasses and pydantic as a side effect

websocket publisher server

import asyncio
import random
from uuid import uuid4
from dataclasses import dataclass

from dataplace import (
    ModelIO, SenderWebSocketServer, Controller, Callback, SpaceStore
)


@dataclass(slots=True, frozen=True)
class Data(ModelIO):
    id: str
    value: int


async def produce(controller: Controller) -> None:
    while controller.running:
        while controller.paused:
            await asyncio.sleep(0.0001)

        data = Data(id=str(uuid4()), value=random.randint(0, 9))

        print(f"produced: {data}")

        await controller.async_callback(data)

        await asyncio.sleep(1)


store = SpaceStore[int, Data](item=Data, signature=lambda data: data.value)

server = SenderWebSocketServer(host="127.0.0.1", port=5555)

controller = Controller(
    callbacks=[
        Callback(async_callback=lambda data: store.add),
        Callback(async_callback=server.call)
    ]
)

loop = asyncio.new_event_loop()

loop.create_task(produce(controller))
loop.create_task(server.start())
loop.run_forever()

websocket subscriber client

import asyncio
from dataclasses import dataclass

from dataplace import (
    ModelIO, ReceiverWebSocketClient, Callback, SpaceStore
)

@dataclass(slots=True, frozen=True)
class Data(ModelIO):

    value: int
    id: str

store = SpaceStore[int, Data](signature=lambda data: data.value)

client = ReceiverWebSocketClient(
    url="ws://127.0.0.1:5555",
    callbacks=[
        Callback(async_callback=lambda data: store.add(data)),
        Callback(async_callback=lambda data: print(f"received: {data}"))
    ]
)

loop = asyncio.new_event_loop()

loop.create_task(client.start())
loop.run_forever()

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

data-place-0.0.7.tar.gz (12.0 kB view details)

Uploaded Source

File details

Details for the file data-place-0.0.7.tar.gz.

File metadata

  • Download URL: data-place-0.0.7.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for data-place-0.0.7.tar.gz
Algorithm Hash digest
SHA256 f64dd9c32c66634cdc857238ed92180f39ea4486a3d2a5c7123f1b850098d726
MD5 f4e7d49d2d5cd252d5150ea7e7bc0752
BLAKE2b-256 ca878a7eee305d0b6a1064f75bb77f7469d2213ebc0176be14e10fe94f132535

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page