pypi-code-graphs-v4 / README.md
IntellAgents's picture
Add dataset card, schemas, provenance, extractor and loading examples
9c9fb17 verified
|
Raw History Blame Contribute Delete
8.95 kB
---
pretty_name: PyPI Code Graphs (v4)
language:
- code
- en
tags:
- python
- pypi
- code
- graph
- static-analysis
- libcst
- parquet
size_categories:
- 100M<n<1B
configs:
- config_name: units
default: true
data_files:
- split: train
path: data/units/*.parquet
- config_name: files
data_files:
- split: train
path: data/files/*.parquet
- config_name: edges
data_files:
- split: train
path: data/edges/*.parquet
- config_name: source
data_files:
- split: train
path: data/source/*.parquet
---
# PyPI Code Graphs (v4)
A complete, scope-aware Python graph derivative of the pinned
[vikp/pypi_clean snapshot](https://huggingface.co/datasets/vikp/pypi_clean/tree/c59858d4234adcf51e843623cdca78ed9ae094c5).
This release packages source text, file records, definition nodes, and static
relationships as four linked Parquet tables. It is a graph view of that snapshot,
not a current crawl of every package on PyPI.
| Configuration | Rows | Contents |
| --- | ---: | --- |
| `source` | 2,438,172 | Exact upstream-cleaned source records, including non-Python files |
| `files` | 1,769,504 | Python files, provenance, parse status, counts, content hashes |
| `units` (default) | 35,212,956 | Module, class, function, method, and nested-function nodes |
| `edges` | 126,728,300 | Containment and aggregated static call relationship records |
The Python file table covers **199,268 distinct package names**. There are
**133,264,997 syntactic call occurrences**, aggregated into call relationship rows.
A relationship row is not necessarily a single resolved binary edge.
Each configuration has 64 Zstandard-compressed Parquet shards. Shard numbers align
across the four tables; every file's nodes and relationships stay in its source
shard. Native schema version **4** is preserved. Release version is **1.0.0**.
`manifest.json` records exact per-shard sizes, row counts, SHA-256 digests, extraction
options, source revision, and the extractor fingerprint. `partition-map.json` maps
the original 2,496 work partitions to published row groups.
## Load
```python
from datasets import load_dataset
repo = "IntellAgents/pypi-code-graphs-v4"
units = load_dataset(repo, "units", split="train", streaming=True)
print(next(iter(units)))
# Other linked tables use the same interface:
files = load_dataset(repo, "files", split="train", streaming=True)
edges = load_dataset(repo, "edges", split="train", streaming=True)
source = load_dataset(repo, "source", split="train", streaming=True)
```
Use `revision=<commit SHA>` to pin a release. Streaming avoids downloading the full
corpus. The `train` split is a **storage convention**, not a validated training split.
Do not use random node/row splits to measure cross-package generalization: related
packages, vendored code, and near duplicates can leak across them. Construct splits
by package and code families before training or evaluation.
For a complete local shard and a per-file graph, see
[`examples/pypi_graphs.py`](examples/pypi_graphs.py). It downloads only the requested
shard, retains candidate lists, and can retrieve the corresponding source record.
The files are ordinary Parquet; no custom dataset loading script is required.
## Graph interpretation
`source_id` joins `files`, `units`, and `edges` and identifies one source file.
`unit_id` identifies a definition occurrence. `parent_unit_id` supplies the definition
hierarchy; a synthetic module node has no parent. This is a **per-file definition
and static-call graph**, not an expression-level AST, a dataflow graph, or a resolved
whole-package runtime call graph.
* `contains`: one parent and one child; `target_unit_ids` is a singleton. These
hierarchy links are exact for the extracted definitions.
* `calls`: a syntactic call expression belongs to `source_unit_id` and retains its
resolution label. `target_unit_ids` can be empty, singleton, or contain alternative
local targets. **Do not turn alternative candidates into multiple confirmed edges.**
* Resolution labels are `local`, `local_heuristic`, `import`, `builtin`,
`local_unresolved`, and `unresolved`. The same-class `self`/`cls` shortcut is labeled
`local_heuristic`; general chained attribute calls are not assumed resolved.
* `candidate_qualified_names` preserves external/builtin/ambiguous name evidence
without inventing nodes for external packages.
* Repeated calls with the same aggregation key are collapsed; `occurrences` records
multiplicity and `line`/`column` retain the first position. This is not a complete
call-site trace. `call_site_kind` distinguishes `body`, `decorator`, `default`,
`annotation`, `class_header`, `class_body`, and `module_body` contexts.
See [`SCHEMA.md`](SCHEMA.md) and [`schemas.json`](schemas.json) for fields and types.
The raw tables keep topology separate from code-bearing node attributes, so they
can support embedding and graph learning views without serializing target IDs into
embedding text. A future model-specific view still needs deliberate feature masking,
negative sampling, and leakage-safe splits; those choices are not baked into this release.
## Code representation and identity
LibCST preserves identifier spelling, literals, docstrings, annotations, decorators,
imports and ordering. Ordinary comments and blank lines are removed by the normalizer;
shebang/encoding directives and type comments are retained when present upstream.
No identifiers are alpha-renamed and no code is executed. Isolated unit representations
stub nested child definitions while retaining surrounding executable and declarative
statements. Full-file normalized text is omitted by this build's default; retrieve
the upstream-cleaned text through the `source` table.
`source_id` is a versioned deterministic digest of `(package, path, filename)`.
`content_hash` separately detects changes to source text. `unit_id` incorporates the
source identity and scoped definition path with same-name occurrence ordinals; it
does not merge identical code in different files. Scoped structural hashes describe
the full unit, isolated unit, header, isolated body, and ordered child structure.
They remain sensitive to names, literals, and annotations; they are not semantic
equivalence proofs.
## Coverage and failures
| File status | Files | Interpretation |
| --- | ---: | --- |
| `ok` | 1,733,207 | Completed extraction |
| `syntax_error` | 35,202 | Retained file record; no graph |
| `skipped_pathological` | 1,088 | Above the 1,000,000-character limit; retained file record |
| `analysis_error` | 6 | Retained unexpected-error record; no graph |
| `metadata_error` | 1 | Partial graph: 203 definitions and 202 containment links; no call analysis |
There are **1,733,208 module roots**, including the partial metadata-error graph.
Consumers requiring fully analyzed files should filter `files.parse_status == "ok"`
and join that filter into the other tables. Failed/skipped files remain recoverable
from the source table. Python-2 syntax was not automatically converted.
## Provenance and validation
Upstream: `vikp/pypi_clean` at
`c59858d4234adcf51e843623cdca78ed9ae094c5`. The upstream card describes a selection
of Python, Markdown, reStructuredText and rendered notebooks from package archives,
with leading comments/licenses removed. The `source` configuration is a byte-for-byte
copy of its 64 Parquet files; it is not the original unmodified package archives.
Extraction used CPython **3.14.6**, LibCST **1.9.0**, and PyArrow **25.0.0**.
The exact extractor modules are included under [`extractor/`](extractor/README.md).
Transform fingerprint:
`d63b9351e4ca57e605b58ad05c7a81d2aade032340fd95564c98944f8ed44b76`.
Release checks covered all partitions and all values: completed-build checksums,
upstream source checksums, globally unique file/node IDs, schema/version validity,
source spans, per-file counts, endpoint locality, the complete containment hierarchy,
and full Arrow value equality after repacking. See
[`audit/corpus-audit.json`](audit/corpus-audit.json),
[`audit/span-bounds.json`](audit/span-bounds.json),
[`audit/diagnostic-check.json`](audit/diagnostic-check.json), and `manifest.json`.
Static resolution labels express the extractor's evidence, not a guarantee of runtime behavior.
## Licensing and reuse
**There is no blanket license grant for the collected package code.** The upstream
snapshot does not supply per-package license metadata and reports removing leading
license comments. Package names and archive paths are retained to help users recover
the original projects and their terms. This release does not establish that every
package is permissively licensed. See [`LICENSE_NOTES.md`](LICENSE_NOTES.md).
For attribution, cite this repository with its commit SHA, the pinned upstream
snapshot, and the originating packages as applicable. Corrections can be reported
through the dataset's community discussions, preferably with `source_id`/`unit_id`.