pybgpkit-parser 0.7.0__cp39-abi3-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pybgpkit_parser/__init__.py +5 -0
- pybgpkit_parser/pybgpkit_parser.pyd +0 -0
- pybgpkit_parser-0.7.0.dist-info/METADATA +223 -0
- pybgpkit_parser-0.7.0.dist-info/RECORD +7 -0
- pybgpkit_parser-0.7.0.dist-info/WHEEL +4 -0
- pybgpkit_parser-0.7.0.dist-info/licenses/LICENSE +21 -0
- pybgpkit_parser-0.7.0.dist-info/sboms/pybgpkit-parser.cyclonedx.json +6304 -0
|
Binary file
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pybgpkit-parser
|
|
3
|
+
Version: 0.7.0
|
|
4
|
+
Classifier: Programming Language :: Rust
|
|
5
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
6
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Requires-Dist: pytest ; extra == 'dev'
|
|
11
|
+
Requires-Dist: pytest-benchmark ; extra == 'dev'
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Summary: Python binding for bgpkit-parser
|
|
15
|
+
License: MIT
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
18
|
+
|
|
19
|
+
# bgpkit-parser-py
|
|
20
|
+
|
|
21
|
+
Python binding for bgpkit-parser
|
|
22
|
+
|
|
23
|
+
## Example
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from pybgpkit_parser import Parser
|
|
27
|
+
import json
|
|
28
|
+
|
|
29
|
+
parser = Parser(
|
|
30
|
+
url="https://spaces.bgpkit.org/parser/update-example",
|
|
31
|
+
filters={"peer_ips": "185.1.8.65, 2001:7f8:73:0:3:fa4:0:1"},
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
for elem in parser:
|
|
35
|
+
print(elem.origin_asns)
|
|
36
|
+
print(json.dumps(elem.to_dict(), indent=4))
|
|
37
|
+
break
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
You can also add `cache_dir` to Parser to cache the downloaded files to a specified directory.
|
|
41
|
+
|
|
42
|
+
Here is an example:
|
|
43
|
+
```python
|
|
44
|
+
from pybgpkit_parser import Parser
|
|
45
|
+
import json
|
|
46
|
+
|
|
47
|
+
parser = Parser(
|
|
48
|
+
url="https://spaces.bgpkit.org/parser/update-example",
|
|
49
|
+
filters={"peer_ips": "185.1.8.65, 2001:7f8:73:0:3:fa4:0:1"},
|
|
50
|
+
cache_dir="./"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
for elem in parser:
|
|
54
|
+
print(elem.origin_asns)
|
|
55
|
+
print(json.dumps(elem.to_dict(), indent=4))
|
|
56
|
+
break
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Filters
|
|
60
|
+
|
|
61
|
+
The original dictionary-based filter API is still supported:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
parser = Parser(url, filters={"peer_ips": "185.1.8.65,2001:7f8:73:0:3:fa4:0:1"})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Reusable Rust-backed filters are also available:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from pybgpkit_parser import Filter, Parser
|
|
71
|
+
|
|
72
|
+
filters = [
|
|
73
|
+
Filter.peer_ips(["185.1.8.65", "2001:7f8:73:0:3:fa4:0:1"]),
|
|
74
|
+
Filter.elem_type("a"),
|
|
75
|
+
]
|
|
76
|
+
parser = Parser.from_filters(url, filters)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Available helper constructors:
|
|
80
|
+
|
|
81
|
+
- `Filter.peer_ip(...)`
|
|
82
|
+
- `Filter.peer_ips([...])`
|
|
83
|
+
- `Filter.origin_asn(...)`
|
|
84
|
+
- `Filter.prefix(...)`
|
|
85
|
+
- `Filter.elem_type(...)`
|
|
86
|
+
|
|
87
|
+
## Available fields for `Elem`
|
|
88
|
+
|
|
89
|
+
```rust
|
|
90
|
+
#[pyclass]
|
|
91
|
+
#[derive(Clone, PartialEq)]
|
|
92
|
+
pub struct Elem {
|
|
93
|
+
#[pyo3(get, set)]
|
|
94
|
+
pub timestamp: f64,
|
|
95
|
+
#[pyo3(get, set)]
|
|
96
|
+
pub elem_type: String,
|
|
97
|
+
#[pyo3(get, set)]
|
|
98
|
+
pub peer_ip: String,
|
|
99
|
+
#[pyo3(get, set)]
|
|
100
|
+
pub peer_asn: u32,
|
|
101
|
+
#[pyo3(get, set)]
|
|
102
|
+
pub peer_bgp_id: Option<String>,
|
|
103
|
+
#[pyo3(get, set)]
|
|
104
|
+
pub prefix: String,
|
|
105
|
+
#[pyo3(get, set)]
|
|
106
|
+
pub next_hop: Option<String>,
|
|
107
|
+
#[pyo3(get, set)]
|
|
108
|
+
pub as_path: Option<String>,
|
|
109
|
+
#[pyo3(get, set)]
|
|
110
|
+
pub origin_asns: Option<Vec<u32>>,
|
|
111
|
+
#[pyo3(get, set)]
|
|
112
|
+
pub origin: Option<String>,
|
|
113
|
+
#[pyo3(get, set)]
|
|
114
|
+
pub local_pref: Option<u32>,
|
|
115
|
+
#[pyo3(get, set)]
|
|
116
|
+
pub med: Option<u32>,
|
|
117
|
+
#[pyo3(get, set)]
|
|
118
|
+
pub communities: Option<Vec<String>>,
|
|
119
|
+
#[pyo3(get, set)]
|
|
120
|
+
pub atomic: Option<String>,
|
|
121
|
+
#[pyo3(get, set)]
|
|
122
|
+
pub aggr_asn: Option<u32>,
|
|
123
|
+
#[pyo3(get, set)]
|
|
124
|
+
pub aggr_ip: Option<String>,
|
|
125
|
+
#[pyo3(get, set)]
|
|
126
|
+
pub only_to_customer: Option<u32>,
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Supported Python Version
|
|
131
|
+
|
|
132
|
+
- Python3.9
|
|
133
|
+
- Python3.10
|
|
134
|
+
- Python3.11
|
|
135
|
+
- Python3.12
|
|
136
|
+
- Python3.13
|
|
137
|
+
|
|
138
|
+
## Installation
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
python3 -m pip install pybgpkit-parser
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Develop
|
|
145
|
+
|
|
146
|
+
`maturin develop` builds local python module and add to the venv.
|
|
147
|
+
|
|
148
|
+
## High-performance projected iteration
|
|
149
|
+
|
|
150
|
+
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.
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
from pybgpkit_parser import Parser, ROUTE_FIELDS
|
|
154
|
+
|
|
155
|
+
# Fast: only converts requested fields
|
|
156
|
+
for timestamp, prefix, as_path in Parser(url).iter_tuples(["timestamp", "prefix", "as_path"]):
|
|
157
|
+
pass
|
|
158
|
+
|
|
159
|
+
# Faster for large files: batch Python boundary crossings
|
|
160
|
+
fields = ["timestamp", "prefix", "as_path"]
|
|
161
|
+
for batch in Parser(url).iter_tuple_batches(fields, batch_size=10_000):
|
|
162
|
+
for timestamp, prefix, as_path in batch:
|
|
163
|
+
pass
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Available field presets:
|
|
167
|
+
|
|
168
|
+
- `BASIC_FIELDS`: `timestamp`, `elem_type`, `peer_ip`, `peer_asn`, `prefix`
|
|
169
|
+
- `ROUTE_FIELDS`: `BASIC_FIELDS` + `as_path`
|
|
170
|
+
- `NEXT_HOP_FIELDS`: `BASIC_FIELDS` + `next_hop`
|
|
171
|
+
|
|
172
|
+
You can also pass your own field list, e.g. `Parser(url).iter_tuples(["peer_asn", "prefix"])`.
|
|
173
|
+
|
|
174
|
+
## Utility methods
|
|
175
|
+
|
|
176
|
+
`Elem` exposes Rust-like helper methods:
|
|
177
|
+
|
|
178
|
+
- `is_announcement()`
|
|
179
|
+
- `is_withdrawal()`
|
|
180
|
+
- `get_origin_asn()`
|
|
181
|
+
- `get_origin_asns()`
|
|
182
|
+
- `has_as_path()`
|
|
183
|
+
- `to_dict()` / `as_dict()`
|
|
184
|
+
- `origin_asn` property
|
|
185
|
+
- `to_json()`
|
|
186
|
+
- `to_psv()`
|
|
187
|
+
- `Elem.get_psv_header()`
|
|
188
|
+
- module constants: `ELEM_TYPE_ANNOUNCE`, `ELEM_TYPE_WITHDRAW`, `PSV_HEADER`
|
|
189
|
+
|
|
190
|
+
`Parser` also provides stream-consuming helpers:
|
|
191
|
+
|
|
192
|
+
- `count()`
|
|
193
|
+
- `iter_batches(batch_size)`
|
|
194
|
+
- `iter_tuples(fields)` — recommended for high-performance subset-field scans
|
|
195
|
+
- `iter_tuple_batches(fields, batch_size)` — recommended for large-file scans
|
|
196
|
+
|
|
197
|
+
## Route-level parsing
|
|
198
|
+
|
|
199
|
+
`RouteParser` exposes upstream `BgpRouteElem` iteration for faster scans when you only need route identity fields:
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from pybgpkit_parser import RouteParser
|
|
203
|
+
|
|
204
|
+
for route in RouteParser(url):
|
|
205
|
+
print(route.timestamp, route.peer_ip, route.peer_asn, route.prefix, route.as_path)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`RouteElem` fields:
|
|
209
|
+
|
|
210
|
+
- `timestamp`
|
|
211
|
+
- `elem_type`
|
|
212
|
+
- `peer_ip`
|
|
213
|
+
- `peer_asn`
|
|
214
|
+
- `prefix`
|
|
215
|
+
- `as_path`
|
|
216
|
+
|
|
217
|
+
`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)`.
|
|
218
|
+
|
|
219
|
+
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)`.
|
|
220
|
+
|
|
221
|
+
## Build and publish
|
|
222
|
+
|
|
223
|
+
See [BUILD.md](./BUILD.md) for automated GitHub Actions release details.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
pybgpkit_parser/__init__.py,sha256=rtvtzRBAk2Xe9Pdf7EvUHxIzkpU1TC7mdA47sWTIVTc,143
|
|
2
|
+
pybgpkit_parser/pybgpkit_parser.pyd,sha256=Sc0jM4X0P1nfyp-iUxKWhpUalUjKslqKczN2k7gxZl0,8072704
|
|
3
|
+
pybgpkit_parser-0.7.0.dist-info/METADATA,sha256=C0_cBkp9AczKv2U2TXDiC4_EVfLv0byZ9KQYmNLWC2s,6111
|
|
4
|
+
pybgpkit_parser-0.7.0.dist-info/WHEEL,sha256=dB50znGoqD95tHNeV5UBZvlfLNwgEh0iQcswp5YahQ4,95
|
|
5
|
+
pybgpkit_parser-0.7.0.dist-info/licenses/LICENSE,sha256=MVs1lXfIqN0jpgf_O0g4mdZeP774D1Z4nWFss25E93U,1084
|
|
6
|
+
pybgpkit_parser-0.7.0.dist-info/sboms/pybgpkit-parser.cyclonedx.json,sha256=zsNe7gDeLDZ37poYcyeDISZ3laHBTXXsS78-gMQcrrk,202080
|
|
7
|
+
pybgpkit_parser-0.7.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 BGPKIT
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|