A framework to help navigate buffers through a graph. The buffers must flow.
Project description
SGN Documentation
SGN is a lightweight Python library for creating and executing task graphs
asynchronously for streaming data. With only builtin-dependencies, SGN is easy to install and use.
This page is for the base library sgn
, but there is a family of libraries that extend the functionality of SGN,
including:
sgn-ts
: TimeSeries utilities for SGNsgn-ligo
: LSC specific utilities for SGNsgn-try
: Process monitoring and alerting utilities for SGN
Installation
To install SGN, simply run:
pip install sgn
SGN has no dependencies outside of the Python standard library, so it should be easy to install on any system.
Quickstart
To get started with SGN, you can create a simple task graph that represents a simple data processing pipeline with integers. Here's an example:
from sgn import Pipeline, DequeSink, DequeSource, CallableTransform
# Define a function to use in the pipeline
def add_ten(frame):
return None if frame.data is None else frame.data + 10
# Create source element
src = DequeSource(
name="src1",
source_pad_names=["H1"],
iters={"src1:src:H1": [1, 2, 3]},
)
# Create a transform element using an arbitrary function
trn1 = CallableTransform.from_callable(
name="t1",
sink_pad_names=["H1"],
callable=add_ten,
output_name="H1",
)
# Create the sink so we can access the data after running
snk = DequeSink(
name="snk1",
sink_pad_names=("H1",),
)
# Create the Pipeline
p = Pipeline()
# Insert elements into pipeline and link them explicitly
p.insert(src, trn1, snk, link_map={
"t1:sink:H1": "src1:src:H1",
"snk1:sink:H1": "t1:src:H1",
})
# Run the pipeline
p.run()
# Check the result of the sink queue to see outputs
assert list(snk.deques["snk1:sink:H1"]) == [13, 12, 11]
The above example can be modified to use any data type, including json-friendly
nested dictionaries, lists, and strings. The CallableTransform
class can be used to
create a transform element using any arbitrary function. The DeqSource
and DeqSink
classes
are used to create source and sink elements that use collections.deque
to store data.
General Concepts
SGN is designed to be simple and easy to use. Here we outline the key concepts, but for more detail see the key concepts page in the documentation with link: concepts.rst In SGN there are a few concepts to understand:
Graph Construction
-
Sources: Sources are the starting point of a task graph. They produce data that can be consumed by other tasks.
-
Transforms: Transforms are tasks that consume data from one or more sources, process it, and produce new data.
-
Sinks: Sinks are tasks that consume data from one or more sources and do something with it. This could be writing the data to a file, sending it over the network, or anything else.
Control Flow
Using these concepts, you can create complex task graphs using SGN that process and move data in a variety of ways. The SGN library provides a simple API for creating and executing task graphs, with a few key types:
-
Frame: A frame is a unit of data that is passed between tasks in a task graph. Frames can contain any type of data, and can be passed between tasks in a task graph.
-
Pad: A pad is a connection point between two tasks in a task graph. Pads are used to pass frames between tasks, and can be used to connect tasks in a task graph. An edge is a connection between two pads in a task graph.
-
Element: An element is a task in a task graph. Elements can be sources, transforms, or sinks, and can be connected together to create a task graph.
-
Pipeline: A pipeline is a collection of elements that are connected together to form a task graph. Pipelines can be executed to process data, and can be used to create complex data processing workflows.
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
File details
Details for the file sgn-0.0.3.tar.gz
.
File metadata
- Download URL: sgn-0.0.3.tar.gz
- Upload date:
- Size: 31.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 224015174ec576a22d1bd34c3c718f5e306c821725e62f12c4a5fa17e6d10011 |
|
MD5 | 73f442b6677813d7d6d877e72ba5639f |
|
BLAKE2b-256 | 345ab3d62970922fe4ad69ae32e6ffde70a0fffe35411eb742a8c7bc95ffec57 |
File details
Details for the file sgn-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: sgn-0.0.3-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 460aece498ea7224345bd3744e6f9996521bb1aeb8f0d89a58f589679049750a |
|
MD5 | a21f4cd8aa2db361b2f8487978029ccf |
|
BLAKE2b-256 | 645de7fc3d006445351aee53f6f6ffdc09cc254b3c3e5f833df89ae45ae62445 |