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"
}
]
>>>
Development
Environment Setup
- Install Poetry
- Clone the repo:
git clone https://github.com/clay584/knex && cd knex
- Install pre-requisits for developement:
poetry install
- Activate the environment:
poetry shell
- Install git pre-commit hook:
pre-commit install && pre-commit autoupdate
Making Changes
- Run tests and validate coverage:
pytest -v --cov=knex --cov-report html tests
- Commit all changes, and have clean git repo on
main
branch. - Bump version:
bump2version <major|minor|patch>
- Push to git:
git push && git push --tags
- Build for PyPI: Automatically done by Github Actions when a tag is pushed.
- Publish to PyPI: Automatically done by Github Actions when a tag is pushed.
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.2.21.tar.gz
(17.2 kB
view details)
Built Distribution
knex-0.2.21-py3-none-any.whl
(17.4 kB
view details)
File details
Details for the file knex-0.2.21.tar.gz
.
File metadata
- Download URL: knex-0.2.21.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.10 CPython/3.8.2 Linux/5.8.0-1041-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e65e93404bf5651f9a8abee96ad249fb080b725041b762e9651f65f5aeffe5e3 |
|
MD5 | cd6de7eb54284ab125480a1aaeba4720 |
|
BLAKE2b-256 | 0e6847bdaad510beb2e34d3607fa75b85ce815006272c1e7ca72fa08d800a884 |
File details
Details for the file knex-0.2.21-py3-none-any.whl
.
File metadata
- Download URL: knex-0.2.21-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.10 CPython/3.8.2 Linux/5.8.0-1041-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 813f4361ebedf82662b29ca47d8555b974ba0343a8c24a64662063327ba266b9 |
|
MD5 | 5a8c8279dd3a94ed21fe8b4128cc4d5c |
|
BLAKE2b-256 | 5c4ac7248abe5db17c27361939d302b3b52e8f7a3cd1a2a48cf568be85710c87 |