asciigraf


Nameasciigraf JSON
Version 1.1.0 PyPI version JSON
download
home_page
SummaryA python library for making ascii-art into network graphs.
upload_time2023-11-02 14:30:04
maintainer
docs_urlNone
authorOpus One Solutions
requires_python
licensecopyright 2017 Anton Lodder Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords graph network testing parser
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            asciigraf
=========

.. image:: https://img.shields.io/badge/License-MIT-yellow.svg
    :target: https://opensource.org/licenses/MIT

.. image:: https://badge.fury.io/py/asciigraf.svg
    :target: https://pypi.python.org/pypi/asciigraf

.. image:: https://img.shields.io/pypi/pyversions/asciigraf.svg
    :target: https://pypi.python.org/pypi/asciigraf

.. image:: https://api.codeclimate.com/v1/badges/e7e872f6832da6cf6ab6/maintainability
   :target: https://codeclimate.com/github/opusonesolutions/asciigraf/maintainability
   :alt: Maintainability

Asciigraf is a python library that turns ascii diagrams of networks into
network objects. It returns a `networkx <https://networkx.github.io/>`__
graph of nodes for each alpha-numeric element in the input text; nodes
are connected in the graph to match the edges represented in the diagram
by ``-``, ``/``, ``\`` and ``|``.

Installation
------------

Asciigraf can be installed from pypi using pip:

.. code::

    ~/$ pip install asciigraf

Usage
-----

Asciigraf expects a string containg a 2-d ascii diagram. Nodes can be an
alphanumeric string composed of words, sentences and punctuation (for a look at
what is all tested to work, see the `node recognition tests`_). Edges can be
composed of ``-``, ``/``, ``\`` and ``|``.

.. _node recognition tests: https://github.com/opusonesolutions/asciigraf/blob/master/tests/test_node_match.py

.. code:: python


    import asciigraf

    network = asciigraf.graph_from_ascii("""
              NodeA-----
                       |
                       |---NodeB
                                         """)

    print(network)
    >>> <networkx.classes.graph.Graph at 0x7f24c3a8b470>

    print(network.edges())
    >>> [('NodeA', 'NodeB')]

    print(network.nodes())
    >>> ['NodeA', 'NodeB']


Networkx provides tools to attach data to graphs, nodes and edges, and asciigraf
leverages these in a number of ways; in the example below you can see that
asciigraf uses this to attach a ``x, y`` position tuple to each node
indicating the line/col position of each node ( *0,0* is at the top-left).
It also attaches a ``length`` attribute
to each edge which matches the number of characters in that edge, as well
as a list of positions for each character an edge. In addition, the input data
is attached as a graph attribute ``ascii_string`` for reference.

