Skip to main content

Cross-platform background daemon manager — Python SDK

Project description

syspulse (Python)

Python SDK for Syspulse, a cross-platform daemon/process manager.

The syspulse package provides Python bindings to the Syspulse core runtime so you can manage background services from Python on Windows, macOS, and Linux.

Install

pip install syspulse

Supported Python versions

  • Python 3.9+
  • CPython implementation

Quick example

import syspulse

print(syspulse.__version__)

What this package contains

  • Native extension module built with PyO3
  • Typed Python package (py.typed)
  • Async-friendly client helpers

Build notes

  • Distributed as wheels and source distribution on PyPI
  • Built from Rust sources via maturin
  • If building locally, use Python <= 3.13 with current PyO3

##Examples

"""Example Python app that manages a process with syspulse."""

from __future__ import annotations

import sys
import time
from pathlib import Path

from syspulse import (  # type: ignore[reportMissingImports]  # pylint: disable=import-error
    Daemon,
    DaemonAlreadyExistsError,
    SyspulseClient,
)


DAEMON_NAME = "py-app-worker"
HERE = Path(__file__).resolve().parent
WORKER = HERE / "worker.py"


def ensure_manager_running(client: SyspulseClient) -> None:
    if not client.is_running():
        raise SystemExit(
            "syspulse manager is not running.\n"
            "Start it in another terminal with: syspulse daemon"
        )


def build_daemon() -> Daemon:
    return Daemon(
        name=DAEMON_NAME,
        command=[sys.executable, str(WORKER)],
        working_dir=str(HERE),
        description="Example worker started from a Python app",
        tags=["example", "python"],
    )


def main() -> None:
    daemon = build_daemon()

    with SyspulseClient() as client:
        ensure_manager_running(client)

        try:
            client.add(daemon)
            print(f"added daemon: {DAEMON_NAME}")
        except DaemonAlreadyExistsError:
            print(f"daemon already exists: {DAEMON_NAME} (reusing)")

        client.start(DAEMON_NAME, wait=True, timeout=15)
        status = client.status(DAEMON_NAME)
        print(f"started: state={status.state}, pid={status.pid}")

        time.sleep(5)
        logs = client.logs(DAEMON_NAME, lines=10)
        print("recent logs:")
        for line in logs:
            print(f"  {line}")

        client.stop(DAEMON_NAME)
        client.remove(DAEMON_NAME)
        print("stopped and removed daemon")


if __name__ == "__main__":
    main()

worker example to go with above

"""Tiny worker process managed by syspulse."""

from __future__ import annotations

import signal
import time


def main() -> None:
    state = {"running": True}

    def _handle_stop(_signum: int, _frame) -> None:
        print("worker: received stop signal, exiting")
        state["running"] = False

    signal.signal(signal.SIGTERM, _handle_stop)
    signal.signal(signal.SIGINT, _handle_stop)

    print("worker: started")
    i = 0
    while state["running"]:
        i += 1
        print(f"worker: heartbeat {i}")
        time.sleep(2)

    print("worker: shutdown complete")


if __name__ == "__main__":
    main()

Project links

License

MIT

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

syspulse-0.1.1.tar.gz (53.3 kB view details)

Uploaded Source

Built Distribution

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

syspulse-0.1.1-cp312-cp312-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.12Windows x86-64

File details

Details for the file syspulse-0.1.1.tar.gz.

File metadata

  • Download URL: syspulse-0.1.1.tar.gz
  • Upload date:
  • Size: 53.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.4

File hashes

Hashes for syspulse-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e069d1575d167e9a13d4d1f31815724aa907da132189287e8804e4b7f659da85
MD5 55549906677b0c3975f7e893fcee3c72
BLAKE2b-256 0941c57d007b5e5877ed92d379a367abd049668c96a63cf9304083932be5ca81

See more details on using hashes here.

File details

Details for the file syspulse-0.1.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for syspulse-0.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 593997ace989d2eab579ab892f76e96816dfd2d399caeb0095993ab73bf900da
MD5 3420b6e2628baf5385c5ea573b77b9db
BLAKE2b-256 0d27ed53ca2c24c06cd627e93f3841eda48d75e43bae2d6b6490511b75c76de7

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