This document covers the code quality standards, development tools, and contribution workflow for the auth0-python SDK. It describes the pre-commit hooks, code style requirements, testing expectations, and procedures for submitting contributions.
For information about the CI/CD pipeline and automated security scanning, see CI/CD Pipeline and Security Scanning. For details on the build system and dependency management, see Build System and Dependencies.
The auth0-python SDK enforces strict code style standards using automated tooling. All code must pass multiple quality checks before being accepted.
The project uses four primary code quality tools, all configured as pre-commit hooks:
| Tool | Version | Purpose | Configuration |
|---|---|---|---|
black | 23.3.0 | Code formatting (opinionated) | Default settings |
flake8 | 5.0.4 | PEP 8 linting and style checking | Default settings |
isort | 5.11.5 | Import statement sorting | --profile black for compatibility |
pyupgrade | 3.3.2 | Python syntax modernization | --keep-runtime-typing for type hints |
Sources: .pre-commit-config.yaml9-29
Pre-commit hooks also enforce basic file hygiene:
Sources: .pre-commit-config.yaml2-7
Pre-commit Hook Execution Flow: Shows the sequential execution of hooks on every commit attempt. All hooks must pass for the commit to succeed.
Sources: .pre-commit-config.yaml1-38
To set up the pre-commit hooks in your local environment:
Once installed, the hooks automatically run on git commit. If any hook fails, the commit is blocked and you must fix the issues before retrying.
The poetry hooks ensure dependency files remain synchronized:
pyproject.toml syntax and consistencypoetry.lock when pyproject.toml changesrequirements.txt from poetry.lockThe poetry-export hook uses these arguments:
This generates a pip-compatible requirements file including development dependencies.
Sources: .pre-commit-config.yaml31-37
The SDK uses pytest as its test framework with coverage reporting via pytest-cov. Tests must be run through Poetry's virtual environment:
The coverage report shows:
--cov-report=term-missing)skip-covered)--cov-report=xml)Sources: .github/workflows/test.yml68
Test Dependency Architecture: The test suite requires both synchronous and asynchronous testing tools. responses mocks synchronous HTTP via requests, while aioresponses mocks asynchronous HTTP via aiohttp.
Sources: pyproject.toml36-44 requirements.txt2-34
The CI pipeline tests against multiple Python versions using a matrix strategy:
CI Test Matrix Configuration: All Python versions (3.9-3.12) run tests in parallel within isolated bubblewrap sandboxes. Only Python 3.10 uploads coverage to Codecov.
Sources: .github/workflows/test.yml39-85
The CI environment uses bubblewrap to run tests in a secure, isolated sandbox:
This ensures tests cannot:
Sources: .github/workflows/test.yml26-37
While there is no enforced minimum coverage percentage, contributors should:
RestClient and AsyncRestClientresponses for sync HTTP mocking, aioresponses for asyncCoverage reports highlight untested lines with --cov-report=term-missing:skip-covered, making it easy to identify gaps.
Sources: .github/workflows/test.yml68
Sources: pyproject.toml29 .github/workflows/test.yml41
Sources: .github/workflows/test.yml54-64
The project uses Poetry with locked dependencies for reproducible builds:
Dependency Lock and Resolution: poetry.lock contains exact versions and cryptographic hashes for all dependencies, ensuring reproducible installs. The pre-commit hook automatically regenerates requirements.txt when dependencies change.
Sources: pyproject.toml28-44 .pre-commit-config.yaml36-37
Key dependency notes:
cryptography >=43.0.1: Explicitly declared because pyjwt has a weak dependency on iturllib3 >=2.2.3: Explicitly declared because requests has a weak dependency on it>= to allow patch/minor updates while ensuring minimum versionsSources: pyproject.toml31-34
Complete Contribution Workflow: Code must pass local pre-commit hooks before being committed, then pass CI tests across all Python versions before being merged.
Sources: .pre-commit-config.yaml1-38 .github/workflows/test.yml1-85
Create a feature branch
Make your changes
Write tests
pytest-asyncio decoratorsRun tests locally
Commit your changes
black and isort) auto-fix issues; just git add the changes and retryPush to your fork
Open a pull request
When contributing new code, follow these organizational patterns:
Authentication API Components (in auth0/authentication/):
AuthenticationBase classself.client (RestClient instance) for HTTP requestsManagement API Endpoints (in auth0/management/):
RestClient instance in __init__Async Support:
auth0/asyncify.py_async suffix for async method namesSources: Based on architectural patterns described in Core Architecture
| Hook | Common Issue | Fix |
|---|---|---|
black | Code formatting doesn't match | Hook auto-fixes; just git add and retry |
flake8 | Line too long (>88 chars) | Break into multiple lines or use implicit string concatenation |
isort | Import order incorrect | Hook auto-fixes; just git add and retry |
pyupgrade | Outdated syntax (e.g., % formatting) | Hook auto-fixes to modern syntax; review and accept |
poetry-lock | poetry.lock out of sync | Hook auto-updates; just git add poetry.lock and retry |
trailing-whitespace | Extra spaces at line endings | Hook auto-fixes; just git add and retry |
Sources: .pre-commit-config.yaml1-38
Some flake8 errors require manual intervention:
Run poetry run flake8 . to see detailed error messages with line numbers.
Tests are located in the auth0/test/ directory, organized by component:
test_authentication.py: Authentication API teststest_management/: Management API endpoint teststest_async*.py: Async-specific teststest_rest.py: HTTP client testsUse descriptive test names
Mock HTTP responses appropriately
Test error cases
Use pytest fixtures for common setup
Sources: General testing best practices aligned with CI configuration in .github/workflows/test.yml68
Refresh this wiki