{ "info": { "author": "Darin Sikanic", "author_email": "darin.sikanic@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "Intended Audience :: Telecommunications Industry", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: System :: Networking" ], "description": "Structify Text\n==============\n\nStructures semi-structured text, useful when parsing command line output\nfrom networking devices.\n\nWhat is it\n----------\n\n| If you\u2019re reading this you\u2019ve probably been tasked with\n programmatically retrieving information from a CLI driven device and\n you\u2019ve got to the point\n| where you have a nice string of text and say to yourself, \u201cwow I wish\n it just returned something structured that I could deal with like JSON\n or some other key/value format\u201d.\n\nWell that\u2019s where ``structifytext`` tries to help. It lets you define\nthe payload you wish came back to you, and with a sprinkle of the right\nregular expressions it does!\n\nInstallation\n------------\n\nWith pip:\n::\n\n pip install structifytext\n\nFrom source\n::\n\n make install\n\n\nUsage\n-----\n\nPass your text and a \"structure\" (python dictionary) to the ``parser`` modules ``parse`` method.\n\n::\n\n from structifytext import parser\n\n output = \"\"\"\n eth0 Link encap:Ethernet HWaddr 00:11:22:3a:c4:ac\n inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0\n UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1\n RX packets:147142475 errors:0 dropped:293854 overruns:0 frame:0\n TX packets:136237118 errors:0 dropped:0 overruns:0 carrier:0\n collisions:0 txqueuelen:1000\n RX bytes:17793317674 (17.7 GB) TX bytes:46525697959 (46.5 GB)\n\n eth1 Link encap:Ethernet HWaddr 00:11:33:4a:c8:ad\n inet addr:192.168.1.3 Bcast:192.168.1.255 Mask:255.255.255.0\n inet6 addr: fe80::225:90ff:fe4a:c8ad/64 Scope:Link\n UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1\n RX packets:51085118 errors:0 dropped:251 overruns:0 frame:0\n TX packets:3447162 errors:0 dropped:0 overruns:0 carrier:0\n collisions:0 txqueuelen:1000\n RX bytes:4999277179 (4.9 GB) TX bytes:657283496 (657.2 MB)\n \"\"\"\n \n struct = {\n 'interfaces': [{\n 'id': '(eth\\d{1,2})',\n 'ipv4_address': 'inet addr:(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})',\n 'mac_address': 'HWaddr\\s((?:[a-fA-F0-9]{2}[:|\\-]?){6})'\n }]\n }\n\n parsed = parser.parse(output, struct)\n print parsed\n\nThis will return the python dictionary\n\n::\n\n {\n 'interfaces': [\n {\n 'id': 'eth0',\n 'ipv4_address': '192.168.1.2',\n 'mac_address': '00:11:22:3a:c4:ac'\n },\n {\n 'id': 'eth1',\n 'ipv4_address': '192.168.1.3',\n 'mac_address': '00:11:33:4a:c8:ad'\n }\n ]\n }\n\nWhich you can then do with as you please, maybe return as JSON as part of a REST service...\n\nThe Struct\n~~~~~~~~~~\n\n| A stuct or structure or payload or whatever have you, is just a\n dictionary that resembles what you wish to get back.\n| With the values either being a dictionary ``{}``, a list ``[]``, or a\n regular expression string ``[a-z](\\d)`` with **one group** (to populate\n the value).\n\nThe structure is recursively parsed, populating the\ndictionary/structure that was provided with values from the input text.\n\n| Quite often, similar sections of semi-structured text are repeated in\n the text you are trying to parse.\n| To parse these sections of text, we define a dictionary with key of\n either ``id`` or ``block_start`` the difference being ``block_start``\n key/value is dropped from the resulting output.\n| This ``id`` or ``block_start`` marks the beginning and end for each\n \u201cchunk\u201d that you\u2019d like parsed.\n| You can forcefully mark the end of a \u201cchunk\u201d by specifying a\n ``block_end`` key and regex value.\n\nAn example is useful here.\n\nE.g. The following structure.\n\n::\n\n {\n 'tables': [\n {\n 'id': '\\[TABLE (\\d{1,2})\\]',\n 'flows': [\n {\n 'id': '\\[FLOW_ID(\\d+)\\]',\n 'info': 'info\\s+=\\s+(.*)'\n }\n ]\n }\n ]\n }\n\nWill create a \u201cchunk/block\u201d from the following output\n\n::\n\n [TABLE 0] Total entries: 3\n [FLOW_ID1]\n info = related to table 0 flow 1\n [TABLE 1] Total entries: 31\n [FLOW_ID1]\n info = related to table 1 flow 1\n\nThat will be parsed as:\n\n::\n\n {\n 'tables': [{\n 'id': '0',\n 'flows': [{ 'id': '1', 'info': 'related to table 0 flow 1' }],\n }, {\n 'id': '1',\n 'flows': [{ 'id': '1', 'info': 'related to table 1 flow 1' }]\n }]\n }\n\nSee under ``tests/test_parser_api.py`` for more usage examples.", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/darinsikanic/structifytext", "keywords": "sructuretext structifytext structure text network cli parser", "license": "Apache", "maintainer": "", "maintainer_email": "", "name": "structifytext", "package_url": "https://pypi.org/project/structifytext/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/structifytext/", "project_urls": { "Homepage": "https://github.com/darinsikanic/structifytext" }, "release_url": "https://pypi.org/project/structifytext/0.2.1/", "requires_dist": [ "six" ], "requires_python": "", "summary": "Structure semi-structured text", "version": "0.2.1" }, "last_serial": 2836056, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "ba595005797e3c5e4200568cea389906", "sha256": "d50ae1a91eb23375d1b407ff2fa950923f972e40abdfbf2e0b0694a8dd7c29d5" }, "downloads": -1, "filename": "structifytext-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ba595005797e3c5e4200568cea389906", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7906, "upload_time": "2017-04-24T08:30:49", "url": "https://files.pythonhosted.org/packages/7d/27/a28a4f5f39d36b50ef728659dada9612f15ce7125702147ac57ee1b3b7f4/structifytext-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6e26c3868dc1c6846b100428f7143832", "sha256": "acfc4db99fd4d9262c6b5145a75e22dd2e2c527b5456c177ae4d0692f1e1e343" }, "downloads": -1, "filename": "structifytext-0.1.1.tar.gz", "has_sig": false, "md5_digest": "6e26c3868dc1c6846b100428f7143832", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7567, "upload_time": "2017-04-24T08:30:52", "url": "https://files.pythonhosted.org/packages/d9/e0/cfa2f122368de5bb4d28101a8058014214121df3e87b8fcceb2669be6817/structifytext-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "15d381b6bb1f7948fac2e2793de3d6ab", "sha256": "2a5a543f7e25f7109dbaeb78aa46b5e40b99ae77856711d0fcaff2ba3497697f" }, "downloads": -1, "filename": "structifytext-0.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "15d381b6bb1f7948fac2e2793de3d6ab", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7940, "upload_time": "2017-04-24T13:45:50", "url": "https://files.pythonhosted.org/packages/3b/6e/80b5b3351424d34dc212002ee18c540750a04e2e9b672897f0ec40213f90/structifytext-0.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "adcd1040857b1487dcaddf0532aab0fc", "sha256": "fcbaba8be8b033b347948579bd1c0242d039935617439b74314e11807bd92dc3" }, "downloads": -1, "filename": "structifytext-0.2.0.tar.gz", "has_sig": false, "md5_digest": "adcd1040857b1487dcaddf0532aab0fc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7599, "upload_time": "2017-04-24T13:45:53", "url": "https://files.pythonhosted.org/packages/42/1e/9c79b82430956cfcadfdca89c2745b30c68823de131d28f503a7d7065c3e/structifytext-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "10d31a9fceac4aa920b79a6c7d5ff749", "sha256": "d023372a2398198613bcf6ee617039052031cbefddf6320afb6253ee9bf6a805" }, "downloads": -1, "filename": "structifytext-0.2.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "10d31a9fceac4aa920b79a6c7d5ff749", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7941, "upload_time": "2017-04-28T02:34:10", "url": "https://files.pythonhosted.org/packages/3b/a2/9b7a98f58c42e38cd5fcc2fc18f273224a42364aecfacf60029b04c24a4c/structifytext-0.2.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ba0a5aceeeddde5f37e41f07e1e5ab4b", "sha256": "2862521d5520b63c2929e7dca0a6a9211a5dc737e4a6b1b5d61c362185dfa541" }, "downloads": -1, "filename": "structifytext-0.2.1.tar.gz", "has_sig": false, "md5_digest": "ba0a5aceeeddde5f37e41f07e1e5ab4b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8222, "upload_time": "2017-04-28T02:34:12", "url": "https://files.pythonhosted.org/packages/43/a1/bb0072f15422183236aae37426957473eabd6889ee6655f163eb5c314afa/structifytext-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "10d31a9fceac4aa920b79a6c7d5ff749", "sha256": "d023372a2398198613bcf6ee617039052031cbefddf6320afb6253ee9bf6a805" }, "downloads": -1, "filename": "structifytext-0.2.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "10d31a9fceac4aa920b79a6c7d5ff749", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7941, "upload_time": "2017-04-28T02:34:10", "url": "https://files.pythonhosted.org/packages/3b/a2/9b7a98f58c42e38cd5fcc2fc18f273224a42364aecfacf60029b04c24a4c/structifytext-0.2.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ba0a5aceeeddde5f37e41f07e1e5ab4b", "sha256": "2862521d5520b63c2929e7dca0a6a9211a5dc737e4a6b1b5d61c362185dfa541" }, "downloads": -1, "filename": "structifytext-0.2.1.tar.gz", "has_sig": false, "md5_digest": "ba0a5aceeeddde5f37e41f07e1e5ab4b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8222, "upload_time": "2017-04-28T02:34:12", "url": "https://files.pythonhosted.org/packages/43/a1/bb0072f15422183236aae37426957473eabd6889ee6655f163eb5c314afa/structifytext-0.2.1.tar.gz" } ] }