Tiny, parallel, poor-man's anacron with requirements.
Project description
napcron
napcron is a small, Python-based, parallel replacement for anacron.
It ensures periodic jobs (daily, weekly, monthly, etc.) still run even if the system was powered off, suspended, or offline when they were scheduled.
Unlike cron, it records when tasks last succeeded and executes only those that are due.
Unlike anacron, it is easy to configure
Installation
From PyPI
python -m pip install --upgrade napcron
From source (local checkout)
git clone https://github.com/alcalde/napcron.git
cd napcron
python -m pip install .
The napcron CLI becomes available on your PATH after installation.
Usage
napcron is designed to be executed once per hour via cron, systemd, or any scheduler.
It reads a YAML configuration file, checks which tasks are due, evaluates their requirements, and executes them in parallel.
Cron job example
Edit your user crontab (crontab -e):
@hourly napcron /home/user/.napcron.yaml
Configuration
Example /home/user/.napcron.yaml:
daily:
- bash /home/user/a.sh:
- internet
- python $HOME/a.py: internet
- ~/just_run_me.sh
- ./also_okay:
weekly:
- /cleanup_logs.sh: [internet, ac_power]
monthly:
- python ~/rotate_backups.py
Explanation
| Frequency | Description | Interval |
|---|---|---|
daily |
Runs once every 24 hours since the last success | 1 day |
weekly |
Runs once every 7 days since the last success | 7 days |
monthly |
Runs once every 30 days | 30 days |
Features
-
Runs missed periodic jobs (daily, weekly, monthly)
-
Executes due tasks in parallel
-
Supports configurable requirements:
internet– verify network connectivityac_power– ensure external power is connectedbattery– placeholder for custom checks
-
Simple YAML configuration
-
Persistent state tracking in
~/.local/state/napcron/ -
Atomic file lock to prevent overlapping runs
-
Safe dry-run mode (
--dry-run) -
Only dependency: PyYAML
Accepted YAML formats for each job:
- "cmd" # No requirements
- cmd: # No requirements (no [] needed)
- cmd: internet # Single requirement
- cmd: [internet, ac_power] # Multiple requirements
Requirements
Each task may specify one or more requirements that must be met before execution. napcron provides the following built-in checks:
| Requirement | Description | Platforms |
|---|---|---|
internet |
Checks for network connectivity by opening a TCP connection to 1.1.1.1:443 or 8.8.8.8:53 | All |
ac_power |
Returns true if the system is running on external power (Linux, macOS, Windows) | Linux / macOS / Windows |
battery |
Placeholder requirement, always returns True | All |
Custom requirement checks can easily be added by extending the REQUIREMENTS dictionary in napcron.py.
Example:
def req_gpu_available(cmd: str) -> bool:
return shutil.which("nvidia-smi") is not None
REQUIREMENTS["gpu"] = req_gpu_available
Used in YAML:
daily:
- python train.py: gpu
State Management
napcron stores metadata about executed tasks in JSON format at:
~/.local/state/napcron/<config-name>.state.json
Each entry includes information such as last success, last attempt, and last exit code.
Example:
{
"tasks": {
"daily::bash /home/daniel/a.sh": {
"frequency": "daily",
"cmd": "bash /home/daniel/a.sh",
"last_success": "2025-10-26T10:00:00+00:00",
"last_status": 0
}
}
}
Command-line Options
| Option | Description |
|---|---|
--dry-run |
Show which jobs would run, without executing or modifying state |
--verbose, -v |
Print detailed logs |
--state PATH |
Use a custom path for the JSON state file |
--max-workers N |
Limit the number of parallel jobs (default: number of due tasks, maximum 32) |
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 napcron-0.1.0.tar.gz.
File metadata
- Download URL: napcron-0.1.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d699fce82599ff3f8d616618f3fd9cb5a0cbd31d8f73d738ddfde5958dff778
|
|
| MD5 |
b840b953bc6189bec875a20188c0b00f
|
|
| BLAKE2b-256 |
6ee2e30c193c5286f09aca7c7c8f18e54388a0725fa93fec43d35234f64bdb75
|
File details
Details for the file napcron-0.1.0-py3-none-any.whl.
File metadata
- Download URL: napcron-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18535e4a036052f193b733572ad50799c4c30251b34eefb88dbe29caab3b7a3d
|
|
| MD5 |
050db4d7432e63105d144a9cdf11d11d
|
|
| BLAKE2b-256 |
5bf274a23e75d571d7d30ef7364d89a56638afec6b6996a56bbd3395af09da77
|