Skip to content

Latest commit

Β 

History

History
70 lines (51 loc) Β· 1.97 KB

File metadata and controls

70 lines (51 loc) Β· 1.97 KB

python-script-template

A batteries-included Python script boilerplate for quickly spinning up new projects.

Features

  • Environment management -- layered .env / .env.local loading via python-dotenv + pydantic-settings
  • HTTP client -- unified sync/async wrapper around httpx (lib/httpx_client.py)
  • Typed settings -- validated config with sensible defaults (config/settings.py)
  • Data directories -- data/input/ and data/output/ ready for file I/O scripts

Project Structure

.
β”œβ”€β”€ main.py                  # Entry point
β”œβ”€β”€ config/
β”‚   └── settings.py          # Pydantic-based settings (reads from .env)
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ dot_env_loader.py    # Layered .env loader
β”‚   └── httpx_client.py      # Sync/async HTTP client wrapper
β”œβ”€β”€ utils/                   # Utility functions
β”‚   └── http.py              # HTTP utility functions
β”œβ”€β”€ scripts/                 # Standalone helper scripts
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ input/               # Raw / source data
β”‚   └── output/              # Generated / processed data
β”œβ”€β”€ _docs/                   # Internal documentation
β”œβ”€β”€ .env.example             # Template for environment variables
└── pyproject.toml           # Project metadata & dependencies (uv)

Quick Start

# 1. Clone / use as template
gh repo create my-script --template code4mk/python-script-template
cd my-script

# 2. Install dependencies (requires uv)
uv sync

# 3. Set up environment variables
cp .env.example .env
# edit .env with your values

# 4. Run
uv run python main.py

Configuration

Environment variables are loaded in order:

  1. .env -- base config
  2. .env.local -- local overrides (gitignored)

Define your own settings in config/settings.py and access them anywhere:

from config.settings import settings

print(settings.db_host)

See _docs/ for detailed documentation on included utilities.

License

MIT