|
1 | 1 | # PyDepsDev |
2 | 2 |
|
3 | | -A Python library for interacting with the Deps.dev API. Easily fetch package, version, and project data from the API. |
| 3 | +A Python library for interacting with Open Source Insights API (deps.dev). |
| 4 | +Easily fetch package, version, project, advisory, container, and PURL data—and leverage automatic name normalization and hash encoding. |
4 | 5 |
|
5 | 6 | ## Table of Contents |
6 | | -- [Installation](#installation) |
7 | | -- [Usage](#usage) |
8 | | - - [Initialization](#initialization) |
9 | | - - [Fetching Data](#fetching-data) |
10 | | -- [Contributing](#contributing) |
11 | | -- [License](#license) |
12 | 7 |
|
13 | | -## Installation |
| 8 | +- [Installation](#installation) |
| 9 | +- [Quick Start](#quick-start) |
| 10 | +- [Name Normalization & Hash Encoding](#name-normalization--hash-encoding) |
| 11 | +- [Endpoints](#endpoints) |
| 12 | + - [Package & Version](#package--version) |
| 13 | + - [Batch Version Queries](#batch-version-queries) |
| 14 | + - [Requirements, Dependencies & Dependents](#requirements-dependencies--dependents) |
| 15 | + - [Capabilities & Similarly-Named](#capabilities--similarly-named) |
| 16 | + - [Project](#project) |
| 17 | + - [Advisories](#advisories) |
| 18 | + - [PURL Lookup](#purl-lookup) |
| 19 | + - [Container Images](#container-images) |
| 20 | +- [Contributing](#contributing) |
| 21 | +- [License](#license) |
14 | 22 |
|
15 | | -To install `pydepsdev`, simply run: |
| 23 | +## Installation |
16 | 24 |
|
17 | 25 | ```bash |
18 | | -pip3 install pydepsdev |
| 26 | +pip install pydepsdev |
19 | 27 | ``` |
20 | 28 |
|
21 | | -## Usage |
| 29 | +## Quick Start |
| 30 | + |
| 31 | +```python |
| 32 | +import asyncio |
| 33 | +from pydepsdev.api import DepsdevAPI |
| 34 | + |
| 35 | +async def main(): |
| 36 | + # Simple init |
| 37 | + api = DepsdevAPI() |
| 38 | + |
| 39 | + # …use api methods… |
22 | 40 |
|
23 | | -### Initialization |
| 41 | + await api.close() |
| 42 | + |
| 43 | +asyncio.run(main()) |
| 44 | +``` |
24 | 45 |
|
25 | | -Start by importing the library and initializing the main class: |
| 46 | +Or use as an async context manager: |
26 | 47 |
|
27 | 48 | ```python |
28 | | -from pydepsdev import DepsdevAPI |
| 49 | +import asyncio |
| 50 | +from pydepsdev.api import DepsdevAPI |
29 | 51 |
|
30 | | -api = DepsdevAPI() |
| 52 | +async def main(): |
| 53 | + async with DepsdevAPI() as api: |
| 54 | + pkg_info = await api.get_package("npm", "foo") |
| 55 | + print(pkg_info) |
| 56 | + |
| 57 | +asyncio.run(main()) |
31 | 58 | ``` |
32 | 59 |
|
33 | | -### Fetching Data |
| 60 | +## Name Normalization & Hash Encoding |
| 61 | + |
| 62 | +- **System names** are case‐insensitive but always sent uppercase. |
| 63 | +- **NuGet** package names are lowercased. |
| 64 | +- **PyPI** package names are normalized per [PEP 503]. |
| 65 | +- When you call `query_package_versions(hash_type, hash_value, …)`, your `hash_value` is automatically Base64‐encoded before sending. |
| 66 | + |
| 67 | +## Endpoints |
| 68 | + |
| 69 | +### Package & Version |
34 | 70 |
|
35 | | -The library provides methods that correspond to different endpoints in the Deps.dev API. Here's a breakdown of each method and how to use them: |
| 71 | +```python |
| 72 | +# Get basic package info + versions list |
| 73 | +await api.get_package(system_name: str, package_name: str) |
| 74 | + |
| 75 | +# Get metadata for a specific version |
| 76 | +await api.get_version(system_name: str, package_name: str, version: str) |
| 77 | +``` |
36 | 78 |
|
37 | | -1. **Get Package Information** |
| 79 | +### Batch Version Queries |
38 | 80 |
|
39 | | - Fetch package details including available versions. |
| 81 | +```python |
| 82 | +# One page (up to 5000) of versions |
| 83 | +await api.get_version_batch( |
| 84 | + [(system, pkg, ver), …], |
| 85 | + page_token: Optional[str] = None |
| 86 | +) |
| 87 | + |
| 88 | +# Retrieve ALL pages for a batch |
| 89 | +await api.get_all_versions_batch( |
| 90 | + [(system, pkg, ver), …] |
| 91 | +) |
| 92 | +``` |
40 | 93 |
|
41 | | - ```python |
42 | | - package_info = await api.get_package("system_name", "package_name") |
43 | | - ``` |
| 94 | +### Requirements, Dependencies & Dependents |
44 | 95 |
|
45 | | -2. **Get Version Information** |
| 96 | +```python |
| 97 | +# NuGet only |
| 98 | +await api.get_requirements("NuGet", "package_name", "version") |
46 | 99 |
|
47 | | - Fetch detailed information about a specific package version. |
| 100 | +# Any supported system |
| 101 | +await api.get_dependencies(system_name, package_name, version) |
48 | 102 |
|
49 | | - ```python |
50 | | - version_info = await api.get_version("system_name", "package_name", "version_number") |
51 | | - ``` |
| 103 | +# Dependent counts |
| 104 | +await api.get_dependents(system_name, package_name, version) |
| 105 | +``` |
52 | 106 |
|
53 | | -3. **Get Requirements** |
| 107 | +### Capabilities & Similarly-Named |
54 | 108 |
|
55 | | - Return the requirements for a specific package version. (Note: Only available for NuGet.) |
| 109 | +```python |
| 110 | +# Go only |
| 111 | +await api.get_capabilities("Go", "module_path", "version") |
56 | 112 |
|
57 | | - ```python |
58 | | - requirements = await api.get_requirements("NuGet", "package_name", "version_number") |
59 | | - ``` |
| 113 | +# Find similarly-named packages |
| 114 | +await api.get_similarly_named_packages(system_name, package_name) |
| 115 | +``` |
60 | 116 |
|
61 | | -4. **Get Dependencies** |
| 117 | +### Query Package Versions |
62 | 118 |
|
63 | | - Fetch the resolved dependency graph for a specific package version. |
| 119 | +```python |
| 120 | +# By hash (hash.value is auto base64‐encoded) |
| 121 | +await api.query_package_versions( |
| 122 | + hash_type: str, # e.g. "SHA256" |
| 123 | + hash_value: str, # raw hex or bytes |
| 124 | + version_system: Optional[str] = None, |
| 125 | + version_name: Optional[str] = None, |
| 126 | + version: Optional[str] = None, |
| 127 | +) |
| 128 | +``` |
64 | 129 |
|
65 | | - ```python |
66 | | - dependencies = await api.get_dependencies("system_name", "package_name", "version_number") |
67 | | - ``` |
| 130 | +### Project |
68 | 131 |
|
69 | | -5. **Get Project Information** |
| 132 | +```python |
| 133 | +# Single project metadata |
| 134 | +await api.get_project(project_id: str) |
70 | 135 |
|
71 | | - Retrieve details about projects hosted by platforms like GitHub, GitLab, or BitBucket. |
| 136 | +# One page of project batch |
| 137 | +await api.get_project_batch( |
| 138 | + [project_id1, project_id2, …], |
| 139 | + page_token: Optional[str] = None |
| 140 | +) |
72 | 141 |
|
73 | | - ```python |
74 | | - project_info = await api.get_project("project_id") |
75 | | - ``` |
| 142 | +# Retrieve all pages |
| 143 | +await api.get_all_projects_batch([…]) |
76 | 144 |
|
77 | | -6. **Get Project Package Versions** |
| 145 | +# List package versions derived from a project |
| 146 | +await api.get_project_package_versions(project_id: str) |
| 147 | +``` |
78 | 148 |
|
79 | | - Fetch the package versions created from a specified source code repository. |
| 149 | +### Advisories |
80 | 150 |
|
81 | | - ```python |
82 | | - project_package_versions = await api.get_project_package_versions("project_id") |
83 | | - ``` |
| 151 | +```python |
| 152 | +# Fetch OSV advisory details |
| 153 | +await api.get_advisory(advisory_id: str) |
| 154 | +``` |
84 | 155 |
|
85 | | -7. **Get Advisory Details** |
| 156 | +### PURL Lookup |
86 | 157 |
|
87 | | - Fetch information about a security advisory from OSV. |
| 158 | +```python |
| 159 | +# Single purl |
| 160 | +await api.get_purl_lookup(purl: str) |
88 | 161 |
|
89 | | - ```python |
90 | | - advisory_info = await api.get_advisory("advisory_id") |
91 | | - ``` |
| 162 | +# One page of PURL batch |
| 163 | +await api.get_purl_lookup_batch( |
| 164 | + [purl1, purl2, …], |
| 165 | + page_token: Optional[str] = None |
| 166 | +) |
92 | 167 |
|
93 | | -8. **Query Package Versions** |
| 168 | +# Retrieve all pages |
| 169 | +await api.get_all_purl_lookup_batch([…]) |
| 170 | +``` |
94 | 171 |
|
95 | | - Query package versions based on content hash or version key. |
| 172 | +### Container Images |
96 | 173 |
|
97 | | - ```python |
98 | | - package_versions = await api.query_package_versions(hash_type="type", hash_value="value", version_system="system_name", version_name="name", version="version_number") |
99 | | - ``` |
| 174 | +```python |
| 175 | +# Query container images by OCI chain ID |
| 176 | +await api.query_container_images(chain_id: str) |
| 177 | +``` |
100 | 178 |
|
101 | | -Get more informating about the query parameters and response values on the [official API documentation](https://docs.deps.dev/api/v3alpha) |
| 179 | +For full details on parameters and response schemas, see the [Deps.dev API docs](https://docs.deps.dev/api/v3alpha). |
102 | 180 |
|
103 | 181 | ## Contributing |
104 | 182 |
|
105 | | -We welcome contributions! If you find a bug or have suggestions, feel free to open an issue or submit a pull request. |
| 183 | +Contributions, issues and feature requests are welcome! |
| 184 | +Feel free to check [issues page](https://github.com/eclipseo/pydepsdev/issues) or submit a pull request. |
106 | 185 |
|
107 | 186 | ## License |
108 | | - |
109 | 187 | This project is licensed under the Apache Software License 2.0. |
0 commit comments