A powerful yet simple Python task scheduler
Project description
PyScheduler
The simplest and most powerful Python scheduler
PyScheduler revolutionizes task scheduling in Python. 3 lines are enough to get started, yet it offers all the power needed for production.
โจ Features
- ๐ฏ Ultra-simple: Get started in 30 seconds
- โก High-performance: Optimized threading, native async tasks
- ๐ก๏ธ Robust: Automatic retry, advanced error handling
- ๐ Comprehensive: Detailed logs, monitoring, statistics
- ๐ Flexible: Intervals, CRON, one-off tasks
- ๐ Production-ready: YAML configuration, integrated CLI
๐ Installation
pip install pyscheduler[full]
Minimal installation (without optional dependencies)
pip install pyscheduler
โก Quick Start
from pyscheduler import PyScheduler, task
@task(60) # Every minute
def backup_data():
print("Automatic backup!")
@task(cron="0 9 * * 1-5") # 9 AM on weekdays
def send_report():
print("Daily report sent")
# That's it! ๐
scheduler = PyScheduler()
scheduler.start()
๐ Usage Examples
Simple Tasks
from pyscheduler import task, daily, startup
@task(30) # Every 30 seconds
def health_check():
return check_system_health()
@daily("02:00") # Every day at 2 AM
def daily_backup():
return backup_database()
@startup() # On startup
def init_app():
return initialize_application()
Advanced Configuration
from pyscheduler import PyScheduler
from pyscheduler.config import RetryConfig, Priority
scheduler = PyScheduler(log_level="INFO")
scheduler.add_task(
func=critical_task,
interval=300, # 5 minutes
priority=Priority.CRITICAL,
timeout=60,
retry_config=RetryConfig(max_attempts=3, backoff_factor=2.0)
)
YAML Configuration
# scheduler_config.yaml
global_settings:
timezone: "Europe/Paris"
log_level: "INFO"
max_workers: 10
tasks:
- name: "backup_task"
module: "myapp.tasks"
function: "backup_database"
schedule:
type: "cron"
value: "0 2 * * *" # 2 AM
priority: "HIGH"
timeout: 3600
scheduler = PyScheduler(config_file="scheduler_config.yaml")
scheduler.start()
๐ช Use Cases
| Need | PyScheduler Solution |
|---|---|
| ๐ Periodic Tasks | @task(interval=60) |
| โฐ Precise Scheduling | @task(cron="0 9 * * 1-5") |
| ๐ Startup/Shutdown Tasks | @startup() / @shutdown() |
| โก Asynchronous Tasks | Native async def support |
| ๐ก๏ธ Robustness | Automatic retry, timeouts |
| ๐ Production | Logs, stats, monitoring |
๐ Full Documentation
- ๐ Complete Guide
- ๐ฏ Detailed Examples
- ๐ง API Reference
- โ FAQ & Troubleshooting
๐โโ๏ธ Quick Examples
Get started with included examples
# After installation
python -c "from pyscheduler.examples import basic_usage; basic_usage.main()"
Real-time Monitoring
with PyScheduler() as scheduler:
# Your tasks here
scheduler.run_forever() # Ctrl+C to stop
๐ Advanced Features
๐ฏ Priorities and Threading
from pyscheduler.config import Priority
@task(interval=60, priority=Priority.CRITICAL)
def critical_health_check():
return monitor_critical_systems()
@task(interval=300, priority=Priority.LOW)
def cleanup_temp_files():
return cleanup_operations()
โก Asynchronous Tasks
@task(interval=30)
async def async_api_calls():
async with aiohttp.ClientSession() as session:
tasks = [fetch_data(session, url) for url in urls]
return await asyncio.gather(*tasks)
๐ก๏ธ Robust Error Handling
from pyscheduler.config import RetryConfig
@task(
interval=120,
retry_config=RetryConfig(
max_attempts=5,
backoff_factor=2.0,
max_delay=300
),
timeout=60
)
def unreliable_external_api():
return call_external_service()
๐ฅ Why PyScheduler?
| Problem | PyScheduler Solution |
|---|---|
| ๐ฉ APScheduler too complex | โ 3 lines to get started |
| ๐ Celery is overkill | โ Zero configuration Redis/broker |
| ๐ง Cron is limited | โ Native Python + cron expressions |
| ๐ No monitoring | โ Detailed logs + statistics |
| ๐ซ No retry | โ Smart retry built-in |
๐ Performance
- โก Startup: < 100ms
- ๐พ Memory: < 20MB for 100 tasks
- ๐ Concurrency: Up to 1000 parallel tasks
- ๐ฏ Precision: ยฑ50ms on schedules
๐ค Contributing
We welcome all contributions!
git clone https://github.com/Tiger-Foxx/PyScheduler.git
cd PyScheduler
pip install -e .[dev]
pytest
๐ License
MIT License - see LICENSE for details.
๐ Acknowledgments
Inspired by the best scheduling tools, designed for Pythonic simplicity.
โญ If PyScheduler helps you, feel free to star the repo!
๐ Homepage โข ๐ Documentation โข ๐ Issues โข ๐ฌ Discussions
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 pyscheduler_fox-1.0.0.tar.gz.
File metadata
- Download URL: pyscheduler_fox-1.0.0.tar.gz
- Upload date:
- Size: 80.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c78aa93f533c8fe2e10958bf162bc0fc4e43516e70b003b9135398c303cd6614
|
|
| MD5 |
e25afd49fd3a389d49aa7f64051b14c4
|
|
| BLAKE2b-256 |
068e827cf94e02b4179949b102da10710299df806a600d461ec64b4d0a5b6517
|
File details
Details for the file pyscheduler_fox-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyscheduler_fox-1.0.0-py3-none-any.whl
- Upload date:
- Size: 89.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a0a7209499c7b24b4ab14e150eed832bc89273cdf97f1c5a8f0d889f6d940c8
|
|
| MD5 |
cfbb9c0743435b96bef8dd030677c35f
|
|
| BLAKE2b-256 |
3e7c8b3998627cea19cbd34f7a5db46ba2e35192443619074d9a8ad5cf344597
|