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.24.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.24.0
File Size Uploaded Provenance Actions
pybgpkit_parser-0.24.0.tar.gz 4.8 MB With provenance Details for pybgpkit_parser-0.24.0.tar.gz

Built distributions (wheels)

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

Total release size: 22.0 MB

Release files / pybgpkit_parser-0.24.0.tar.gz

Download URL pybgpkit_parser-0.24.0.tar.gz
Size 4.8 MB
Tags Source
SHA-256 checksum
How to use checksums
f848ec7b8c5908ded17c1b24b7d332190093b5252ec08369bd04e9477c598b45
BLAKE2b-256 checksum
How to use checksums
4b1fc1531ea95516475dbd4c7d70dfaf2eb156fa2786fa2861e304dfb1c128e2
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 6, 2026.

Transparency log

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

Download URL pybgpkit_parser-0.24.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
523b8255201ebd70496921e513d385d1cb20cc80e5198a892d4519dcd4d1eb90
BLAKE2b-256 checksum
How to use checksums
0809b1810efae5d0e1cff51c4ed33802ace22ccaa190053e840c02f10cdad78f
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 6, 2026.

Transparency log

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

Download URL pybgpkit_parser-0.24.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
eee1924e1e7064bc12ef3204bc068f1af78919c258eac015eba9d79aefc3653f
BLAKE2b-256 checksum
How to use checksums
7fbf48c784441688c6f19414ab2460345c2b5cb90e81aed8b9367282035d1021
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 6, 2026.

Transparency log

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

Download URL pybgpkit_parser-0.24.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
b974f0d53642f2ba99be420368bd7fcb1f1e34a3d693146baa64c01659aa4b0b
BLAKE2b-256 checksum
How to use checksums
1fe4258bf428227fd3507a5a731a039eaf13835a1a343fd54dc2924533fc28f6
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 6, 2026.

Transparency log

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

Download URL pybgpkit_parser-0.24.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
81d9bde69ef311e1a242d8e6b8abcaedf632ea3b942fb30731661b74cf712261
BLAKE2b-256 checksum
How to use checksums
c36c92aac1158003bd5e68b15165da5e68fa6e10baad46965b267810dbe4c035
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 6, 2026.

Transparency log

Security for pybgpkit-parser 0.24.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.24.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 6, 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