FAQ
Frequently asked questions about the Cookiecutter Python Package template.
General Questions
What is this template for?
This template helps you create modern Python packages with best practices built-in. It's designed for: - Python libraries and packages - Command-line applications - Web APIs and services - Data science projects - Any Python project that needs professional structure
How is this different from other Python templates?
This template focuses on: - Modern tooling: Uses latest tools like Ruff, uv, and modern GitHub Actions - Flexibility: Choose only the tools you need - Performance: Emphasizes fast tools (Ruff vs flake8+black+isort) - Best practices: Incorporates years of Python packaging experience - Documentation: Comprehensive guides and examples
Do I need to use all the tools?
No! The template is designed to be modular. You can: - Start with minimal setup (just Ruff + pytest) - Add tools gradually as your project grows - Skip tools you don't need or want to learn yet
Tool-Specific Questions
Why Ruff instead of flake8 + black + isort?
Ruff advantages: - 10-100x faster than traditional tools - Single tool replaces multiple tools - Less configuration needed - Same results with better performance - Active development and rapid improvements
When to stick with traditional tools: - Existing projects with extensive custom configurations - Team strongly prefers separate tools - Need specific plugins not available in Ruff
Should I use uv or pip?
Use uv when: - You want the fastest dependency resolution - You're starting a new project - You want modern Python tooling
Use pip when: - Working with existing projects - Team is not ready to adopt new tools - You need specific pip features not in uv
You can always switch later - both use the same requirements.txt
and pyproject.toml
formats.
MkDocs vs Sphinx - which should I choose?
Choose MkDocs when: - You prefer writing in Markdown - You want a modern, clean theme out of the box - Your documentation is primarily user-focused - You want quick setup and deployment
Choose Sphinx when: - You need advanced cross-referencing - You want to generate PDF documentation - You're working on a large, complex project - You need the Python ecosystem standard
Tox vs Nox - what's the difference?
Tox: - INI-based configuration - Mature and widely adopted - Great for standard testing scenarios
Nox: - Python-based configuration - More flexible and programmable - Easier to customize for complex scenarios
Recommendation: Start with Tox for simplicity, move to Nox if you need more flexibility.
Project Setup Questions
What Python versions should I support?
Current recommendations (as of 2024): - Minimum: Python 3.9 (still has security support) - Recommended: Python 3.10+ (better error messages, match statements) - Latest: Python 3.12 (performance improvements)
Consider your audience: - Libraries: Support 3.9+ for wider compatibility - Applications: Can use newer versions (3.11+) - Enterprise: Check company standards
How do I handle dependencies?
For libraries (distributed on PyPI):
# Use minimum versions with flexibility
dependencies = [
"requests>=2.25.0",
"click>=8.0.0,<9.0.0",
]
For applications (deployed directly):
Should I include a CLI interface?
Include CLI when: - Your package solves a problem users might want to run from command line - You're building a tool or utility - You want to provide easy access to main functionality
Skip CLI when: - Building a pure library - Functionality doesn't make sense as command-line tool - API-only package
Development Workflow Questions
How do I set up my development environment?
# 1. Clone your generated project
cd your-project
# 2. Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
# 3. Install in development mode
pip install -e .[dev]
# 4. Set up pre-commit (if enabled)
pre-commit install
# 5. Run tests to verify setup
pytest
What's the recommended development workflow?
# Daily workflow
git pull origin main
make test # or pytest
make lint # or ruff check src tests
make format # or ruff format src tests
# Before committing (pre-commit handles this automatically)
make type-check # or mypy src
make security-check # or bandit -r src && safety check
# Commit (pre-commit runs automatically)
git add .
git commit -m "feat: add new feature"
git push
How do I add new dependencies?
For runtime dependencies:
# Edit pyproject.toml
[project]
dependencies = [
"existing-package>=1.0.0",
"new-package>=2.0.0", # Add here
]
For development dependencies:
Then reinstall:
Testing Questions
How do I run tests?
# Basic test run
pytest
# With coverage
pytest --cov=src
# Specific test file
pytest tests/test_core.py
# Specific test function
pytest tests/test_core.py::test_function_name
# Verbose output
pytest -v
# Stop on first failure
pytest -x
How do I test CLI applications?
# tests/test_cli.py
from typer.testing import CliRunner
from your_package.cli import app
runner = CliRunner()
def test_cli_basic():
"""Test basic CLI functionality."""
result = runner.invoke(app, ["command", "--option", "value"])
assert result.exit_code == 0
assert "expected output" in result.stdout
How do I mock external dependencies?
# Using pytest-mock
def test_with_mock(mocker):
"""Test with mocked external call."""
mock_requests = mocker.patch('your_package.core.requests.get')
mock_requests.return_value.json.return_value = {"key": "value"}
result = your_function()
assert result == expected_result
mock_requests.assert_called_once()
# Using unittest.mock
from unittest.mock import patch, Mock
@patch('your_package.core.external_service')
def test_with_patch(mock_service):
"""Test with patched service."""
mock_service.return_value = Mock()
mock_service.return_value.process.return_value = "result"
result = your_function()
assert result == "processed: result"
Deployment Questions
How do I publish to PyPI?
Manual approach:
Automated approach (with GitHub Actions):
1. Tag your release: git tag v1.0.0
2. Push the tag: git push origin v1.0.0
3. GitHub Actions automatically builds and publishes
How do I handle versioning?
Manual versioning:
Automatic versioning (with semantic-release):
- Use conventional commits (feat:
, fix:
, breaking:
)
- Semantic-release automatically increments version
- Generates changelog automatically
How do I deploy documentation?
GitHub Pages (automatic with MkDocs):
Read the Docs: 1. Connect your GitHub repository 2. Enable the webhook 3. Documentation builds automatically on push
Troubleshooting
Pre-commit hooks are too slow
# .pre-commit-config.yaml
# Add to slow hooks:
- id: mypy
pass_filenames: false
args: [--cache-dir=.mypy_cache]
Import errors in tests
# Make sure you installed in development mode
pip install -e .
# Check your PYTHONPATH includes src/
export PYTHONPATH="${PYTHONPATH}:${PWD}/src"
CI fails but local tests pass
Common causes: - Different Python versions - Missing dependencies in CI - Platform-specific issues - Environment variables not set
Solutions: - Test locally with same Python version as CI - Check CI logs for specific errors - Ensure all dependencies are declared - Add debugging output to CI
Tool configuration conflicts
Ruff vs other formatters:
# Don't use black if using ruff format
# Don't use isort if using ruff
[tool.ruff]
select = ["E", "W", "F", "I"] # I = isort
MyPy finding issues not caught locally:
Getting Help
Where can I get support?
- GitHub Issues: Template repository issues
- Discussions: GitHub Discussions for questions and ideas
- Community: Python Discord, Reddit r/Python
- Documentation: Tool-specific documentation
How do I contribute to the template?
- Fork the repository
- Create a feature branch
- Test your changes with multiple configurations
- Update documentation if needed
- Submit a pull request
How do I report bugs?
- Check existing issues first
- Provide minimal reproduction case
- Include cookiecutter configuration used
- Include error messages and logs
- Specify your operating system and Python version
This FAQ should cover most common questions. If you have additional questions, please check the documentation or open an issue!