|
| 1 | +# deps-pypi |
| 2 | + |
| 3 | +[](https://crates.io/crates/deps-pypi) |
| 4 | +[](https://docs.rs/deps-pypi) |
| 5 | +[](https://codecov.io/gh/bug-ops/deps-lsp) |
| 6 | +[](../../LICENSE) |
| 7 | + |
| 8 | +PyPI/Python support for deps-lsp. |
| 9 | + |
| 10 | +This crate provides parsing, validation, and registry client functionality for Python dependency management in `pyproject.toml` files, supporting both PEP 621 and Poetry formats. |
| 11 | + |
| 12 | +## Features |
| 13 | + |
| 14 | +- **PEP 621 Support**: Parse `[project.dependencies]` and `[project.optional-dependencies]` |
| 15 | +- **Poetry Support**: Parse `[tool.poetry.dependencies]` and `[tool.poetry.group.*.dependencies]` |
| 16 | +- **PEP 508 Parsing**: Handle complex dependency specifications with extras and markers |
| 17 | +- **PEP 440 Versions**: Validate and compare Python version specifiers |
| 18 | +- **PyPI API Client**: Fetch package metadata from PyPI JSON API with HTTP caching |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +```rust |
| 23 | +use deps_pypi::{PypiParser, PypiRegistry}; |
| 24 | +use deps_core::PackageRegistry; |
| 25 | + |
| 26 | +// Parse pyproject.toml |
| 27 | +let content = std::fs::read_to_string("pyproject.toml")?; |
| 28 | +let parser = PypiParser::new(); |
| 29 | +let dependencies = parser.parse(&content)?; |
| 30 | + |
| 31 | +// Fetch versions from PyPI |
| 32 | +let registry = PypiRegistry::new(); |
| 33 | +let versions = registry.get_versions("requests").await?; |
| 34 | +``` |
| 35 | + |
| 36 | +## Supported Formats |
| 37 | + |
| 38 | +### PEP 621 (Standard) |
| 39 | + |
| 40 | +```toml |
| 41 | +[project] |
| 42 | +dependencies = [ |
| 43 | + "requests>=2.28.0,<3.0", |
| 44 | + "flask[async]>=3.0", |
| 45 | + "numpy>=1.24; python_version>='3.9'", |
| 46 | +] |
| 47 | + |
| 48 | +[project.optional-dependencies] |
| 49 | +dev = ["pytest>=7.0", "mypy>=1.0"] |
| 50 | +``` |
| 51 | + |
| 52 | +### Poetry |
| 53 | + |
| 54 | +```toml |
| 55 | +[tool.poetry.dependencies] |
| 56 | +python = "^3.9" |
| 57 | +requests = "^2.28.0" |
| 58 | +flask = {version = "^3.0", extras = ["async"]} |
| 59 | + |
| 60 | +[tool.poetry.group.dev.dependencies] |
| 61 | +pytest = "^7.0" |
| 62 | +mypy = "^1.0" |
| 63 | +``` |
| 64 | + |
| 65 | +## License |
| 66 | + |
| 67 | +MIT |
0 commit comments