Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/clay584/knex
Python library for creating chainable parsers
https://github.com/clay584/knex
Last synced: about 1 month ago
JSON representation
Python library for creating chainable parsers
- Host: GitHub
- URL: https://github.com/clay584/knex
- Owner: clay584
- License: gpl-3.0
- Created: 2021-09-09T03:43:28.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-07T21:49:59.000Z (3 months ago)
- Last Synced: 2024-11-08T03:49:05.049Z (about 2 months ago)
- Language: Python
- Homepage: https://clay584.github.io/knex/
- Size: 563 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 19
-
Metadata Files:
- Readme: README-pypi.md
- License: LICENSE
Awesome Lists containing this project
README
# KNEX
Python library for creating chainable data transformers.
## Installation
`pip install knex`
## Usage
```python
>>> 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"
}
]
>>>```