High-performance Python requirements.txt parser and editor written in Go. Supports complete pip specification with powerful editing capabilities.
π Complete Documentation | β‘ Quick Start | π‘ Examples
URL: https://scagogogo.github.io/python-requirements-parser/
We provide comprehensive online documentation including:
π Documentation | π Link | π Description |
---|---|---|
π Home | Visit Home | Project overview and quick start |
β‘ Quick Start | Quick Start | Get up and running in minutes |
π API Reference | API Docs | Complete API reference manual |
π Supported Formats | Formats | All supported requirements.txt formats |
π Performance Guide | Performance | Production best practices |
π‘ Examples | Examples | Progressive examples and tutorials |
- π Multi-language support - English and Simplified Chinese
- π± Mobile-friendly - Responsive design for all devices
- π Full-text search - Find what you need quickly
- π¨ Syntax highlighting - Beautiful code examples
- π Interactive examples - Copy-paste ready code
- π Performance benchmarks - Real-world performance data
go get github.com/scagogogo/python-requirements-parser
package main
import (
"fmt"
"log"
"github.com/scagogogo/python-requirements-parser/pkg/parser"
"github.com/scagogogo/python-requirements-parser/pkg/editor"
)
func main() {
// Parse requirements.txt
p := parser.New()
reqs, err := p.ParseFile("requirements.txt")
if err != nil {
log.Fatal(err)
}
// Edit with position-aware editor (minimal diff)
editor := editor.NewPositionAwareEditor()
doc, err := editor.ParseRequirementsFile(content)
if err != nil {
log.Fatal(err)
}
// Update package versions
updates := map[string]string{
"flask": "==2.0.1",
"django": ">=3.2.13",
"requests": ">=2.28.0",
}
err = editor.BatchUpdateVersions(doc, updates)
if err != nil {
log.Fatal(err)
}
// Serialize with minimal changes
result := editor.SerializeToString(doc)
fmt.Println(result)
}
- VersionEditor - Basic text-based editing
- VersionEditorV2 - Parser-based reconstruction editing
- PositionAwareEditor - Position-based minimal diff editing β
Operation | Time | Memory | Allocations |
---|---|---|---|
Parse 100 packages | 357 Β΅s | 480 KB | 4301 allocs |
Single update | 67.67 ns | 8 B | 1 alloc |
Batch update (10 packages) | 374.1 ns | 0 B | 0 allocs |
Serialize 100 packages | 4.3 Β΅s | 8.2 KB | 102 allocs |
The PositionAwareEditor achieves 50% fewer changes compared to traditional editors:
- Real-world test: 68-line requirements.txt file
- PositionAwareEditor: 5.9% change rate (4/68 lines)
- Traditional editor: 11.8% change rate (8/68 lines)
Perfect preservation of:
- β Comments and formatting
- β
VCS dependencies (
git+https://...
) - β
URL dependencies (
https://...
) - β
File references (
-r requirements-dev.txt
) - β
Environment markers (
; python_version >= "3.7"
) - β
Global options (
--index-url https://...
)
Full support for all pip-compatible formats:
# Basic dependencies
flask==2.0.1
django>=3.2.0,<4.0.0
requests~=2.25.0
# Dependencies with extras
django[rest,auth]>=3.2.0
uvicorn[standard]>=0.15.0
# Environment markers
pywin32>=1.0; platform_system == "Windows"
dataclasses>=0.6; python_version < "3.7"
# VCS dependencies
git+https://github.com/user/project.git#egg=project
-e git+https://github.com/dev/project.git@develop#egg=project
# URL dependencies
https://example.com/package.whl
http://mirrors.aliyun.com/pypi/web/package-1.0.0.tar.gz
# File references
-r requirements-dev.txt
-c constraints.txt
# Global options
--index-url https://pypi.example.com
--extra-index-url https://private.pypi.com
--trusted-host pypi.example.com
# Hash verification
flask==2.0.1 --hash=sha256:abcdef1234567890
- π Security Updates - Automated vulnerability patching
- π¦ Package Management - Dependency analysis and updates
- π CI/CD Pipelines - Automated dependency management
- π οΈ Development Tools - IDE plugins and package managers
- π Dependency Analysis - Project dependency auditing
- 10x faster parsing performance
- Lower memory usage for large files
- No Python runtime dependency
- Better error handling and recovery
- Complete pip specification support
- Three editing modes for different use cases
- Position-aware editing for minimal diffs
- Comprehensive test coverage (100+ test cases)
- Production-ready with real-world validation
# Run all tests
go test ./...
# Run with coverage
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
# Run benchmarks
go test -bench=. ./...
# Run CI simulation locally
make ci-full
We welcome contributions! Please see our Contributing Guide for details.
# Clone the repository
git clone https://github.com/scagogogo/python-requirements-parser.git
cd python-requirements-parser
# Install dependencies
go mod download
# Run tests
make test
# Run all checks
make ci-full
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by Python's pip and setuptools
- Built with Go's excellent standard library
- Documentation powered by VitePress
β Star us on GitHub if this project helped you! β