.. code:: python

    print(network.nodes(data=True))
    >>> [('NodeA', {'position': (10, 1)}), ('NodeB', {'position': (23, 3)})]

    print(network.edges(data=True))
    >>> [('NodeA', 'NodeB', OrderedDict([('length', 10), 'points', [...]))]
    
    print(network.edge['NodeA']['NodeB']['points'])
    >>> [(15, 1), (16, 1), (17, 1), (18, 1),
         (19, 1), (19, 2), (19, 3), (20, 3), (21, 3), (22, 3)]

    print(network.graph["ascii_string"])
    >>>
        NodeA-----
                 |
                 |---NodeB


Asciigraf also lets you annotate the edges of graphs using in-line labels ---
denoted by parentheses. The contents of the label will be attached to the edge
on which it is drawn with the attribute name ``label``.

.. code:: python

    network = asciigraf.graph_from_ascii("""

        A---(nuts)----B----(string)---C
                      |
                      |
                      |
                      D---(pebbles)----E

    """)

    print(network.get_edge_data("A", "B")["label"])
    >>> nuts

    print(network.get_edge_data("B", "C")["label"])
    >>> string

    print(network.get_edge_data("D", "E")["label"])
    >>> pebbles

    print(hasattr(network.get_edge_data("B", "D"), "label"))
    >>> False


Have fun!

.. code:: python

    import asciigraf


    network = asciigraf.graph_from_ascii("""
              s---p----1---nx
             /    |        |
            /     |        0---f
           6l-a   c--
          /   |      \--k
         /   ua         |  9e
        q      \        | /
                \-r7z   jud
                    \    |
                     m   y
                      \  |
                       v-ow
                                 """)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "asciigraf",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "graph,network,testing,parser",
    "author": "Opus One Solutions",
    "author_email": "rnd@opusonesolutions.com",
    "download_url": "https://files.pythonhosted.org/packages/a7/d6/a7ba4bd0fdfe71b2d09c0aba4e641b48c698e01edcc7cc67c8c546ec85f9/asciigraf-1.1.0.tar.gz",
    "platform": null,
    "description": "asciigraf\n=========\n\n.. image:: https://img.shields.io/badge/License-MIT-yellow.svg\n    :target: https://opensource.org/licenses/MIT\n\n.. image:: https://badge.fury.io/py/asciigraf.svg\n    :target: https://pypi.python.org/pypi/asciigraf\n\n.. image:: https://img.shields.io/pypi/pyversions/asciigraf.svg\n    :target: https://pypi.python.org/pypi/asciigraf\n\n.. image:: https://api.codeclimate.com/v1/badges/e7e872f6832da6cf6ab6/maintainability\n   :target: https://codeclimate.com/github/opusonesolutions/asciigraf/maintainability\n   :alt: Maintainability\n\nAsciigraf is a python library that turns ascii diagrams of networks into\nnetwork objects. It returns a `networkx <https://networkx.github.io/>`__\ngraph of nodes for each alpha-numeric element in the input text; nodes\nare connected in the graph to match the edges represented in the diagram\nby ``-``, ``/``, ``\\`` and ``|``.\n\nInstallation\n------------\n\nAsciigraf can be installed from pypi using pip:\n\n.. code::\n\n    ~/$ pip install asciigraf\n\nUsage\n-----\n\nAsciigraf expects a string containg a 2-d ascii diagram. Nodes can be an\nalphanumeric string composed of words, sentences and punctuation (for a look at\nwhat is all tested to work, see the `node recognition tests`_). Edges can be\ncomposed of ``-``, ``/``, ``\\`` and ``|``.\n\n.. _node recognition tests: https://github.com/opusonesolutions/asciigraf/blob/master/tests/test_node_match.py\n\n.. code:: python\n\n\n    import asciigraf\n\n    network = asciigraf.graph_from_ascii(\"\"\"\n              NodeA-----\n                       |\n                       |---NodeB\n                                         \"\"\")\n\n    print(network)\n    >>> <networkx.classes.graph.Graph at 0x7f24c3a8b470>\n\n    print(network.edges())\n    >>> [('NodeA', 'NodeB')]\n\n    print(network.nodes())\n    >>> ['NodeA', 'NodeB']\n\n\nNetworkx provides tools to attach data to graphs, nodes and edges, and asciigraf\nleverages these in a number of ways; in the example below you can see that\nasciigraf uses this to attach a ``x, y`` position tuple to each node\nindicating the line/col position of each node ( *0,0* is at the top-left).\nIt also attaches a ``length`` attribute\nto each edge which matches the number of characters in that edge, as well\nas a list of positions for each character an edge. In addition, the input data\nis attached as a graph attribute ``ascii_string`` for reference.\n\n.. code:: python\n\n    print(network.nodes(data=True))\n    >>> [('NodeA', {'position': (10, 1)}), ('NodeB', {'position': (23, 3)})]\n\n    print(network.edges(data=True))\n    >>> [('NodeA', 'NodeB', OrderedDict([('length', 10), 'points', [...]))]\n    \n    print(network.edge['NodeA']['NodeB']['points'])\n    >>> [(15, 1), (16, 1), (17, 1), (18, 1),\n         (19, 1), (19, 2), (19, 3), (20, 3), (21, 3), (22, 3)]\n\n    print(network.graph[\"ascii_string\"])\n    >>>\n        NodeA-----\n                 |\n                 |---NodeB\n\n\nAsciigraf also lets you annotate the edges of graphs using in-line labels ---\ndenoted by parentheses. The contents of the label will be attached to the edge\non which it is drawn with the attribute name ``label``.\n\n.. code:: python\n\n    network = asciigraf.graph_from_ascii(\"\"\"\n\n        A---(nuts)----B----(string)---C\n                      |\n                      |\n                      |\n                      D---(pebbles)----E\n\n    \"\"\")\n\n    print(network.get_edge_data(\"A\", \"B\")[\"label\"])\n    >>> nuts\n\n    print(network.get_edge_data(\"B\", \"C\")[\"label\"])\n    >>> string\n\n    print(network.get_edge_data(\"D\", \"E\")[\"label\"])\n    >>> pebbles\n\n    print(hasattr(network.get_edge_data(\"B\", \"D\"), \"label\"))\n    >>> False\n\n\nHave fun!\n\n.. code:: python\n\n    import asciigraf\n\n\n    network = asciigraf.graph_from_ascii(\"\"\"\n              s---p----1---nx\n             /    |        |\n            /     |        0---f\n           6l-a   c--\n          /   |      \\--k\n         /   ua         |  9e\n        q      \\        | /\n                \\-r7z   jud\n                    \\    |\n                     m   y\n                      \\  |\n                       v-ow\n                                 \"\"\")\n",
    "bugtrack_url": null,
    "license": "copyright 2017 Anton Lodder  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "A python library for making ascii-art into network graphs.",
    "version": "1.1.0",
    "project_urls": {
        "repository": "https://github.com/opusonesolutions/asciigraf"
    },
    "split_keywords": [
        "graph",
        "network",
        "testing",
        "parser"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "929d79e3ed3170b5116239f308bc42c3a6c5dfe6f114624a36b6243a0c379bfe",
                "md5": "be328b907c4e21167e0bffbc0127afd1",
                "sha256": "a308a9a5f785970299255b430d48d1fd2c3addf7a0c4aea749d0957aa09326cc"
            },
            "downloads": -1,
            "filename": "asciigraf-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "be328b907c4e21167e0bffbc0127afd1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10821,
            "upload_time": "2023-11-02T14:30:01",
            "upload_time_iso_8601": "2023-11-02T14:30:01.470743Z",
            "url": "https://files.pythonhosted.org/packages/92/9d/79e3ed3170b5116239f308bc42c3a6c5dfe6f114624a36b6243a0c379bfe/asciigraf-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a7d6a7ba4bd0fdfe71b2d09c0aba4e641b48c698e01edcc7cc67c8c546ec85f9",
                "md5": "86a2b1f8a6452a0e7a3fe191c74e4fba",
                "sha256": "641f8e3c97642ba812d3640246ed236e58b533a1322123ed46f9b06357d9102b"
            },
            "downloads": -1,
            "filename": "asciigraf-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "86a2b1f8a6452a0e7a3fe191c74e4fba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 11856,
            "upload_time": "2023-11-02T14:30:04",
            "upload_time_iso_8601": "2023-11-02T14:30:04.272578Z",
            "url": "https://files.pythonhosted.org/packages/a7/d6/a7ba4bd0fdfe71b2d09c0aba4e641b48c698e01edcc7cc67c8c546ec85f9/asciigraf-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-02 14:30:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "opusonesolutions",
    "github_project": "asciigraf",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "asciigraf"
}
        
Elapsed time: 0.16133s