daemonizer
Light-weight and easy-to-use Python package that simplifies the process of daemonizing Python applications, allowing them to run in the background as standalone logics.
Features
- Simple API to daemonize any Python function or class
- Automatic handling of process management (PID files, logging, etc.)
- Support for start, stop, restart, and status operations
- Signal handling (SIGTERM, SIGINT, etc.)
- Compatible with UNIX-like systems
- Python 3.7+ support
Getting started
Install package using uv or pip:
uv add daemonizer-py # pip install daemonizer-py
Create a Python script daemon.py where you can define your daemon logic following below framework:
from datetime import datetime
from time import sleep
from daemonizer.core.daemons.logic import forever_loop
from daemonizer.core.daemons.unix import UNIXDaemon
class SampleDaemon(UNIXDaemon):
""" Sample daemon """
@forever_loop(catch_exceptions=False, after_delay=0.01)
def run(self) -> None:
with open("/tmp/hello_daemon.log", "a") as f:
f.write(f"Hello, World {datetime.now()}\n")
f.write(f"{self.kwargs().get('ssa', None)}\n")
sleep(1)
Defining a daemon is very simple:
- Create a subclass of
UNIXDaemon - Just overload the
run(...)method with your logic to be executed in the daemon
Once defined, you can start a daemon using two methods:
- Using
handlerfunc:
if __name__ == "__main__":
handler(SampleDaemon(name="daemon_1"))
uv run daemon.py [start|stop|restart|status]
- Using context manager handler with
DaemonHandler():
from daemonizer.core.handlers.ctx_manager import DaemonHandler
# Daemons handler
with DaemonHandler() as h:
h.start(SampleDaemon1(name="daemon_1"))
h.start(SampleDaemon2(name="daemon_2"))
- Using CLI:
daemonizer start daemon.py # START op will be performed on all daemons defined in this file
daemonizer start daemon.py SampleDaemon1 # START op will be performed **ONLY** on `SampleDaemon1` defined in this file
- Using API or web-app (WIP)
The package provides a simple command-line interface to interact with the daemonized process. The following commands are available:
$ python3 main.py {start,stop,restart,status}
Contribute
Clone the repo, improve the code base and submit a pull request
git clone https://github.com/lcsrodriguez/daemonizer.git
cd daemonizer/
uv sync
pre-commit install-hooks
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for daemonizer-py 1.5.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| daemonizer_py-1.5.4.tar.gz | 74.5 kB | Without provenance | Details for daemonizer_py-1.5.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| daemonizer_py-1.5.4-py3-none-any.whl | Python 3 | none | any | Details for daemonizer_py-1.5.4-py3-none-any.whl |
Total release size: 105.0 kB
Release files / daemonizer_py-1.5.4.tar.gz
| Download URL | daemonizer_py-1.5.4.tar.gz |
|---|---|
| Size | 74.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97d9b979a84df4773f957a49aa2e5651772fae0986ad28b8a7e66a226df10b15
|
|
BLAKE2b-256 checksum How to use checksums |
6c99181ea7ad77d247a9d6cd9ed1e93035e3946729dbe1a3d3d9eef2866feb44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","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}
|
Release files / daemonizer_py-1.5.4-py3-none-any.whl
| Download URL | daemonizer_py-1.5.4-py3-none-any.whl |
|---|---|
| Size | 30.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0007cb8940bf1918bc0c91d3337758ca21b4c5fa8a3a8471688738b9116af958
|
|
BLAKE2b-256 checksum How to use checksums |
c15b4eb76bc81e8dd70baaac4e88d610fd48ce56d3edaf5d3d68450f23a9dbd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","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}
|
Security for daemonizer-py 1.5.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.