bgpkit-parser-py
Python binding for bgpkit-parser
Example
from pybgpkit_parser import Parser
import json
parser = Parser(
url="https://spaces.bgpkit.org/parser/update-example",
filters={"peer_ips": "185.1.8.65, 2001:7f8:73:0:3:fa4:0:1"},
)
for elem in parser:
print(elem.origin_asns)
print(json.dumps(elem.to_dict(), indent=4))
break
You can also add cache_dir to Parser to cache the downloaded files to a specified directory.
Here is an example:
from pybgpkit_parser import Parser
import json
parser = Parser(
url="https://spaces.bgpkit.org/parser/update-example",
filters={"peer_ips": "185.1.8.65, 2001:7f8:73:0:3:fa4:0:1"},
cache_dir="./"
)
for elem in parser:
print(elem.origin_asns)
print(json.dumps(elem.to_dict(), indent=4))
break
Filters
The original dictionary-based filter API is still supported:
parser = Parser(url, filters={"peer_ips": "185.1.8.65,2001:7f8:73:0:3:fa4:0:1"})
Reusable Rust-backed filters are also available:
from pybgpkit_parser import Filter, Parser
filters = [
Filter.peer_ips(["185.1.8.65", "2001:7f8:73:0:3:fa4:0:1"]),
Filter.elem_type("a"),
]
parser = Parser.from_filters(url, filters)
Available helper constructors:
Filter.peer_ip(...)Filter.peer_ips([...])Filter.origin_asn(...)Filter.prefix(...)Filter.elem_type(...)
Available fields for Elem
#[pyclass]
#[derive(Clone, PartialEq)]
pub struct Elem {
#[pyo3(get, set)]
pub timestamp: f64,
#[pyo3(get, set)]
pub elem_type: String,
#[pyo3(get, set)]
pub peer_ip: String,
#[pyo3(get, set)]
pub peer_asn: u32,
#[pyo3(get, set)]
pub peer_bgp_id: Option<String>,
#[pyo3(get, set)]
pub prefix: String,
#[pyo3(get, set)]
pub next_hop: Option<String>,
#[pyo3(get, set)]
pub as_path: Option<String>,
#[pyo3(get, set)]
pub origin_asns: Option<Vec<u32>>,
#[pyo3(get, set)]
pub origin: Option<String>,
#[pyo3(get, set)]
pub local_pref: Option<u32>,
#[pyo3(get, set)]
pub med: Option<u32>,
#[pyo3(get, set)]
pub communities: Option<Vec<String>>,
#[pyo3(get, set)]
pub atomic: Option<String>,
#[pyo3(get, set)]
pub aggr_asn: Option<u32>,
#[pyo3(get, set)]
pub aggr_ip: Option<String>,
#[pyo3(get, set)]
pub only_to_customer: Option<u32>,
}
Supported Python Version
- Python3.9
- Python3.10
- Python3.11
- Python3.12
- Python3.13
Installation
python3 -m pip install pybgpkit-parser
Develop
maturin develop builds local python module and add to the venv.
High-performance projected iteration
For best performance, prefer projected tuple iteration when you only need a subset of fields. This avoids creating full Elem objects and skips conversion for unused fields.
from pybgpkit_parser import Parser, ROUTE_FIELDS
# Fast: only converts requested fields
for timestamp, prefix, as_path in Parser(url).iter_tuples(["timestamp", "prefix", "as_path"]):
pass
# Faster for large files: batch Python boundary crossings
fields = ["timestamp", "prefix", "as_path"]
for batch in Parser(url).iter_tuple_batches(fields, batch_size=10_000):
for timestamp, prefix, as_path in batch:
pass
Available field presets:
BASIC_FIELDS:timestamp,elem_type,peer_ip,peer_asn,prefixROUTE_FIELDS:BASIC_FIELDS+as_pathNEXT_HOP_FIELDS:BASIC_FIELDS+next_hop
You can also pass your own field list, e.g. Parser(url).iter_tuples(["peer_asn", "prefix"]).
Utility methods
Elem exposes Rust-like helper methods:
is_announcement()is_withdrawal()get_origin_asn()get_origin_asns()has_as_path()to_dict()/as_dict()origin_asnpropertyto_json()to_psv()Elem.get_psv_header()- module constants:
ELEM_TYPE_ANNOUNCE,ELEM_TYPE_WITHDRAW,PSV_HEADER
Parser also provides stream-consuming helpers:
count()iter_batches(batch_size)iter_tuples(fields)— recommended for high-performance subset-field scansiter_tuple_batches(fields, batch_size)— recommended for large-file scans
Route-level parsing
RouteParser exposes upstream BgpRouteElem iteration for faster scans when you only need route identity fields:
from pybgpkit_parser import RouteParser
for route in RouteParser(url):
print(route.timestamp, route.peer_ip, route.peer_asn, route.prefix, route.as_path)
RouteElem fields:
timestampelem_typepeer_ippeer_asnprefixas_path
RouteParser supports the same constructor style, from_filters(...), parse_all(), parse_next(), count(), iter_batches(batch_size), iter_tuples(fields), and iter_tuple_batches(fields, batch_size).
For route scans, this is the fastest object-based API; for maximum throughput use RouteParser.iter_tuples(ROUTE_FIELDS) or RouteParser.iter_tuple_batches(ROUTE_FIELDS, batch_size).
Build and publish
See BUILD.md for automated GitHub Actions release details.
Metadata
Release files for pybgpkit-parser 0.18.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pybgpkit_parser-0.18.0.tar.gz | 31.5 kB | With provenance | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| pybgpkit_parser-0.18.0-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details |
| pybgpkit_parser-0.18.0-cp39-abi3-manylinux_2_38_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.38+ x86-64 | Details |
| pybgpkit_parser-0.18.0-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details |
| pybgpkit_parser-0.18.0-cp39-abi3-macosx_10_12_x86_64.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 16.4 MB
Release files / pybgpkit_parser-0.18.0.tar.gz
| Download URL | pybgpkit_parser-0.18.0.tar.gz |
|---|---|
| Size | 31.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e131be45eb75568b2edbd0922657253d103d7b82ad9c8782ba735feb17a1f016
|
|
BLAKE2b-256 checksum How to use checksums |
b144f78e619827e8823a185e8dd79de9736b09c680281db403eb42bb44717d17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.
Transparency logRelease files / pybgpkit_parser-0.18.0-cp39-abi3-win_amd64.whl
| Download URL | pybgpkit_parser-0.18.0-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 3.6 MB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
c3392b70dd780e8ef07d8a67b31fbe08f166b928c5f0477dee4c5790fa390408
|
|
BLAKE2b-256 checksum How to use checksums |
2c614cf198dab91bae820b0c4b06951317069a3c8a9a9a1e7582798dfbb8a54b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.
Transparency logRelease files / pybgpkit_parser-0.18.0-cp39-abi3-manylinux_2_38_x86_64.whl
| Download URL | pybgpkit_parser-0.18.0-cp39-abi3-manylinux_2_38_x86_64.whl |
|---|---|
| Size | 4.5 MB |
| Tags | CPython 3.9 Linux glibc 2.38+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f8a519a89ad658f081bedb47cb314ffe8108e9f3dd7592bd9017e39f28446aae
|
|
BLAKE2b-256 checksum How to use checksums |
5e092954b18f44022efd24dc9ffde71b89108a983cce585794f1137562ec00f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.
Transparency logRelease files / pybgpkit_parser-0.18.0-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | pybgpkit_parser-0.18.0-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ab734081fa975f41d2b5a6f47d6b3755710e8b892aa671b3bc429a12dd650720
|
|
BLAKE2b-256 checksum How to use checksums |
9a95c6b2fad3836021b336f500a9090a5366aca17773e09770c0dc4663cdb335
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.
Transparency logRelease files / pybgpkit_parser-0.18.0-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | pybgpkit_parser-0.18.0-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
34cfd0acb852427ab4dc58d3325da299b62b668ebcea9c7a71b2b31a94d4ca35
|
|
BLAKE2b-256 checksum How to use checksums |
8285d8bba96758f88ef0586a819c5095857af8b7db676132509c704d6e892aca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.
Transparency logSecurity for pybgpkit-parser 0.18.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 5 files in this release have been uploaded with provenance metadata.
Attestation for pybgpkit_parser-0.18.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.