Python library for building composable text parsers
Project description
KNEX
Python library for creating chainable data transformers.
Installation
pip install knex
Usage
>>> from knex.parsers import *
>>>
>>> input_data = """
... Interface IP-Address OK? Method Status Protocol
... GigabitEthernet0/1 unassigned YES unset up up
... GigabitEthernet0/2 192.168.190.235 YES unset up up
... GigabitEthernet0/3 unassigned YES unset up up
... GigabitEthernet0/4 192.168.191.2 YES unset up up
... TenGigabitEthernet2/1 unassigned YES unset up up
... Virtual36 unassigned YES unset up up
... """
>>>
>>> pattern = r"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"
>>>
>>> end = (
Start(input_data)
> RegexExtractAll(pattern)
> GetIndex(0)
> Concat("", "/24")
> IpNetwork()
)
>>>
>>> print(end.result)
192.168.190.0/24
>>> print(json.dumps(end.history, indent=4))
[
{
"parser": "RegexExtractAll",
"input": "...omitted for brevity...",
"args": {
"pattern": "\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b"
},
"error": false,
"output": [
"192.168.190.235",
"192.168.191.2"
]
},
{
"parser": "GetIndex",
"input": [
"192.168.190.235",
"192.168.191.2"
],
"args": {
"idx": 0
},
"error": false,
"output": "192.168.190.235"
},
{
"parser": "Concat",
"input": "192.168.190.235",
"args": {
"prefix": "",
"suffix": "/24"
},
"error": false,
"output": "192.168.190.235/24"
},
{
"parser": "IpNetwork",
"input": "192.168.190.235/24",
"args": {},
"error": false,
"output": "192.168.190.0/24"
}
]
>>>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
knex-0.4.0.tar.gz
(18.2 kB
view details)
Built Distribution
knex-0.4.0-py3-none-any.whl
(18.3 kB
view details)
File details
Details for the file knex-0.4.0.tar.gz
.
File metadata
- Download URL: knex-0.4.0.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.8.2 Linux/5.11.0-1020-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2bec3d1c627d0dd80dbe8cb2b2afa7ad99c25bcc208b8c50d3bb3b5a273b2ea |
|
MD5 | 3d2999ca72dd500725cafa9f9444d3a3 |
|
BLAKE2b-256 | 39ab0dd2d21e2ce14092fe840e1748e50ff2688eacf9cc31ca3174c8455c1999 |
File details
Details for the file knex-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: knex-0.4.0-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.8.2 Linux/5.11.0-1020-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59f31b819295f4dbda02e48cb09af52f4f30448fbd8d707319db62b967303667 |
|
MD5 | fef1d6b9fdc4bc1d335c715d283d5239 |
|
BLAKE2b-256 | 40bac03f39eb17dcc2580ef4eeebcfadd2a020c8164f1121624e83eec98d35ac |