Contributing & Developer Tools
Relevant source files
The following files were used as context for generating this wiki page:
The python-multipart project utilizes a standardized set of development scripts, linting tools, and testing frameworks to maintain high code quality and security. The project infrastructure is built around the hatchling build system and leverages tools like ruff, mypy, and pytest for validation.
Developers are encouraged to use the provided scripts in the scripts/ directory, which follow the "Scripts to Rule Them All" pattern. These scripts automate dependency installation, testing, and code formatting to ensure consistency across environments.
Development Environment and Tooling
The project defines its development environment and dependencies within pyproject.toml. It uses hatchling as the build backend and manages various dependency groups for development, testing, and documentation.
Dependency Management
Development dependencies are categorized under the dev group in pyproject.toml. This includes testing suites, coverage tools, and static analyzers.
| Tool Category | Tools Used |
|---|---|
| Testing | pytest, pytest-cov, pytest-codspeed, pytest-timeout |
| Linting/Formatting | ruff |
| Type Checking | mypy, types-PyYAML |
| Documentation | mkdocs, mkdocs-material, mkdocstrings-python |
| Fuzzing | atheris |
Sources: pyproject.toml:50-74
Standardized Development Scripts
The project provides a set of shell scripts to streamline common development tasks.
scripts/setup: Installs all necessary project dependencies.scripts/test: Executes the fullpytestsuite.scripts/lint: Automatically runs code formatting viaruff.scripts/check: Runsruffin check mode and executes themypytype checker.scripts/rename: Validates that backward-compatibility for themultipartpackage name remains functional.
Sources: scripts/README.md:3-7
Testing Architecture
Testing is central to the project, which enforces 100% code coverage. The test suite includes unit tests, integration tests against HTTP data samples, and automated fuzzing.
Test Execution Flow
The following diagram illustrates the typical developer workflow for validating changes:
The diagram shows the sequential validation steps from dependency setup to final fuzz testing.
Sources: scripts/README.md:1-10, pyproject.toml:135-140
Unit and Functional Testing
Tests are primarily located in tests/test_multipart.py. The suite uses unittest and pytest to verify individual parsers (MultipartParser, QuerystringParser, OctetStreamParser) and helper functions.
Key testing features:
- HTTP Dataset Testing: The suite reads sample
.httpand.yamlfiles fromtests/test_data/http/to validate parser behavior against real-world scenarios. - Fuzzing Simulation: The suite includes internal fuzzing tests that randomly mutate request bodies to check for state machine stability.
- Boundary Validation: Specific tests ensure the parser correctly handles edge cases like preamble data before the first boundary and epilogue data after the last boundary.
Sources: tests/test_multipart.py:655-680, tests/test_multipart.py:734-750
Security and Fuzzing
The project implements coverage-guided fuzz testing to discover edge-case bugs and security vulnerabilities.
Fuzz Testing with Atheris
Fuzzing is located in the fuzz/ directory and utilizes the Atheris library. Fuzzers target different entry points of the library:
fuzz_form.py: Targets the high-levelparse_formandcreate_form_parserAPIs.fuzz_multipart_parser.py: Directly targets theMultipartParserclass with various boundary lengths and chunked write scenarios.
Sources: fuzz/README.md:9-12, fuzz/fuzz_form.py:53-65, fuzz/fuzz_multipart_parser.py:68-76
Vulnerability Reporting
Security issues should not be reported through public GitHub issues. Instead, contributors should use the "Report a vulnerability" button under the repository's Security tab to submit a private report.
Sources: SECURITY.md:3-7
Documentation and CI/CD
Documentation is managed via MkDocs with the material theme. The configuration is defined in mkdocs.yml, utilizing mkdocstrings to generate API references directly from Python source code.
Documentation Structure
- Introduction:
index.md - API Reference:
api.md(automated viamkdocstrings) - Changelog:
changelog.md
Sources: mkdocs.yml:54-57
Static Analysis Configuration
The project uses ruff for both linting and formatting. The configuration in pyproject.toml sets a line length of 120 and enforces specific linting rules (E, F, I, FA). Type checking via mypy is set to strict = true.
Sources: pyproject.toml:113-130
The combination of standardized scripts, strict type checking, comprehensive test datasets, and automated fuzzing ensures that python-multipart remains a robust and stable streaming parser for the Python ecosystem.