Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

pysubnettree-rs

Latest version: v0.5.1

Overview

Last scanned
24 Nov 2026
Published
24 Nov 2026
PyPI package Publisher: sim0n
1 Stars
0 Forks
7 Versions
6.7K Downloads
Rust Repo language

Scan summary

pysubnettree-rs was last scanned on 24 Nov 2026 at version 0.5.1. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 7 versions; the latest 2 were published on 24 Nov 2026.
  • Findings: No rules fired in version 0.5.1.
  • Downloads: 6,736 downloads.

Versions

7 versions published
Versions and the rules that fired in each
VersionPublishedStatus
0.5.1 LATEST 24 Nov 2026 No rules fired
0.5.0 24 Nov 2026 No rules fired
0.4.1 17 Nov 2026 No rules fired
0.4.0 12 Nov 2026 Not shown
0.3.0 11 Nov 2026 Not shown

No rules fired in 0.5.1

Findings

Findings for v0.5.1. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 0.5.1; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

pysubnettree-rs

Tests PyPI Python versions

Fast, memory-efficient longest-prefix-match lookups of IPv4 and IPv6 subnets for Python, written in safe Rust (#![forbid(unsafe_code)]) using PyO3.

Load a large collection of networks (for example a full BGP routing table), attach a value to each one, and find the most specific network for any IP address. The loaded structure can be saved to a compact, checksummed file (XXH3-64) and loaded again quickly.

Build a tree with SubnetTreeBuilder, then query the immutable SubnetTreeRS:

from pysubnettree_rs import SubnetTreeBuilder, SubnetTreeRS

builder = SubnetTreeBuilder()
builder['10.0.0.0/8'] = {'name': 'private', 'asn': 64512}
builder['10.1.0.0/16'] = {'name': 'office'}
builder.insert('2001:db8::/32', 'documentation')
builder.insert('192.0.2.0/24')  # no value: lookups return None
tree = builder.build()          # immutable, lock-free copy
del builder                     # frees the builder's memory

tree['10.1.2.3']          # mappingproxy({'name': 'office'}), values are read-only
tree['192.0.2.1']         # None (found, no value)
tree.get('172.16.0.1')    # None (not found), tree['172.16.0.1'] raises KeyError
'2001:db8::1' in tree     # True
tree.lookup('10.1.2.3')   # ('10.1.0.0/16', mappingproxy({'name': 'office'}))

tree.dump('networks.pst')
tree = SubnetTreeRS.load('networks.pst')

The tree can't be modified, so it needs no locking and can be shared between threads freely. To change it, use tree.to_builder() or SubnetTreeBuilder.load(path) to get a modifiable copy.

Typed values

A tree can be restricted to one value type, such as a frozen dataclass or a frozen pydantic model. Inserts are then checked at runtime, and type checkers see that type in every method:

from dataclasses import dataclass

from pysubnettree_rs import SubnetTreeBuilder, SubnetTreeRS


@dataclass(frozen=True, slots=True)
class Route:
    asn: int
    country: str | None = None
    tags: tuple[str, ...] = ()


builder = SubnetTreeBuilder(value_type=Route)   # SubnetTreeBuilder[Route]
builder['10.0.0.0/8'] = Route(asn=64512, country='LU')
builder.insert('10.1.0.0/16')                   # no value
builder['192.0.2.0/24'] = {'asn': 1}            # mypy error, TypeError at runtime
tree = builder.build()                          # SubnetTreeRS[Route]

route = tree['10.200.0.1']                      # Route | None
tree['10.0.0.0/8'] = Route(asn=1)               # mypy error, TypeError: the tree is immutable

tree.dump('routes.pst')
tree = SubnetTreeRS.load('routes.pst', value_type=Route)

Features

  • Longest prefix match for IPv4 and IPv6 in one structure. IPv4-mapped IPv6 addresses (::ffff:a.b.c.d) are treated as IPv4.
  • Keys can be str ('10.0.0.0/8', '10.1.2.3'), packed bytes (4 or 16 bytes), or ipaddress address and network objects.
  • Values can be None, bool, int (64 bit), float, str, bytes, list/tuple, dict with str keys, enum members, frozen dataclasses, and frozen pydantic models, nested in any combination. Every supported value can be saved to disk without pickle, and comes back as what was inserted: types that could not be restored, such as namedtuple, are rejected.
  • Values are read-only. Lookups return immutable objects: list and tuple come back as tuple, and dict as types.MappingProxyType. Equal values are stored once and returned as the same object, with no copying or conversion per lookup.
  • Optional value type, SubnetTreeBuilder(value_type=Route), with generic typing (SubnetTreeBuilder[Route] builds a SubnetTreeRS[Route]).
  • An immutable tree class for queries: no locks, safe to share between threads. On free-threaded Python, lookups scale with the number of threads.
  • A compact binary on-disk format with an XXH3-64 checksum. Untrusted files are fully validated, and classes are never imported by name from a file.
  • Repeated strings in the values (names, countries, the field names of dataclasses) are stored once, in memory and on disk.
  • Works with pickle and with free-threaded Python (3.14t).
  • Releases the GIL while building the lookup structure and during file I/O.

API

SubnetTreeRS (immutable, for queries) and SubnetTreeBuilder (modifiable) share the read methods. Lookups on the builder are a convenience: they take a lock and compile pending changes first.

Method SubnetTreeRS SubnetTreeBuilder Description
SubnetTreeBuilder(value_type=None) ✓ Create an empty builder, optionally restricted to one value type.
build() ✓ An immutable SubnetTreeRS with a copy of the contents.
to_builder() ✓ A modifiable copy.
insert(network, value=None) / b[network] = value ✓ Add or replace a network. Host bits are ignored.
insert_many(mapping_or_pairs) ✓ Bulk insert, faster than repeated insert; all or nothing.
remove(network) / del b[network], clear() ✓ Remove networks.
t[key] ✓ ✓ Value of the longest match, KeyError if there is none.
get(key, default=None) ✓ ✓ Value of the longest match, or default.
lookup(key) ✓ ✓ (network, value) of the longest match, or None.
lookup_all(key) ✓ ✓ All matching (network, value) pairs, most specific first.
key in t ✓ ✓ True if any network matches.
has_network(network) / get_exact(network, default=None) ✓ ✓ Exact network match.
len(t), iter(t), items() ✓ ✓ Container protocol.
stats(), memory_usage() ✓ ✓ Sizes and approximate memory use.
to_bytes() / dump(path) ✓ ✓ Serialize to bytes or a file (written atomically).
from_bytes(data, value_type=None, types=()) / load(path, ...) ✓ ✓ Deserialize, as an immutable tree or as a builder to modify it.
materialize(), load(..., eager=True) ✓ Build all value objects now instead of on first use (see below).

A lookup key can be an address or a network. For a network such as '10.1.2.0/24', the result is the most specific stored network that contains the whole key network.

When loading data that contains dataclasses, pydantic models or enums, pass their classes: the value type as value_type, and any other classes, such as nested ones, in types.

SubnetTreeRS.load() validates the whole file but builds a value's Python object only when a lookup first returns it, so loading stays fast and small even when (almost) every network has its own value. Pass eager=True, or call materialize(), to build them all up front. A builder also builds a value's object only when a lookup first returns it. To write a large tree to a file, builder.dump(path) needs the least memory: it copies nothing.

Performance

Full 2016 routeviews table, IPv4 and IPv6, with AS numbers as values. The table is generated by benchmarks/bench.py --update README.md (see Development), so anyone can reproduce it.

AMD Ryzen 9 3900X 12-Core Processor, Python 3.13.5, pysubnettree-rs 0.5.1, pysubnettree 0.38.1; 1,000,000 lookups per set, median of 3 passes in each of 3 processes.

pysubnettree-rs pysubnettree
Load 644,586 networks 0.26 s 0.33 s
Lookup, addresses inside table networks 159 ns 1199 ns
Lookup, random addresses 113 ns 803 ns
of which Python loop and call overhead 29 ns 32 ns
Memory (RSS increase) 16 MB 98 MB
Save to file (size) 0.011 s (4.3 MB) n/a
Load from file 0.028 s n/a
Load from file, a distinct dataclass per network (35 MB) 0.198 s n/a
same, eager=True (builds every value object up front) 2.132 s n/a
Compared to other algorithms

The table above measures the whole Python API against pysubnettree. For an in-depth comparison of the data structure itself, in Rust and without Python overhead, see Lookup algorithms. It covers Tree Bitmap (as in NLnet Labs' rotonda-store), Poptrie (including the poptrie crate), DIR-24-8, a binary trie, hash tables per prefix length and several index variants. It reports memory, build time, and lookup throughput and latency for IPv4 and IPv6 on three CPU targets. Those tables are generated too (research/lpm-bench), so they can be reproduced on any machine.

How it works

The networks of each address family are kept in sorted arrays without pointers, and flattened into disjoint address ranges that carry the value directly. A lookup is a binary search over a few ranges, selected by a direct index on 16 address bits. For IPv6, the index uses the bits after the prefix all networks share (2000::/4) and has a second level. This was chosen by benchmarking it against Tree Bitmap, Poptrie, DIR-24-8 and others; see docs/algorithms.md.

The structure is designed for "load in bulk, then query". A builder buffers modifications and merges them when it is built or queried. Interleaving single inserts with lookups on a builder rebuilds the structure on every lookup, which costs O(n). Insert everything, call build(), then query the tree.

Development

Requires Rust (stable, edition 2024) and uv.

uv sync                     # build the extension in debug mode and install dev tools
uv run pytest               # Python tests
cargo test --no-default-features   # Rust core tests (no libpython needed)
uv run prek run --all-files # linters (ruff, mypy, rustfmt, clippy, ...)
uv run --group docs zensical serve                # documentation

# benchmark against pysubnettree and regenerate the table in this README; build in release
# mode and don't let uv rebuild in debug mode
uv run --group bench maturin develop --release --uv
uv run --no-sync python benchmarks/bench.py --update README.md

# data structure benchmarks without Python, regenerates docs/algorithms.md (see there)
(cd research/lpm-bench && cargo run --release -- --update ../../docs/algorithms.md)

# combined Rust + Python coverage (needs cargo-llvm-cov) -> coverage.lcov
./scripts/coverage.sh

License

Apache License 2.0, see LICENSE.

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • pypi-releases pysubnettree-rs

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

PHP2Shell, Day 5 93.6% of Measurable Instances Still Unpatched (1)
Vulnerability Insights

PHP2Shell, Day 5: The Panic Hasn’t Turned Into Patching

Copy of Template Design OX Blog (2)
Research

NGINX2Root: Five Critical NGINX Flaws Expose Web Servers to Remote Code Execution

Vulnerability Insights

Compromised Claude Code extensions (versions 2.1.312 & 2.1.313) in Cursor try to install a backdoor

Frame 2085668439 (1)
Group 1261154229