A lightweight Python-native service manager.
Project description
konstant
A lightweight, cross-platform Python process manager. Think PM2 but Python-native and without the Node dependency.
Features
- Manage long-running Python processes via a simple CLI
- Automatic restart with configurable backoff protection
- Log capture with rotation
- Service registration that survives reboots (systemd on Linux, launchd on macOS, Windows services via pywin32)
- No daemon required — state is stored in flat JSON files
- Works on Windows, macOS, and Linux
Installation
pip install konstant
Quick Start
- Create a
konstant.tomlin your working directory:
[services.my-worker]
script = "worker.py"
interpreter = "python"
cwd = "/home/user/myapp"
env_file = ".env"
autorestart = true
max_restarts = 10
restart_delay = 5
- Start your services:
konstant start # start all services
konstant start my-worker # start a specific service
CLI Commands
konstant start [name] Start service(s)
konstant stop [name] Stop service(s)
konstant restart [name] Restart service(s)
konstant status [name] Show pid, uptime, restart count, status
konstant logs [name] Tail logs (default: last 50 lines)
konstant logs [name] --follow Stream logs live
konstant install [name] Register as system service (survives reboot)
konstant uninstall [name] Remove system service registration
Configuration
See konstant.toml for all available options:
| Key | Type | Default | Description |
|---|---|---|---|
script |
str | required | Path to the Python script to run |
interpreter |
str | "python" |
Python interpreter to use |
cwd |
str | "." |
Working directory for the process |
env_file |
str | "" |
Path to a .env file to load |
autorestart |
bool | true |
Restart on crash |
max_restarts |
int | 10 |
Max restarts within a 60s window |
restart_delay |
int | 5 |
Seconds to wait before restarting |
args |
list | [] |
Extra arguments passed to the script |
Service Registration
konstant install registers services so they start automatically on boot. The backend is chosen based on the OS:
| Platform | Backend | Location |
|---|---|---|
| Linux | systemd (user) | ~/.config/systemd/user/konstant_{name}.service |
| macOS | launchd (user) | ~/Library/LaunchAgents/com.konstant.{name}.plist |
| Windows | Windows Service (pywin32) | Windows Service Manager |
No root/admin is required on Linux or macOS — services are registered at the user level.
konstant install my-worker # register
konstant uninstall my-worker # remove
The --user and --password flags are only meaningful on Windows.
Logging
By default, logs are written in plain text with timestamps. You can switch to structured JSON output per-service or globally, and optionally forward logs to Elasticsearch or Logstash.
JSON structured logs
Set format = "json" in a global [logging] section or per-service under [services.<name>.logging]:
# Global default — all services emit JSON
[logging]
format = "json"
# Or override per-service
[services.my-worker.logging]
format = "json"
Each log line becomes a JSON object with ELK-compatible field names:
{"@timestamp": "2026-03-26T18:20:31Z", "service": "my-worker", "stream": "stdout", "message": "tick 0", "level": "INFO"}
konstant logs automatically pretty-prints JSON lines for readability. Use --raw to see the raw JSON.
Log forwarding
Forward logs directly to Elasticsearch or Logstash — no Filebeat required:
# Global forwarding (applies to all services)
[logging.forward]
enabled = true
type = "elasticsearch" # "elasticsearch" or "logstash"
url = "http://localhost:9200"
index = "konstant-logs"
# Optional auth
username = ""
password = ""
api_key = ""
# Per-service override
[services.my-worker.logging.forward]
enabled = true
type = "logstash"
url = "tcp://localhost:5044"
Forwarding runs in a background thread. If the remote is unreachable, batches are retried (3 attempts with backoff) then dropped — local log files are always written regardless.
Forwarding options
| Key | Type | Default | Description |
|---|---|---|---|
enabled |
bool | false |
Enable log forwarding |
type |
str | "elasticsearch" |
"elasticsearch" or "logstash" |
url |
str | "http://localhost:9200" |
Elasticsearch URL or Logstash tcp://host:port |
index |
str | "konstant-logs" |
Elasticsearch index name |
username |
str | "" |
Basic auth username |
password |
str | "" |
Basic auth password |
api_key |
str | "" |
Elasticsearch API key |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file konstant-0.1.1.tar.gz.
File metadata
- Download URL: konstant-0.1.1.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b554f7cb2744182d81853eeb525238bdfead5093afef681f4de398e8edeb3561
|
|
| MD5 |
948f8d61fa176a677b66c1e1bd391c91
|
|
| BLAKE2b-256 |
d0bb789c22845bee92da4e92f3f6c2c7df66cdc6882ec4db2241b874d3a56e3a
|
Provenance
The following attestation bundles were made for konstant-0.1.1.tar.gz:
Publisher:
publish-pypi.yml on karan-kulkarni05/konstant
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
konstant-0.1.1.tar.gz -
Subject digest:
b554f7cb2744182d81853eeb525238bdfead5093afef681f4de398e8edeb3561 - Sigstore transparency entry: 1188774512
- Sigstore integration time:
-
Permalink:
karan-kulkarni05/konstant@15bf5093fcaf13ad38176e6390812ca5b08f2bb9 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/karan-kulkarni05
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@15bf5093fcaf13ad38176e6390812ca5b08f2bb9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file konstant-0.1.1-py3-none-any.whl.
File metadata
- Download URL: konstant-0.1.1-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad0b84c7022d4a85e076c08e23a0257ba8d5967dc8a41356beed87024bd8a872
|
|
| MD5 |
157b8d10d8149c18d096525674b9f530
|
|
| BLAKE2b-256 |
6a437117a5f053f12af9ad92152f753b71e701e6e75f5bb242046ca5bdea79c1
|
Provenance
The following attestation bundles were made for konstant-0.1.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on karan-kulkarni05/konstant
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
konstant-0.1.1-py3-none-any.whl -
Subject digest:
ad0b84c7022d4a85e076c08e23a0257ba8d5967dc8a41356beed87024bd8a872 - Sigstore transparency entry: 1188774542
- Sigstore integration time:
-
Permalink:
karan-kulkarni05/konstant@15bf5093fcaf13ad38176e6390812ca5b08f2bb9 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/karan-kulkarni05
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@15bf5093fcaf13ad38176e6390812ca5b08f2bb9 -
Trigger Event:
push
-
Statement type: