Python library for creating chainable data transformers.
pip install knex
❌ - Planned
✔️ - Implemented
General | String | Number | Date | Other |
---|---|---|---|---|
✔️ Append | ✔️ Base64Decode | ❌ Absolute | ❌ BetweenDates | ❌ AsnToInt |
✔️ Count | ✔️ Base64Encode | ❌ Add | ❌ BetweenHours | ❌ DecodeCiscoType7 |
✔️ FirstElement | ✔️ Concat | ❌ Ceil | ❌ DateStringToISOFormat | ❌ EncodeCiscoType7 |
✔️ GetField | ❌ Cut | ❌ Divide | ❌ DateToEpoch | ❌ EncryptCiscoType5 |
✔️ GetIndex | ❌ DumpJSON | ❌ Floor | ❌ DateToString | ❌ FuzzyWuzzyFind |
❌ If-Then-Else | ❌ FromString | ❌ Modulus | ❌ FormattedDateToEpoch | ❌ InterfaceRangeExpand |
✔️ IndexOf | ❌ GenieParse | ❌ Multiply | ❌ ModifyDateTime | ❌ IpProtocolNameToNumber |
✔️ Join | ❌ JSONUnescape | ❌ Round | ❌ TimeStampToDate | ❌ IpProtocolNumberToName |
❌ Jq | ❌ Jinja2Render | ❌ Subtract | ❌ JsonSchemaValidate | |
❌ JsonToTable | ✔️ Length | ❌ SumList | ✔️ MacAddress | |
✔️ LastElement | ❌ LoadJSON | ❌ ToPercent | ❌ NormalInterfaceName | |
❌ ReverseList | ✔️ RegexExtractAll | ❌ PythonFunction | ||
❌ SetIfEmpty | ❌ RegexReplace | ❌ Random | ||
❌ Slice | ✔️ Split | ❌ SortInterfaceList | ||
❌ Sort | ❌ Substring | ✔️ TextFSMParse | ||
❌ Stringify | ❌ TemplateRender | ❌ ThisOrThat | ||
❌ Unique | ✔️ ToLower | ❌ ToCamelCase | ||
❌ WhereFieldEquals | ❌ ToString | ❌ ToSnakeCase | ||
✔️ ToUpper | ❌ Ttp | |||
❌ Trim | ❌ URLDecode | |||
❌ YamlDumps | ❌ URLEncode | |||
❌ YamlLoads | ❌ ValidateCiscoType5 | |||
❌ ValidateCiscoType7 | ||||
❌ VlanConfigToList | ||||
❌ YamaleValidate |
>>> 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"
}
]
>>>
- 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
- Run tests and validate coverage:
pytest -v --cov=knex --cov-report html tests
- The HTML coverage report will be located at
./htmlcov/index.html
.
- The HTML coverage report will be located at
- 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.
Docs are created automatically using mkdocs
and mkdocstring
.
Testing docs live can be done using mkdocs serve -a localhost:<port>
.
Docs are built and published automatically using Github Actions.
- Add the tests for the parser in
./tests/test_knex.py
. - Add the parser in
./knex/parsers.py
with docstrings. - Write amazing code until all tests are passing.
- Add the parser in
./knex/__init__.py
. - Add the parser in
./gen_table.py
. - Run
./gen_table.py
. It will generate that stupid markdown table - Run tests and validate coverage:
pytest -v --cov=knex --cov-report html tests
- The HTML coverage report will be located at
./htmlcov/index.html
.
- The HTML coverage report will be located at
There are a few of the CI tools that require standard requirements.txt format (not Poetry). Therefore when adding new dependencies with Poetry, we need to sync those to regular old requirements.txt files. This can be done with the following commands.
poetry export --without-hashes -f requirements.txt > requirements.txt
poetry export --without-hashes -f requirements.txt --dev > requirements-dev.txt
Pre-commit will make sure these are in sync if we forget.