Skip to main content

An RFC 2622 conformant Routing Policy Specification Language (RPSL) parser with a focus on speed and correctness.

Project description


An RFC 2622 conformant Routing Policy Specification Language (RPSL) parser with a focus on speed and correctness.

⚡️ Outperforms other parsers by a factor of 33-60x
📰 Complete implementation for multiline RPSL values
💬 Able to parse objects directly from whois server responses
🧠 Low memory footprint by leveraging zero-copy
🧪 Robust parsing of any valid input ensured by Property Based Tests

Examples

Parsing RPSL

A string containing an object in RPSL notation can be parsed to a tuple with attribute name-value pairs.

from rpsl_parser import parse_rpsl_object

role_acme = """
role:        ACME Company
address:     Packet Street 6
address:     128 Series of Tubes
address:     Internet
email:       rpsl-parser@github.com
nic-hdl:     RPSL1-RIPE
source:      RIPE
"""
parsed = parse_rpsl_object(role_acme)
print(parsed)
(('role', ('ACME Company',)),
 ('address', ('Packet Street 6',)),
 ('address', ('128 Series of Tubes',)),
 ('address', ('Internet',)),
 ('email', ('rpsl-parser@github.com',)),
 ('nic-hdl', ('RPSL1-RIPE',)),
 ('source', ('RIPE',)))

Since RPSL attribute values may be spread over multiple lines and values consisting only of whitespace are valid, the tuple[str | None, ...] type is used to represent them.

Parsing a WHOIS server response

Whois servers often respond to queres with multiple objects. An example ARIN query for AS32934 will return with the requested ASNumber object first, followed by it's associated OrgName:

$ whois -h whois.arin.net AS32934
ASNumber:       32934
ASName:         FACEBOOK
ASHandle:       AS32934
RegDate:        2004-08-24
Updated:        2012-02-24
Comment:        Please send abuse reports to abuse@facebook.com
Ref:            https://rdap.arin.net/registry/autnum/32934


OrgName:        Facebook, Inc.
OrgId:          THEFA-3
Address:        1601 Willow Rd.
City:           Menlo Park
StateProv:      CA
PostalCode:     94025
Country:        US
RegDate:        2004-08-11
Updated:        2012-04-17
Ref:            https://rdap.arin.net/registry/entity/THEFA-3

To extract each individual object, the parse_whois_server_response function can be used as such:

from rpsl_parser import parse_whois_server_response

parsed = parse_whois_server_response(AS32934)
print(parsed)
((('ASNumber', ('32934',)),
  ('ASName', ('FACEBOOK',)),
  ('ASHandle', ('AS32934',)),
  ('RegDate', ('2004-08-24',)),
  ('Updated', ('2012-02-24',)),
  ('Comment', ('Please send abuse reports to abuse@facebook.com',)),
  ('Ref', ('https://rdap.arin.net/registry/autnum/32934',))),
 (('OrgName', ('Facebook, Inc.',)),
  ('OrgId', ('THEFA-3',)),
  ('Address', ('1601 Willow Rd.',)),
  ('City', ('Menlo Park',)),
  ('StateProv', ('CA',)),
  ('PostalCode', ('94025',)),
  ('Country', ('US',)),
  ('RegDate', ('2004-08-11',)),
  ('Updated', ('2012-04-17',)),
  ('Ref', ('https://rdap.arin.net/registry/entity/THEFA-3',))))

🚧 Work in progress

  • More descriptive error messages

    When invalid RPSL is parsed, the current error messages do not properly convey where exactly the error is located in the parsed text.

Installation

Using PyPI:

pip3 install rpsl-parser

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

rpsl_parser-0.1.1.tar.gz (228.7 kB view hashes)

Uploaded Source

Built Distributions

