Metadata-Version: 2.5
Name: datastreamservicelib
Version: 1.16.0
Summary: AsyncIO eventloop helpers and Abstract Base Classes for making services that use ZMQ nice, easy and DRY
Project-URL: Homepage, https://gitlab.com/advian-oss/python-datastreamservicelib/
Project-URL: Repository, https://gitlab.com/advian-oss/python-datastreamservicelib/
Author-email: Eero af Heurlin <eero.afheurlin@iki.fi>
License-Expression: MIT
License-File: LICENSE
Requires-Python: <4.0,>=3.12
Requires-Dist: click<9.0,>=8.0
Requires-Dist: datastreamcorelib<2.0,>=1.8
Requires-Dist: libadvian<2.0,>=1.9
Requires-Dist: pyzmq<28.0,>=26.0
Requires-Dist: toml<1.0,>=0.10
Requires-Dist: tomlkit<1.0,>=0.11
Description-Content-Type: text/x-rst

====================
datastreamservicelib
====================

AsyncIO eventloop helpers and Abstract Base Classes for making services that use ZMQ nice, easy and DRY.

Python 3.12, 3.13 and 3.14 are supported.

Usage
-----

Use the CookieCutter template at https://gitlab.com/advian-oss/python-datastreamserviceapp_template
or see ``src/datastreamservicelib/console.py`` for publisher and subscriber examples.

Create and run services inside a managed event loop::

    import asyncio
    from pathlib import Path
    from datastreamservicelib.service import SimpleService

    async def main() -> int:
        service = SimpleService(Path("config.toml"))
        return await service.run()

    raise SystemExit(asyncio.run(main()))

Local development
-----------------

Install uv_ and create the locked development environment::

    uv sync --locked --python 3.12
    uv run --locked prek install --install-hooks
    uv run --locked prek run --all-files
    uv run --locked pytest

.. _uv: https://docs.astral.sh/uv/getting-started/installation/

Use Python 3.12 for development when checking compatibility with the oldest supported version.
To use another supported interpreter, run ``uv sync --locked --python 3.14``.
Commands run through ``uv run`` use the project environment; manual activation is optional.

The hooks use Ruff for linting and formatting, strict Pyrefly for type checking,
and Bandit for security checks. The configuration remains ``.pre-commit-config.yaml``;
prek is the hook runner. Individual checks and CLI help are available with::

    uv run --locked ruff check src tests
    uv run --locked ruff format --check src tests
    uv run --locked pyrefly check
    uv run --locked bandit -r src
    uv run --locked testpublisher --help
    uv run --locked testsubscriber --help

Refresh ``uv.lock`` after editing dependencies with ``uv lock``. Commit both the metadata
and lockfile. Build the wheel and source distribution with ``uv build``.

Version bumps
^^^^^^^^^^^^^

Preview and apply a patch bump with::

    uv run --locked bump-my-version bump patch --dry-run -v
    uv run --locked bump-my-version bump patch
    uv lock
    uv build

``.bumpversion.toml`` updates the project metadata, package version, version test,
and production image tags in this README. Review and commit the changes; bumping
does not automatically commit or create a tag.

Containers
----------

``Dockerfile`` uses Debian Trixie. ``Dockerfile_alpine`` uses Alpine 3.24.
Both provide ``test``, ``tox``, ``devel_shell`` and ``production`` targets.
Production uses Python 3.14; tox tests Python 3.12, 3.13 and 3.14.

Run all container builds and checks with Docker or Podman::

    CONTAINER_ENGINE=docker ./run_tests.sh
    CONTAINER_ENGINE=podman ./run_tests.sh

Limit the run when developing a particular target::

    CONTAINER_ENGINE=podman VARIANTS=debian TARGETS=tox ./run_tests.sh

The script copies source into each image and does not mount the host virtualenv,
Git hooks, or SSH agent. Public dependencies need no SSH forwarding. It does not
need a shared temporary directory in Podman Machine.

An optional wheelhouse can be used during builds::

    WHEELHOUSE_URL=http://host.docker.internal:3141/debian/ CONTAINER_ENGINE=podman ./run_tests.sh

Set ``VARIANTS=debian`` when using a Debian-specific wheelhouse. For Alpine, use the
appropriate wheelhouse URL. The script maps ``host.docker.internal`` to the host gateway;
without ``WHEELHOUSE_URL``, uv uses its normal package index.

Development shell
^^^^^^^^^^^^^^^^^

Build and run a development shell::

    docker build --target devel_shell -t datastreamservicelib:devel_shell .
    docker run --rm -it datastreamservicelib:devel_shell

Podman equivalent::

    podman build --format docker --target devel_shell -t datastreamservicelib:devel_shell .
    podman run --rm -it datastreamservicelib:devel_shell

Run ``uv run --locked pytest`` or ``uv run --locked docker/prek_init.sh`` inside the
container. Rebuild to include source edits. For interactive source editing, mount the
repository at ``/app``; its VM sharing configuration must permit this when using Podman.
The development environment is kept at ``/opt/venv`` inside the container.

Tox
^^^

Run a single interpreter in the tox image::

    podman build --format docker --target tox -t datastreamservicelib:tox .
    podman run --rm datastreamservicelib:tox -e py314

For Docker, use ``docker`` instead of ``podman`` and omit ``--format docker``.
With no arguments, the tox image runs all supported interpreters. Each tox environment
syncs from ``uv.lock`` and runs hooks, pytest, Pyrefly and Bandit.

Production
^^^^^^^^^^

Build a production image and inspect the publisher/subscriber commands::

    docker build --target production -t datastreamservicelib:1.16.0 .
    docker run --rm datastreamservicelib:1.16.0 testpublisher --help
    docker run --rm datastreamservicelib:1.16.0 testsubscriber --help

Podman equivalent::

    podman build --format docker --target production -t datastreamservicelib:1.16.0 .
    podman run --rm datastreamservicelib:1.16.0 testpublisher --help

The default command displays help for both tools. To exchange messages between
containers, use a common network and a TCP socket, or a shared volume and an IPC socket.
IPC sockets shared between macOS and a Linux VM do not behave like native Linux sockets.

Continuous integration
----------------------

GitLab runs the Python test matrix and builds wheel/source distributions. It also builds
and runs all four container targets on Debian and Alpine using ``run_tests.sh``.
Container jobs require a privileged Docker-in-Docker runner with shared TLS certificates.
Local validation uses Podman; remote runner behavior must be verified in GitLab.
