This repository contains a collection of Python projects that exemplify common operations and design patterns in Python. It serves as a quick reference guide with practical examples (recipes) of how to implement frequently used libraries and design patterns in Python 3.11+.
- Generics in Python
- Reading and writing JSON
- Reading and writing YAML
- Handling HTTP Requests
- Data classes
- Error Handling and Logging
- Context Managers (with statement)
- Decorators
- Reading and writing from/to Postgres
- Reading and writing from/to MongoDB
- Reading and writing from/to Redis
- Type Hinting and Static Type Checking
- Functional Programming
- Packaging and Distribution
- API Development with FastAPI
- Concurrent Processing (Threading vs Multiprocessing)
- Property-Based Testing
- Event-Driven Programming
- Asynchronous Programming (asyncio)
- Metaprogramming
- Performance Optimization
- Memory Management
- Cython Integration
Each recipe follows a consistent structure:
.
├── <pattern_name>/
│ ├── README.md
│ ├── <pattern_name>/
│ ├── tests/
│ ├── main.py
│ └── requirements.txt
Where:
- README.md contains detailed notes about the recipe, including implementation details and usage examples
- main.py provides a demonstration of the pattern in action
- tests/ contains unit tests that validate the implementation
- Python 3.11+
- pip (Python package installer)
- Go Task (optional, for task automation)
- Clone the repository
- Install development dependencies:
pip install -r requirements-dev.txt
- Set up Git hooks (optional, but recommended):
./hooks/install-hooks.sh
This project uses Go Task to automate common development tasks:
task setup-root-venv
: Creates and sets up the root virtual environmenttask setup-recipe-venv RECIPE=<name>
: Sets up a recipe-specific virtual environmenttask format RECIPE=<name>
: Formats code using blacktask lint RECIPE=<name>
: Runs flake8 lintingtask test RECIPE=<name>
: Runs tests for a specific recipetask validate-recipe RECIPE=<name>
: Runs format, lint, and test for a recipetask validate-all
: Validates all recipes in the repository
This project uses several tools to maintain code quality:
- black: Code formatting
- flake8: Code linting
- pytest: Testing framework
- pytest-cov: Test coverage reporting
- pre-commit: Runs black and flake8 on staged Python files
- pre-push: Runs tests for modified recipes before pushing
The project uses GitHub Actions for CI, which runs on every push to main and pull requests:
- Runs tests against Python 3.11 and 3.12
- Enforces code formatting with black
- Runs linting with flake8
- Requires 70% test coverage
- Reports coverage to Codecov with component-based tracking:
- Each recipe is tracked as a separate component
- Cross-cutting components for tests and core implementations
- Coverage status displayed in PR comments