Skip to main content

Python-native bindings for roto-api longest-prefix lookups

Project description

roto-api-native

roto-api-native exposes the roto-api Rust lookup engine as an installable Python package for high-volume longest-prefix ASN/prefix enrichment.

This package is an unofficial Python binding based on NLnetLabs/roto-api. It is not affiliated with or endorsed by NLnet Labs. The original project is licensed under BSD-3-Clause, and that upstream license is preserved here.

Install name:

  • roto-api-native

Import name:

  • roto_api

Overview

The package can:

  • download and prepare a local routing snapshot when you explicitly call ensure_data(...)
  • load that snapshot into the Rust lookup engine
  • run longest-prefix lookups entirely in-process from Python

The package does not:

  • install routing dumps at package install time
  • fetch data on plain import roto_api
  • provide the original HTTP API server
  • watch upstream dumps in the background or hot-reload automatically

Install

From PyPI:

pip install roto-api-native

Build locally:

maturin build --release
$wheel = Get-ChildItem .\target\wheels\*.whl | Select-Object -First 1
python -m pip install --force-reinstall $wheel.FullName

Quick Start

One-step bootstrap and open:

from roto_api import open_lookup

lookup = open_lookup("./data")

print(lookup.lookup_ip("8.8.8.8"))
print(lookup.lookup_ips(["8.8.8.8", "1.1.1.1"]))
print(lookup.source_status())

Explicit bootstrap and later load:

from roto_api import ensure_data, load_lookup

data_dir = ensure_data("./data", refresh=False)
lookup = load_lookup(data_dir)

print(lookup.lookup_ip("8.8.8.8"))

Force a refresh:

from roto_api import open_lookup

lookup = open_lookup("./data", refresh=True)

Snapshot Layout

The convenience loaders expect a directory containing these filenames:

  • delegated_all.csv
  • pfx_asn_dfz_v4.csv and/or pfx_asn_dfz_v6.csv
  • optional metadata files:
    • del_ext.timestamps.json
    • riswhois.timestamps.json

If you use:

  • load_lookup(data_dir), or
  • RotoLookup.from_data_dir(data_dir)

then those filenames matter. The loader does not search arbitrary names.

If you need custom filenames, use:

from roto_api import RotoLookup

lookup = RotoLookup(
    prefixes_file="./custom/delegated.csv",
    ris_files=["./custom/ris_v4.csv", "./custom/ris_v6.csv"],
    timestamps_dir="./custom",
)

Manual File Format

If you build the snapshot yourself:

delegated_all.csv

  • pipe-delimited delegated-extended records
  • no header row required
  • first row is treated as data

pfx_asn_dfz_v4.csv

  • comma-separated
  • format per row: prefix,length,asn
  • example: 8.8.8.0,24,15169
  • no header row required

pfx_asn_dfz_v6.csv

  • comma-separated
  • format per row: prefix,length,asn
  • example: 2001:4860::,32,15169
  • no header row required

del_ext.timestamps.json and riswhois.timestamps.json

  • optional metadata files
  • despite the .json extension, these are CSV-formatted text files for compatibility with the original naming

Public API

Functions:

  • ensure_data(data_dir, refresh=False, del_ext_sources=None, riswhois_sources=None)
  • load_lookup(data_dir)
  • open_lookup(data_dir, refresh=False, del_ext_sources=None, riswhois_sources=None)

Class:

  • RotoLookup

Methods:

  • RotoLookup.from_data_dir(data_dir)
  • RotoLookup.lookup_ip(ip)
  • RotoLookup.lookup_ips(ips)
  • RotoLookup.source_status()

The detailed reference is in API.md in the source repository.

Upstream Sources

Delegated RIR files:

  • https://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-extended-latest
  • https://ftp.apnic.net/stats/apnic/delegated-apnic-extended-latest
  • https://ftp.arin.net/pub/stats/arin/delegated-arin-extended-latest
  • https://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-extended-latest
  • https://ftp.ripe.net/pub/stats/ripencc/delegated-ripencc-extended-latest

RIS Whois dumps:

  • https://www.ris.ripe.net/dumps/riswhoisdump.IPv4.gz
  • https://www.ris.ripe.net/dumps/riswhoisdump.IPv6.gz

You can override these URLs via ensure_data(...) / open_lookup(...) parameters or environment variables.

Why It Is Fast

Compared with sending one HTTP request per IP, this package avoids:

  • socket I/O per lookup
  • HTTP parsing and response generation
  • JSON serialization/deserialization per lookup
  • Python-to-server process overhead

The hot lookup path stays inside one in-process Rust engine.

Platform Support

Native wheels are platform-specific.

This repo is currently set up to publish wheels for:

  • Linux x86_64
  • Windows x86_64

An sdist can also be published so unsupported platforms may build locally if they have a suitable Rust toolchain.

Publishing

Release and PyPI steps are documented in PUBLISHING.md in the source repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

roto_api_native-0.2.2.tar.gz (31.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

roto_api_native-0.2.2-cp39-abi3-win_amd64.whl (267.3 kB view details)

Uploaded CPython 3.9+Windows x86-64

roto_api_native-0.2.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (407.8 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

File details

Details for the file roto_api_native-0.2.2.tar.gz.

File metadata

  • Download URL: roto_api_native-0.2.2.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for roto_api_native-0.2.2.tar.gz
Algorithm Hash digest
SHA256 d89481e51471698e13545ef7d78d55df620fb02816978a6d2025b49e4090a325
MD5 538e70288916f3764e9b70027a0f8d93
BLAKE2b-256 35d85efc23369f7fbc10b4f032dd9fcde6af24c32e776dc106097ec7b3a2d22a

See more details on using hashes here.

Provenance

The following attestation bundles were made for roto_api_native-0.2.2.tar.gz:

Publisher: publish.yml on AMM48/roto-api-native

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file roto_api_native-0.2.2-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for roto_api_native-0.2.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c5eae8ab902b8ab5552850955a4e45a88ae66b1fdbfbbb9def6f98a192368ab6
MD5 e8679d593c3416da7e8f2126360f566d
BLAKE2b-256 fd4aa55904603fa8e329229b2a0b7ea2a697323646e57ee4d26a21ec8204eb7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for roto_api_native-0.2.2-cp39-abi3-win_amd64.whl:

Publisher: publish.yml on AMM48/roto-api-native

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file roto_api_native-0.2.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for roto_api_native-0.2.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 838b24804fee52dd9396a04db1d0ee55334f1bdfff74d3a9c7977e2da71cb1ea
MD5 cd05c707b59a637919161402d82056ab
BLAKE2b-256 9739ab3b7cd3cdae186afed6e89fe963c7f117e80daff0a40e0e88c05b0f88a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for roto_api_native-0.2.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on AMM48/roto-api-native

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page