Skip to main content

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, prefix
  • ROUTE_FIELDS: BASIC_FIELDS + as_path
  • NEXT_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_asn property
  • to_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 scans
  • iter_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:

  • timestamp
  • elem_type
  • peer_ip
  • peer_asn
  • prefix
  • as_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.25.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pybgpkit-parser 0.25.0
File Size Uploaded Provenance Actions
pybgpkit_parser-0.25.0.tar.gz 32.0 kB With provenance Details for pybgpkit_parser-0.25.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pybgpkit-parser 0.25.0
File Actions
pybgpkit_parser-0.25.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for pybgpkit_parser-0.25.0-cp39-abi3-win_amd64.whl
pybgpkit_parser-0.25.0-cp39-abi3-manylinux_2_38_x86_64.whl CPython 3.9 abi3 Linux glibc 2.38+ x86-64 Details for pybgpkit_parser-0.25.0-cp39-abi3-manylinux_2_38_x86_64.whl
pybgpkit_parser-0.25.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for pybgpkit_parser-0.25.0-cp39-abi3-macosx_11_0_arm64.whl
pybgpkit_parser-0.25.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for pybgpkit_parser-0.25.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 17.3 MB

Release files / pybgpkit_parser-0.25.0.tar.gz

Download URL pybgpkit_parser-0.25.0.tar.gz
Size 32.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5558838261e8bd622e35a47e48bea29355cd345d3a6c8c3ebdf14f6a9484b29a
BLAKE2b-256 checksum
How to use checksums
255d7ae56a006cedb30bbc48a37d5089ccfada47961b72738c460bd32dce0802
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 30, 2026.

Transparency log

Release files / pybgpkit_parser-0.25.0-cp39-abi3-win_amd64.whl

Download URL pybgpkit_parser-0.25.0-cp39-abi3-win_amd64.whl
Size 3.9 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
01933bdcd94348bd6a6dd9b69143f3523cd624a9d4ac7a0318cf394c54e4a409
BLAKE2b-256 checksum
How to use checksums
8018aa265c97ee9c68a26766c355e14d26ff9820980df76a5e5506179f799c00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 30, 2026.

Transparency log

Release files / pybgpkit_parser-0.25.0-cp39-abi3-manylinux_2_38_x86_64.whl

Download URL pybgpkit_parser-0.25.0-cp39-abi3-manylinux_2_38_x86_64.whl
Size 4.8 MB
Tags CPython 3.9 Linux glibc 2.38+ x86-64 abi3
SHA-256 checksum
How to use checksums
150beaaa1b77a0a42a94c1cbb29d4bd974d8ac6cbcb3e2b31bd7569305d3c981
BLAKE2b-256 checksum
How to use checksums
e89213e60a59788240091a012c7a38dee9723b64a8b80be663e78dcc2acfe59c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 30, 2026.

Transparency log

Release files / pybgpkit_parser-0.25.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL pybgpkit_parser-0.25.0-cp39-abi3-macosx_11_0_arm64.whl
Size 4.2 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6eed7068ac90dfe0fcbf9e549f773f0475c123d2e484e139e6bcde44523e2fc6
BLAKE2b-256 checksum
How to use checksums
184d007b1ca8d92e70d350acd437c0b83284313a160a380cb7967b37ff6b6946
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 30, 2026.

Transparency log

Release files / pybgpkit_parser-0.25.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL pybgpkit_parser-0.25.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 4.4 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
0a68211fd0a23a02c44059f2ceb05f51a2a874cc3ac8631570b23aa9337b762a
BLAKE2b-256 checksum
How to use checksums
23ec6f92bdf2be5e72a91bdf98e76973fa3b5020ca1edae7aac8315e72a71155
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 30, 2026.

Transparency log

Security for pybgpkit-parser 0.25.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.

Select from 5 files

Attestation for pybgpkit_parser-0.25.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 Nov 30, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page