rpsl_parser-0.1.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (185.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rpsl_parser-0.1.1-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (257.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

rpsl_parser-0.1.1-pp310-pypy310_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (198.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

rpsl_parser-0.1.1-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (178.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

rpsl_parser-0.1.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (178.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

rpsl_parser-0.1.1-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl (192.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

rpsl_parser-0.1.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (185.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rpsl_parser-0.1.1-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (257.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

rpsl_parser-0.1.1-pp39-pypy39_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (198.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

rpsl_parser-0.1.1-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (178.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

rpsl_parser-0.1.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (178.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

rpsl_parser-0.1.1-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl (192.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

rpsl_parser-0.1.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (185.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rpsl_parser-0.1.1-pp38-pypy38_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (257.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

rpsl_parser-0.1.1-pp38-pypy38_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (198.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

rpsl_parser-0.1.1-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (178.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

rpsl_parser-0.1.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (178.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

rpsl_parser-0.1.1-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.whl (192.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

rpsl_parser-0.1.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (186.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rpsl_parser-0.1.1-pp37-pypy37_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (259.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

rpsl_parser-0.1.1-pp37-pypy37_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (199.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

rpsl_parser-0.1.1-pp37-pypy37_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (180.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

rpsl_parser-0.1.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (179.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

rpsl_parser-0.1.1-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.whl (193.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

rpsl_parser-0.1.1-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl (279.5 kB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ s390x

rpsl_parser-0.1.1-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (221.8 kB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ppc64le

rpsl_parser-0.1.1-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (198.4 kB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARMv7l

rpsl_parser-0.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (198.1 kB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

rpsl_parser-0.1.1-cp312-none-win_amd64.whl (114.1 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

rpsl_parser-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (184.9 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

rpsl_parser-0.1.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (249.3 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ s390x

rpsl_parser-0.1.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (197.6 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64le

rpsl_parser-0.1.1-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (177.8 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARMv7l

rpsl_parser-0.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (177.5 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

rpsl_parser-0.1.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl (191.8 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.5+ i686

rpsl_parser-0.1.1-cp311-none-win_amd64.whl (111.8 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

rpsl_parser-0.1.1-cp311-none-win32.whl (105.0 kB view hashes)

Uploaded CPython 3.11 Windows x86

rpsl_parser-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (185.1 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

rpsl_parser-0.1.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (256.2 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

rpsl_parser-0.1.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (198.1 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

rpsl_parser-0.1.1-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (178.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

rpsl_parser-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (178.1 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

rpsl_parser-0.1.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl (192.2 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.5+ i686

rpsl_parser-0.1.1-cp311-cp311-macosx_11_0_arm64.whl (168.6 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

rpsl_parser-0.1.1-cp311-cp311-macosx_10_7_x86_64.whl (179.5 kB view hashes)

Uploaded CPython 3.11 macOS 10.7+ x86-64

rpsl_parser-0.1.1-cp310-none-win_amd64.whl (111.8 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

rpsl_parser-0.1.1-cp310-none-win32.whl (105.0 kB view hashes)

Uploaded CPython 3.10 Windows x86

rpsl_parser-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (185.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

rpsl_parser-0.1.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (256.2 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

rpsl_parser-0.1.1-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (198.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

rpsl_parser-0.1.1-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (178.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

rpsl_parser-0.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (178.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

rpsl_parser-0.1.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl (192.2 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ i686

rpsl_parser-0.1.1-cp310-cp310-macosx_11_0_arm64.whl (168.6 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

rpsl_parser-0.1.1-cp310-cp310-macosx_10_7_x86_64.whl (179.5 kB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

rpsl_parser-0.1.1-cp39-none-win_amd64.whl (111.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

rpsl_parser-0.1.1-cp39-none-win32.whl (105.0 kB view hashes)

Uploaded CPython 3.9 Windows x86

rpsl_parser-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (185.1 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

rpsl_parser-0.1.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (256.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

rpsl_parser-0.1.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (198.1 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

rpsl_parser-0.1.1-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (178.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

rpsl_parser-0.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (178.1 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

rpsl_parser-0.1.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (192.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ i686

rpsl_parser-0.1.1-cp38-none-win_amd64.whl (112.1 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

rpsl_parser-0.1.1-cp38-none-win32.whl (105.2 kB view hashes)

Uploaded CPython 3.8 Windows x86

rpsl_parser-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (185.1 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

rpsl_parser-0.1.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl (256.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ s390x

rpsl_parser-0.1.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (198.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

rpsl_parser-0.1.1-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (177.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARMv7l

rpsl_parser-0.1.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (178.1 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

rpsl_parser-0.1.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl (192.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ i686

rpsl_parser-0.1.1-cp37-none-win_amd64.whl (112.0 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

rpsl_parser-0.1.1-cp37-none-win32.whl (105.2 kB view hashes)

Uploaded CPython 3.7 Windows x86

rpsl_parser-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (185.1 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

rpsl_parser-0.1.1-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl (256.4 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ s390x

rpsl_parser-0.1.1-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (198.2 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ppc64le

rpsl_parser-0.1.1-cp37-cp37m-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (177.9 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARMv7l

rpsl_parser-0.1.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (178.1 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

rpsl_parser-0.1.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.whl (192.2 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.5+ i686

Supported by

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