8.5 KiB
8.5 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is a Python project optimized for modern Python development. The project uses industry-standard tools and follows best practices for scalable application development.
Development Commands
Environment Management
python -m venv venv- Create virtual environmentsource venv/bin/activate(Linux/Mac) orvenv\Scripts\activate(Windows) - Activate virtual environmentdeactivate- Deactivate virtual environmentpip install -r requirements.txt- Install dependenciespip install -r requirements-dev.txt- Install development dependencies
Package Management
pip install <package>- Install a packagepip install -e .- Install project in development modepip freeze > requirements.txt- Generate requirements filepip-tools compile requirements.in- Compile requirements with pip-tools
Testing Commands
pytest- Run all testspytest -v- Run tests with verbose outputpytest --cov- Run tests with coverage reportpytest --cov-report=html- Generate HTML coverage reportpytest -x- Stop on first failurepytest -k "test_name"- Run specific test by namepython -m unittest- Run tests with unittest
Code Quality Commands
black .- Format code with Blackblack --check .- Check code formatting without changesisort .- Sort importsisort --check-only .- Check import sortingflake8- Run linting with Flake8pylint src/- Run linting with Pylintmypy src/- Run type checking with MyPy
Development Tools
python -m pip install --upgrade pip- Upgrade pippython -c "import sys; print(sys.version)"- Check Python versionpython -m site- Show Python site informationpython -m pdb script.py- Debug with pdb
Technology Stack
Core Technologies
- Python - Primary programming language (3.8+)
- pip - Package management
- venv - Virtual environment management
Common Frameworks
- Django - High-level web framework
- Flask - Micro web framework
- FastAPI - Modern API framework with automatic documentation
- SQLAlchemy - SQL toolkit and ORM
- Pydantic - Data validation using Python type hints
Data Science & ML
- NumPy - Numerical computing
- Pandas - Data manipulation and analysis
- Matplotlib/Seaborn - Data visualization
- Scikit-learn - Machine learning library
- TensorFlow/PyTorch - Deep learning frameworks
Testing Frameworks
- pytest - Testing framework
- unittest - Built-in testing framework
- pytest-cov - Coverage plugin for pytest
- factory-boy - Test fixtures
- responses - Mock HTTP requests
Code Quality Tools
- Black - Code formatter
- isort - Import sorter
- flake8 - Style guide enforcement
- pylint - Code analysis
- mypy - Static type checker
- pre-commit - Git hooks framework
Project Structure Guidelines
File Organization
src/
├── package_name/
│ ├── __init__.py
│ ├── main.py # Application entry point
│ ├── models/ # Data models
│ ├── views/ # Web views (Django/Flask)
│ ├── api/ # API endpoints
│ ├── services/ # Business logic
│ ├── utils/ # Utility functions
│ └── config/ # Configuration files
tests/
├── __init__.py
├── conftest.py # pytest configuration
├── test_models.py
├── test_views.py
└── test_utils.py
requirements/
├── base.txt # Base requirements
├── dev.txt # Development requirements
└── prod.txt # Production requirements
Naming Conventions
- Files/Modules: Use snake_case (
user_profile.py) - Classes: Use PascalCase (
UserProfile) - Functions/Variables: Use snake_case (
get_user_data) - Constants: Use UPPER_SNAKE_CASE (
API_BASE_URL) - Private methods: Prefix with underscore (
_private_method)
Python Guidelines
Type Hints
- Use type hints for function parameters and return values
- Import types from
typingmodule when needed - Use
Optionalfor nullable values - Use
Unionfor multiple possible types - Document complex types with comments
Code Style
- Follow PEP 8 style guide
- Use meaningful variable and function names
- Keep functions focused and single-purpose
- Use docstrings for modules, classes, and functions
- Limit line length to 88 characters (Black default)
Best Practices
- Use list comprehensions for simple transformations
- Prefer
pathliboveros.pathfor file operations - Use context managers (
withstatements) for resource management - Handle exceptions appropriately with try/except blocks
- Use
loggingmodule instead of print statements
Testing Standards
Test Structure
- Organize tests to mirror source code structure
- Use descriptive test names that explain the behavior
- Follow AAA pattern (Arrange, Act, Assert)
- Use fixtures for common test data
- Group related tests in classes
Coverage Goals
- Aim for 90%+ test coverage
- Write unit tests for business logic
- Use integration tests for external dependencies
- Mock external services in tests
- Test error conditions and edge cases
pytest Configuration
# pytest.ini or pyproject.toml
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = "--cov=src --cov-report=term-missing"
Virtual Environment Setup
Creation and Activation
# Create virtual environment
python -m venv venv
# Activate (Linux/Mac)
source venv/bin/activate
# Activate (Windows)
venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt
Requirements Management
- Use
requirements.txtfor production dependencies - Use
requirements-dev.txtfor development dependencies - Consider using
pip-toolsfor dependency resolution - Pin versions for reproducible builds
Django-Specific Guidelines
Project Structure
project_name/
├── manage.py
├── project_name/
│ ├── __init__.py
│ ├── settings/
│ ├── urls.py
│ └── wsgi.py
├── apps/
│ ├── users/
│ ├── products/
│ └── orders/
└── requirements/
Common Commands
python manage.py runserver- Start development serverpython manage.py migrate- Apply database migrationspython manage.py makemigrations- Create new migrationspython manage.py createsuperuser- Create admin userpython manage.py collectstatic- Collect static filespython manage.py test- Run Django tests
FastAPI-Specific Guidelines
Project Structure
src/
├── main.py # FastAPI application
├── api/
│ ├── __init__.py
│ ├── dependencies.py # Dependency injection
│ └── v1/
│ ├── __init__.py
│ └── endpoints/
├── core/
│ ├── __init__.py
│ ├── config.py # Settings
│ └── security.py # Authentication
├── models/
├── schemas/ # Pydantic models
└── services/
Common Commands
uvicorn main:app --reload- Start development serveruvicorn main:app --host 0.0.0.0 --port 8000- Start production server
Security Guidelines
Dependencies
- Regularly update dependencies with
pip list --outdated - Use
safetypackage to check for known vulnerabilities - Pin dependency versions in requirements files
- Use virtual environments to isolate dependencies
Code Security
- Validate input data with Pydantic or similar
- Use environment variables for sensitive configuration
- Implement proper authentication and authorization
- Sanitize data before database operations
- Use HTTPS for production deployments
Development Workflow
Before Starting
- Check Python version compatibility
- Create and activate virtual environment
- Install dependencies from requirements files
- Run type checking with
mypy
During Development
- Use type hints for better code documentation
- Run tests frequently to catch issues early
- Use meaningful commit messages
- Format code with Black before committing
Before Committing
- Run full test suite:
pytest - Check code formatting:
black --check . - Sort imports:
isort --check-only . - Run linting:
flake8 - Run type checking:
mypy src/