API-key based CLI client for Food Tracker
Project description
Food Tracker CLI
A fast, local-first CLI tool for tracking food entries with approximate macros. It uses a local SQLite database and supports JSON output for machine readability.
Features
- ⚡️ Fast Entry: Quick logging via CLI args.
- 📊 Local Database: All data stored in
~/.local/share/food/food.db(SQLite). - 📈 Reporting: Daily totals, weekly summaries.
- 🤖 Agent Ready: JSON output mode for AI integration.
- 🖥️ Web UI: Optional local web interface.
Installation
Prerequisites
- Python 3.10 or higher
Setup
It is recommended to use a virtual environment to avoid dependency conflicts.
# 1. Clone or navigate to directory
cd food-tracker-cli
# 2. Create virtual environment
python3 -m venv venv
# 3. Activate it
# On macOS/Linux:
source venv/bin/activate
# On Windows:
# .\venv\Scripts\activate
# 4. Install dependencies
pip install -r requirements.txt
# 5. Initialize Database
python -m cli.main init-db
Deployment
See SETUP.md for Cloudflare Access setup and API key integration.
GitHub Actions
A CI/CD pipeline is configured in .github/workflows/publish.yml. It builds and pushes an arm64 deployment image (optimized for Raspberry Pi) to GitHub Container Registry (ghcr.io) for faster production rollout.
Environment Types
- Persistent deployment (
make deploy)- Uses
deploy/compose.yml - Runs as the stable production-like instance
- Persists DB/cache via bind mount
./data:/app/data(data/app.db,data/widget_cache.jsoninside container) - Fixed URL: http://localhost:8787
- Reserved for external access (for example Cloudflare Tunnel ->
http://192.168.178.38:8787)
- Uses
- Development (
make dev)- Uses
docker-compose.yml - Builds a local image from your current source tree
- Persists DB/cache in docker volume
food-data-devat/app/data(data/app.db,data/widget_cache.jsoninside container) - Independent URL: http://localhost:8686
make devprints the access URL after startup- Must not bind to
8787so it cannot interfere with the deployed tunnel endpoint
- Uses
- Local development build (
make dev-local)- Alias for
make dev
- Alias for
- Branch verification
make masterwas removed- Use CI (GitHub Actions) as the branch verification gate
Production Deployment (Raspberry Pi)
[!NOTE] If the Docker image is Private on GitHub, you must log in first:
echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdinAlternatively, make the package Public in GitHub Package settings.
For production deployment on a Raspberry Pi:
-
Copy the deployment files:
deploy/compose.ymlMakefile
-
Deploy (Start + Auto-Updates):
make deployThis command pulls the latest image, then starts the persistent
food-trackeron port8787pluswatchtower. After initial deployment, watchtower keeps the deploy container on the newestlatestimage automatically. -
View Logs:
make logs -
Stop:
make down-deploy
Typical Workflow
# 1) Start or update the persistent deployed instance
make deploy
# 2) Start a separate development instance
make dev
Expected URLs:
- Deploy: http://localhost:8787
- Dev: http://localhost:8686
Useful commands:
- Stop dev:
make down-dev - Stop deploy:
make down-deploy - Build and run local source (no registry image):
make dev-local - Dev logs:
make logs-dev - Deploy logs:
make logs-deploy - Backward-compatible alias for stopping dev:
make down
Usage
CLI Commands
Current commands in cli/main.py:
# initialize db + migrations
python -m cli.main init-db
# add one entry
python -m cli.main add "Banana" 105 0.4 27 1.3
# list recent entries
python -m cli.main list --limit 10
# delete by id
python -m cli.main delete 1
# run web ui
python -m cli.main ui --host 0.0.0.0 --port 8787
# seed mock data (used by make dev if db is empty)
python -m cli.main seed-mock --if-empty
Standalone Client (pipx)
For OpenClaw users who should not clone this repo, install the API client via pipx:
pipx install "git+https://github.com/Branchenprimus/food-tracker-cli.git"
Then configure key + endpoint:
export FOOD_TRACKER_API_KEY='ftk_...'
export FOOD_TRACKER_API_BASE='https://kcal-tracker.darwin-labs.org'
Use:
food-tracker-cli me
food-tracker-cli add "Cheeseburger" 650 28 52 35
food-tracker-cli list --limit 5
food-tracker-cli delete 123
PyPI release automation:
- Workflow:
.github/workflows/pypi-publish.yml - Trigger: push tag
v*(for examplev2.1.0) - Auth: PyPI Trusted Publisher (OIDC), no PyPI token required.
- Configure on PyPI project:
- Owner:
Branchenprimus - Repository:
food-tracker-cli - Workflow:
pypi-publish.yml - Environment:
pypi
- Owner:
Web UI
The Web UI is available at:
- Deploy: http://localhost:8787
- Dev: http://localhost:8686
Configuration
The database location defaults to:
- macOS/Linux:
~/.local/share/food/food.db - Windows:
~/AppData/Local/food/food.db
You can override this by setting the FOOD_TRACKER_DB environment variable.
API Integration (Agents)
For external agents, prefer HTTP API calls instead of direct local CLI DB writes.
- App API:
/api/*(entries, stats, settings, api keys) - Widget API:
/v1/widget/today(separate route/flow) - API key format:
ftk_... - Send key as either:
Authorization: Bearer <api_key>X-API-Key: <api_key>
Notes:
- One API key per user is enforced. Generating a new key revokes/removes old keys.
- In
dev, requests without API key can still resolve toDEV_USER_EMAILfallback.
Security notes:
- Never commit API keys to git or paste them into shared logs.
- Prefer Cloudflare URL (
https) over plain HTTP endpoints. - Rotate keys if exposed; old key is revoked when a new one is generated.
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 food_tracker_cli-0.2.0.tar.gz.
File metadata
- Download URL: food_tracker_cli-0.2.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9aab1014d2b978f95be2eb64f6c3e9d11ed48928445a8f75e228c519fc7f9e90
|
|
| MD5 |
a45d1ea91d09192be1a8b7c6c0657cd2
|
|
| BLAKE2b-256 |
c42951887a4cb1b0fe89e6252279165c25acea67c36bbddbf6252abf02c4c291
|
Provenance
The following attestation bundles were made for food_tracker_cli-0.2.0.tar.gz:
Publisher:
pypi-publish.yml on Branchenprimus/food-tracker-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
food_tracker_cli-0.2.0.tar.gz -
Subject digest:
9aab1014d2b978f95be2eb64f6c3e9d11ed48928445a8f75e228c519fc7f9e90 - Sigstore transparency entry: 996997398
- Sigstore integration time:
-
Permalink:
Branchenprimus/food-tracker-cli@5af6bcc3f155140dd062bde8df94d6acf6e99b9b -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Branchenprimus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@5af6bcc3f155140dd062bde8df94d6acf6e99b9b -
Trigger Event:
push
-
Statement type:
File details
Details for the file food_tracker_cli-0.2.0-py3-none-any.whl.
File metadata
- Download URL: food_tracker_cli-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.0 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 |
9a421559204f6ffd4bd002b1d8c4949fb7607e2de5916dc2da19ecefa6bdc4ff
|
|
| MD5 |
ab31fe4161017b10d58553d036afdaf6
|
|
| BLAKE2b-256 |
e0713b453a481e8b888edc211e0ca297de72f4c0be962144c6713a6f32f42b1b
|
Provenance
The following attestation bundles were made for food_tracker_cli-0.2.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on Branchenprimus/food-tracker-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
food_tracker_cli-0.2.0-py3-none-any.whl -
Subject digest:
9a421559204f6ffd4bd002b1d8c4949fb7607e2de5916dc2da19ecefa6bdc4ff - Sigstore transparency entry: 996997454
- Sigstore integration time:
-
Permalink:
Branchenprimus/food-tracker-cli@5af6bcc3f155140dd062bde8df94d6acf6e99b9b -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Branchenprimus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@5af6bcc3f155140dd062bde8df94d6acf6e99b9b -
Trigger Event:
push
-
Statement type: