Skip to main content

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

  1. Install Poetry
  2. Clone the repo: git clone https://github.com/clay584/knex && cd knex
  3. Install pre-requisits for developement: poetry install
  4. Activate the environment: poetry shell
  5. Install git pre-commit hook: pre-commit install && pre-commit autoupdate

Making Changes

  1. Run tests and validate coverage: pytest -v --cov=knex --cov-report html tests
  2. Commit all changes, and have clean git repo on main branch.
  3. Bump version: bump2version <major|minor|patch>
  4. Push to git: git push && git push --tags
  5. Build for PyPI: Automatically done by Github Actions when a tag is pushed.
  6. Publish to PyPI: Automatically done by Github Actions when a tag is pushed.

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

knex-0.2.7.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

knex-0.2.7-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file knex-0.2.7.tar.gz.

File metadata

  • Download URL: knex-0.2.7.tar.gz
  • Upload date:
  • Size: 17.1 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

Hashes for knex-0.2.7.tar.gz
Algorithm Hash digest
SHA256 ea2b82653967e97acab3d7797642396cfe87504e4fcf9b40d97c6a7ea925bf20
MD5 7060778bfa06c4fcd132ef2ed1aaaa64
BLAKE2b-256 ba3d67638f8d2aff584d18ab17548ff09a0d806433d3278c4f593be7604de9f5

See more details on using hashes here.

File details

Details for the file knex-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: knex-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 17.2 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

Hashes for knex-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f29a3cd8ec61a7be6379c1023e59ffb2976db52ca6ef944b0c3b51125769cae7
MD5 916463f21a95c33ef7d0729c01ce197a
BLAKE2b-256 d3bf920dcb8541a9f925f3b6e5c064b47a9d080d7cdb9436e75e4b9e65cf4dca

See more details on using hashes here.

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