Remove nbqa in favor of ruff's native Jupyter support (v0.6.0+). Replace papermill with nbconvert due to uv dependency resolution issues. Also remove S105/S106 ignores to enforce better security practices. - Update pyproject.toml to use ruff v0.12.12 with native notebook support - Replace papermill with nbconvert for notebook execution - Remove nbqa from all dependencies and pre-commit hooks - Update GitHub Actions workflows to use ruff directly - Remove hardcoded password ignores for better security - Update documentation to reflect simplified setup - Add dummy package structure for hatchling build system 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
5.4 KiB
Contributing to Anthropic Cookbook
Thank you for your interest in contributing to the Anthropic Cookbook! This guide will help you get started with development and ensure your contributions meet our quality standards.
Development Setup
Prerequisites
- Python 3.11 or higher
- uv package manager (recommended) or pip
Quick Start
-
Install uv (recommended package manager):
curl -LsSf https://astral.sh/uv/install.sh | shOr with Homebrew:
brew install uv -
Clone the repository:
git clone https://github.com/anthropics/anthropic-cookbook.git cd anthropic-cookbook -
Set up the development environment:
# Create virtual environment and install dependencies uv sync --all-extras # Or with pip: pip install -e ".[dev]" -
Install pre-commit hooks:
uv run pre-commit install # Or: pre-commit install -
Set up your API key:
cp .env.example .env # Edit .env and add your Anthropic API key
Quality Standards
This repository uses automated tools to maintain code quality:
The Notebook Validation Stack
- papermill: Parameterized notebook execution for testing
- ruff: Fast Python linter and formatter with native Jupyter support
- nbstripout: Keeps notebooks clean in git (removes outputs)
Before Committing
-
Clean notebook outputs:
uv run nbstripout skills/**/*.ipynb -
Run quality checks:
uv run ruff check skills/ --fix uv run ruff format skills/ uv run python scripts/validate_notebooks.py uv run python scripts/check_models.py -
Test notebook execution (optional, requires API key):
uv run papermill skills/classification/guide.ipynb test.ipynb \ -p model "claude-3-5-haiku-latest" \ -p test_mode true \ -p max_tokens 10
Pre-commit Hooks
Pre-commit hooks will automatically run before each commit to ensure code quality:
- Strip notebook outputs
- Format code with ruff
- Validate notebook structure
- Check for hardcoded API keys
- Validate Claude model usage
If a hook fails, fix the issues and try committing again.
Contribution Guidelines
Notebook Best Practices
-
Use environment variables for API keys:
import os api_key = os.environ.get("ANTHROPIC_API_KEY") -
Use current Claude models:
- For examples:
claude-3-5-haiku-latest(fast and cheap) - For powerful tasks:
claude-opus-4-1 - Check allowed models in
scripts/allowed_models.py
- For examples:
-
Keep notebooks focused:
- One concept per notebook
- Clear explanations and comments
- Include expected outputs as markdown cells
-
Test your notebooks:
- Ensure they run from top to bottom without errors
- Use minimal tokens for example API calls
- Include error handling
Git Workflow
-
Create a feature branch:
git checkout -b <your-name>/<feature-description> # Example: git checkout -b alice/add-rag-example -
Use conventional commits:
# Format: <type>(<scope>): <subject> # Types: feat # New feature fix # Bug fix docs # Documentation style # Formatting refactor # Code restructuring test # Tests chore # Maintenance ci # CI/CD changes # Examples: git commit -m "feat(skills): add text-to-sql notebook" git commit -m "fix(api): use environment variable for API key" git commit -m "docs(readme): update installation instructions" -
Keep commits atomic:
- One logical change per commit
- Write clear, descriptive messages
- Reference issues when applicable
-
Push and create PR:
git push -u origin your-branch-name gh pr create # Or use GitHub web interface
Pull Request Guidelines
- PR Title: Use conventional commit format
- Description: Include:
- What changes you made
- Why you made them
- How to test them
- Related issue numbers
- Keep PRs focused: One feature/fix per PR
- Respond to feedback: Address review comments promptly
Testing
Local Testing
Run the validation suite:
# Check all notebooks
uv run python scripts/validate_notebooks.py
# Check model usage
uv run python scripts/check_models.py
# Run pre-commit on all files
uv run pre-commit run --all-files
CI/CD
Our GitHub Actions workflows will automatically:
- Validate notebook structure
- Check for hardcoded secrets
- Lint code with ruff
- Test notebook execution (for maintainers)
- Check links
- Validate Claude model usage
External contributors will have limited API testing to conserve resources.
Getting Help
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Discord: Anthropic Discord
Security
- Never commit API keys or secrets
- Use environment variables for sensitive data
- Report security issues privately to security@anthropic.com
License
By contributing, you agree that your contributions will be licensed under the same license as the project (MIT License).