Skip to main content

Base processor classes and protocols for ezmsg signal processing pipelines

Project description

ezmsg-baseproc

Base processor classes and protocols for building message-processing components in ezmsg.

Installation

pip install ezmsg-baseproc

Or install the latest development version:

pip install git+https://github.com/ezmsg-org/ezmsg-baseproc@dev

Overview

ezmsg-baseproc provides abstract base classes for creating message processors that can be used both standalone and within ezmsg pipelines. The package offers a consistent pattern for building:

  • Protocols - Type definitions for processors, transformers, consumers, and producers
  • Processors - Transform input messages to output messages
  • Producers - Generate output messages without requiring input
  • Consumers - Accept input messages without producing output
  • Transformers - A specific type of processor with typed input/output
  • Stateful variants - Processors that maintain state across invocations
  • Adaptive transformers - Transformers that can be trained via partial_fit
  • Composite processors - Chain multiple processors together efficiently

All base classes support both synchronous and asynchronous operation, making them suitable for offline analysis and real-time streaming applications.

Usage

Creating a Simple Transformer

from dataclasses import dataclass
from ezmsg.baseproc import BaseTransformer
from ezmsg.util.messages.axisarray import AxisArray, replace

@dataclass
class MySettings:
    scale: float = 1.0

class MyTransformer(BaseTransformer[MySettings, AxisArray, AxisArray]):
    def _process(self, message: AxisArray) -> AxisArray:
        return replace(message, data=message.data * self.settings.scale)

Creating a Stateful Transformer

from ezmsg.baseproc import BaseStatefulTransformer, processor_state

@processor_state
class MyState:
    count: int = 0
    hash: int = -1

class MyStatefulTransformer(BaseStatefulTransformer[MySettings, AxisArray, AxisArray, MyState]):
    def _reset_state(self, message: AxisArray) -> None:
        self._state.count = 0

    def _process(self, message: AxisArray) -> AxisArray:
        self._state.count += 1
        return message

Creating an ezmsg Unit

from ezmsg.baseproc import BaseTransformerUnit

class MyUnit(BaseTransformerUnit[MySettings, AxisArray, AxisArray, MyTransformer]):
    SETTINGS = MySettings
    # That's all - the base class handles everything else!

Development

We use uv for development.

  1. Install uv if not already installed
  2. Clone and cd into the repository
  3. Run uv sync to create a .venv and install dependencies
  4. Run uv run pytest tests to run tests
  5. (Optional) Install pre-commit hooks: uv run pre-commit install

License

MIT License - see LICENSE for details.

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

ezmsg_baseproc-1.2.0.tar.gz (40.2 kB view details)

Uploaded Source

Built Distribution

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

ezmsg_baseproc-1.2.0-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file ezmsg_baseproc-1.2.0.tar.gz.

File metadata

  • Download URL: ezmsg_baseproc-1.2.0.tar.gz
  • Upload date:
  • Size: 40.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ezmsg_baseproc-1.2.0.tar.gz
Algorithm Hash digest
SHA256 bcb66ddd522c230fda3aaf6113c92e3f69fc9f0715bea73edb5f407ba4252761
MD5 81baec3fb6af454a9ba5917997353618
BLAKE2b-256 893c124ecffc1c189f4f50fa69f1db6c2ba5ef5a18f21ec17965e07f3c115cdd

See more details on using hashes here.

File details

Details for the file ezmsg_baseproc-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: ezmsg_baseproc-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ezmsg_baseproc-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99a1faeb0c151a6e944d9fbafa2174fc25a01abe1b3cb8077b36c928a5a8a506
MD5 19ef7cd2a902a5f0fe8069959db30d3b
BLAKE2b-256 b018f05c684503c21e0cec0f219ca3c713b02a43c810f519d5a2ee84ebe50ae6

See more details on using hashes here.

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