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

A definition of a data model. Can be either shared globally or reimplemented separately. Also defines an async loop function that will be used to produce Data objects.

from dataclasses import dataclass
import asyncio
import random
from uuid import uuid4
from dataplace import ModelIO, Controller


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


async def produce(controller: Controller) -> None:
    while controller.running:
        await controller.async_hold()
        await controller.async_callback(
            Data(id=str(uuid4()), value=random.randint(0, 9))
        )

        await asyncio.sleep(1)

async socket based data sending server

import asyncio
from dataplace import Sender, Controller, Callback, SpaceStore

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

server = Sender.Socket.Server(host="127.0.0.1", port=5555)

controller = Controller(
    callbacks=[
        Callback(store.add, types={Data}),
        Callback(server.call, types={Data}),
        Callback(print, types={Data})
    ]
)

loop = asyncio.new_event_loop()
loop.create_task(produce(controller))
loop.create_task(server.start())
loop.run_forever()

async socket based data receiving client

import asyncio
from dataplace import Receiver, Callback, SpaceStore

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

client = Receiver.Socket.Client(
    host="127.0.0.1",
    port=5555,
    callbacks=[
        Callback(store.add, types={Data}),
        Callback(print, types={Data})
    ]
)

loop = asyncio.new_event_loop()
loop.create_task(client.start())
loop.run_forever()

async websocket based data sending server

import asyncio
from dataplace import Sender, Controller, Callback, SpaceStore

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

server = Sender.WebSocket.Server(host="127.0.0.1", port=5555)

controller = Controller(
    callbacks=[
        Callback(store.add, types={Data}),
        Callback(server.call, types={Data}),
        Callback(print, types={Data})
    ]
)

loop = asyncio.new_event_loop()
loop.create_task(produce(controller))
loop.create_task(server.start())
loop.run_forever()

async websocket based data receiving client

import asyncio
from dataplace import Receiver, Callback, SpaceStore

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

client = Receiver.WebSocket.Client(
    url="ws://127.0.0.1:5555",
    callbacks=[
        Callback(store.add, types={Data}),
        Callback(print, types={Data})
    ]
)

loop = asyncio.new_event_loop()
loop.create_task(client.start())
loop.run_forever()

async socket based data receiving server

import asyncio
from dataplace import Receiver, Callback, SpaceStore

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

server = Receiver.Socket.Server(
    host="127.0.0.1",
    port=5555,
    callbacks=[
        Callback(store.add, types={Data}),
        Callback(print, types={Data})
    ]
)

loop = asyncio.new_event_loop()
loop.create_task(server.start())
loop.run_forever()

async socket based data sending client

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

client = Sender.Socket.Client(host="127.0.0.1", port=5555)

controller = Controller(
    callbacks=[
        Callback(store.add, types={Data}),
        Callback(client.call, types={Data}),
        Callback(print, types={Data})
    ]
)

loop = asyncio.new_event_loop()
loop.run_until_complete(client.start())
loop.create_task(produce(controller))
loop.run_forever()

async websocket based data receiving server

import asyncio
from dataplace import Receiver, Callback, SpaceStore

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

server = Receiver.WebSocket.Server(
    host="127.0.0.1",
    port=5555,
    callbacks=[
        Callback(store.add, types={Data}),
        Callback(print, types={Data})
    ]
)

loop = asyncio.new_event_loop()
loop.create_task(server.start())
loop.run_forever()

async websocket based data sending client

import asyncio
from dataplace import Sender, Callback, SpaceStore

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

client = Sender.WebSocket.Client(url="ws://127.0.0.1:5555")

controller = Controller(
    callbacks=[
        Callback(store.add, types={Data}),
        Callback(client.call, types={Data}),
        Callback(print, types={Data})
    ]
)

loop = asyncio.new_event_loop()
loop.run_until_complete(client.start())
loop.create_task(produce(controller))
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.2.5.tar.gz (11.8 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: data-place-0.2.5.tar.gz
  • Upload date:
  • Size: 11.8 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.2.5.tar.gz
Algorithm Hash digest
SHA256 c5f89ff82f3b51ce854a429212689ddd03ce2f047ff7badfceb9af4b1d805dfc
MD5 cc18aa07184d15c7d05abbb11d2cc7d9
BLAKE2b-256 d5d47f675f97ea2e126a0dff4e281e6665f5eb853787ad552f51bf43e33039f7

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