A simple CLI calorie tracker
Project description
caltrack
A minimal CLI calorie tracker. Built with Python and Click.
Installation
From local source (recommended while developing)
# Clone or navigate to the project folder
cd caltrack
# Install in editable mode — changes to source take effect immediately
pip install -e .
From PyPI (once published)
pip install caltrack
Usage
# Add calories
caltrack add 1300
# Remove calories
caltrack remove 400
# Check today's total
caltrack read
# Show version
caltrack --version
# Show help
caltrack --help
caltrack add --help
Where data is stored
All data lives in ~/.caltrack/caltrack.db (SQLite). You can inspect it anytime:
sqlite3 ~/.caltrack/caltrack.db "SELECT * FROM calories;"
The calories table has one row per day:
| id | date | calories |
|---|---|---|
| 1 | 2026-04-27 | 1800 |
Developer Guide — Adding New Commands
1. Add your command to an existing or new file
Commands live in caltrack/commands/. Open an existing file or create a new one.
# caltrack/commands/calories.py (or a new file like caltrack/commands/goals.py)
import click
from caltrack import storage
@click.command()
@click.argument("goal", type=int)
def set_goal(goal: int):
"""Set a daily calorie GOAL."""
# your logic here
click.echo(f"🎯 Daily goal set to {goal} kcal")
2. Register the command in cli.py
Open caltrack/cli.py and add two lines:
from caltrack.commands.calories import add, remove, read, set_goal # add your import
cli.add_command(set_goal) # register it
That's it. Run caltrack set-goal 2000 and it works.
Note: Click automatically converts underscores to hyphens in command names, so
set_goalbecomescaltrack set-goal.
3. Adding storage fields or new tables
New data belongs in caltrack/storage.py. To add a new table, drop a CREATE TABLE IF NOT EXISTS block into _init_db() — it runs on every connection so it's always safe:
def _init_db(conn):
# existing calories table ...
conn.execute("""
CREATE TABLE IF NOT EXISTS goals (
id INTEGER PRIMARY KEY AUTOINCREMENT,
date TEXT NOT NULL UNIQUE,
goal INTEGER NOT NULL
)
""")
conn.commit()
Then add a helper function and use it from your command:
def set_goal(goal: int):
with _db() as conn:
conn.execute(
"INSERT OR REPLACE INTO goals (date, goal) VALUES (?, ?)",
(today_key(), goal),
)
4. Bumping the version
Edit the version field in pyproject.toml:
version = "0.2.0"
Then reinstall:
pip install -e .
5. Publishing to PyPI
# Install build tools (one-time)
pip install build twine
# Build the package
python -m build
# Upload to PyPI
twine upload dist/*
Project structure
caltrack/
├── pyproject.toml # Package metadata and dependencies
├── README.md
└── caltrack/
├── __init__.py
├── cli.py # Entry point — registers all commands
├── storage.py # Read/write ~/.caltrack/data.json
└── commands/
├── __init__.py
└── calories.py # add, remove, read commands
Dependencies
- Click — CLI framework
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 caltrack-0.1.0.tar.gz.
File metadata
- Download URL: caltrack-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e561ac2721ef04f5a0ed92d62bcd516eaf5ba653016a52e3c4a93d9db3669c0
|
|
| MD5 |
a9f1d10a238674b7b0853adfec551cfb
|
|
| BLAKE2b-256 |
64d9c05101877dc78ca3297fea480c030f7cdf87f971228bb19d58f58dc5ee78
|
File details
Details for the file caltrack-0.1.0-py3-none-any.whl.
File metadata
- Download URL: caltrack-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13fdae3c45707846ea3e3b7547c5314498cdc5400a2de3c26196ac955ef35015
|
|
| MD5 |
a7ca7ede344d2b79837c09ff540139cf
|
|
| BLAKE2b-256 |
e0111643ae0fb3fa16e4b66b619b5dda7e78d34c1e8def5f346a46481d735646
|