python-daemon
Library to implement a well-behaved Unix daemon process.
What it is and what it does
python-daemon is a library that implements the PEP 3143 standard for well-behaved Unix daemon processes. Creating a daemon—a process that runs in the background detached from the terminal—requires several tricky steps: forking, closing file descriptors, handling signals, and setting up the process environment correctly. This library encapsulates all of that complexity into a simple context manager interface, so you can wrap your main program logic and let DaemonContext handle the daemon setup automatically.
You configure the daemon by setting options on a DaemonContext instance (signal handlers, working directory, file descriptors to preserve, etc.) and then use it as a context manager. The library depends only on lockfile for file-based locking during the daemonization process. It requires Python 3.7 or later and runs only on POSIX systems.
Use it for:
- Long-running background services (log aggregators, monitoring agents, scheduled job runners) that need to detach from the terminal.
- System utilities that must fork and run as true Unix daemons with proper signal handling and file descriptor management.
- Applications that need to customize daemon behavior (e.g., preserve specific file descriptors, set working directory, manage pidfiles).
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Implements PEP 3143 well-behaved Unix daemon processes, handling the complex steps of forking and process environment setup so your program can run reliably in the background.
Yes, if you are building a Unix daemon in Python and want to follow PEP 3143 correctly without reimplementing the forking and setup logic yourself. The dormant maintenance status is not a blocker—the package is feature-complete and stable—but verify that it meets your Python version and OS requirements. Not suitable for Windows.
Install
python-daemon on PyPI
pip
pip install python-daemonuv
uv add python-daemonpoetry
poetry add python-daemonInstalling python-daemon
Before you install
Low install friction with a single lightweight dependency (lockfile). Maintenance is dormant—last release was 619 days ago—but the package is marked Production/Stable and has been actively maintained since 2009, suggesting it is feature-complete and unlikely to require frequent updates.
License in practice
Dual-licensed under Apache License 2.0 (daemon library) and GNU General Public License version 3+ (packaging and tests). Permissive treatment means you can use, modify, and distribute freely, but be aware of the GPL v3 component if you redistribute the package itself.
Quickstart
pip install python-daemon
import daemon
with daemon.DaemonContext():
# Your background process code here
pass
Unix/POSIX systems only; not supported on Windows.
Verify before relying
- Whether dormant maintenance status (last release 619 days ago) poses a risk for future Python or OS compatibility.
- Specific behavior differences or limitations when used with modern async frameworks or process managers.
Package facts
| License | Copying this work ################# ‘python-daemon’ is under Copyright © 2008–2024 Ben Finney and others. This work, ‘python-daemon’, is free software: you may copy, modify, and/or distribute this… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — lockfile |
| Maintenance | dormant — 619 days since the last release |
| First released | |
| Downloads | 21,136,028/month — #1,011 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: python_daemon-3.1.2-py3-none-any.whl
Keywords: daemon, fork, unix
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
daemonizeDaemonize provides a Python library for…
permissive · top 15,000 on PyPI
pidManages process ID files with stale detection,…
permissive · top 15,000 on PyPI
supervisorSupervisor is a client/server system that…
permissive · top 5,000 on PyPI
circusCircus runs and watches multiple processes and…
permissive · top 15,000 on PyPI
kantokuKantoku runs and watches multiple processes and…
permissive · top 15,000 on PyPI
cotyledonCotyledon provides a framework for building…
permissive · top 15,000 on PyPI
jeedomdaemonProvides a base class and framework for…
permissive · top 15,000 on PyPI
hupperHupper monitors Python source files for changes…
permissive · top 5,000 on PyPI
pigpioProvides Python access to the pigpio daemon for…
permissive · top 15,000 on PyPI
loggingProvides a standard error logging mechanism for…
unclear · top 15,000 on PyPI