pygraph-tool


Namepygraph-tool JSON
Version 0.2.0 PyPI version JSON
download
home_page
Summarypygraph-tool is a module to create and manipulate graphs.
upload_time2023-01-31 21:29:45
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT
keywords graph pygraph pygraph-tool nodes edges node edge
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pygraph-tool

pygraph-tool is a module to create and manipulate graphs. Nodes can be all objects who you want and edges are oriented and valued at 1 by default. If you wish one graph not oriented, edges must be declared in one direction and then in the other.

## Getting started

### Import modules
Graph module:
```python
from pygraph_tool import Graph
```
Exceptions module:
```python
from pygraph_tool import (
    NodeException,
    EdgeException,
    GraphException
)
```
Others modules (optional):
```python
from pygraph_tool import Node, Edge
```

### Create new graph
The new graph is empty (No node and no edge).
```python
graph: Graph = Graph()
```

### Create new nodes in graph
Create new nodes n1, n2 and n3, three nodes of graph.
```python
graph.add_node("I'm n1", "n1")
graph.add_node("I'm n2", "n2")
graph.add_node("I'm n3", "n3")
```
If node already exists(same id), the `GraphException` is raise.
```python
try:
    graph.add_node("I'm n1 again", "n1")
except GraphException as error:
    pass  # or do something...
```
If an argument is `None`, the `NodeException` is raise.

### Create new unidirectional edge in graph
Create new edges e1 such as n1->n2 with weight = 1.5, 
e2 such as n3->n2 with weight by default = 1 and 
e3 such as n1->n3 with weight by default = 1
```python
graph.add_unidirectional_edge("n1", "n2", "e1", 1.5)
graph.add_unidirectional_edge("n3", "n2", "e2")
graph.add_unidirectional_edge("n1", "n3", "e3")
```
If edge already exists (same id), the `GraphException` is raise.
```python
try:
    graph.add_unidirectional_edge("n2", "n3", "e1")
except GraphException as error:
    pass  # or do something...
```
If an argument (except `weight` argument) is `None`, the `EdgeException` is raise.

### Create new bidirectional edge in graph
coming soon...

### Remove node
If node doesn't exist in graph, `GraphException` is raise.
```python
try:
    graph.remove_node("n2")
except GraphException as error:
    pass  # or do something...
```

### Remove edge
If edge doesn't exist in graph, `GraphException` is raise.
```python
try:
    graph.remove_edge("e3")
except GraphException as error:
    pass  # or do something...
```

### Visualize the graph (very simple representation)
Create function for display graph
```python
def displayGraph(graph: Graph) -> None:
    # display the graph's nodes
    for node in graph.nodes:
        print(f"{node.node_id}: {node.node_content}")

    # display the graph's edges
    for edge in graph.edges:
        message: str = (
            f"{edge.node_start.node_id} "
            f"--- {edge.edge_id} = {edge.weight} ---> "
            f"{edge.node_end.node_id}"
        )
        print(message)


# Display graph
displayGraph(graph)
```

## Author
If you have any questions or suggestions, please don't hesitate to contact me : <belaich.david@outlook.fr>.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pygraph-tool",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "graph,pygraph,pygraph-tool,nodes,edges,node,edge",
    "author": "",
    "author_email": "BEL AICH David <belaich.david@outlook.fr>",
    "download_url": "https://files.pythonhosted.org/packages/db/5b/b3f9ad0801e6f56e6e2c553af5c5f8282df2043d5c34590cfa0fd9bfabb4/pygraph-tool-0.2.0.tar.gz",
    "platform": null,
    "description": "# pygraph-tool\n\npygraph-tool is a module to create and manipulate graphs. Nodes can be all objects who you want and edges are oriented and valued at 1 by default. If you wish one graph not oriented, edges must be declared in one direction and then in the other.\n\n## Getting started\n\n### Import modules\nGraph module:\n```python\nfrom pygraph_tool import Graph\n```\nExceptions module:\n```python\nfrom pygraph_tool import (\n    NodeException,\n    EdgeException,\n    GraphException\n)\n```\nOthers modules (optional):\n```python\nfrom pygraph_tool import Node, Edge\n```\n\n### Create new graph\nThe new graph is empty (No node and no edge).\n```python\ngraph: Graph = Graph()\n```\n\n### Create new nodes in graph\nCreate new nodes n1, n2 and n3, three nodes of graph.\n```python\ngraph.add_node(\"I'm n1\", \"n1\")\ngraph.add_node(\"I'm n2\", \"n2\")\ngraph.add_node(\"I'm n3\", \"n3\")\n```\nIf node already exists(same id), the `GraphException` is raise.\n```python\ntry:\n    graph.add_node(\"I'm n1 again\", \"n1\")\nexcept GraphException as error:\n    pass  # or do something...\n```\nIf an argument is `None`, the `NodeException` is raise.\n\n### Create new unidirectional edge in graph\nCreate new edges e1 such as n1->n2 with weight = 1.5, \ne2 such as n3->n2 with weight by default = 1 and \ne3 such as n1->n3 with weight by default = 1\n```python\ngraph.add_unidirectional_edge(\"n1\", \"n2\", \"e1\", 1.5)\ngraph.add_unidirectional_edge(\"n3\", \"n2\", \"e2\")\ngraph.add_unidirectional_edge(\"n1\", \"n3\", \"e3\")\n```\nIf edge already exists (same id), the `GraphException` is raise.\n```python\ntry:\n    graph.add_unidirectional_edge(\"n2\", \"n3\", \"e1\")\nexcept GraphException as error:\n    pass  # or do something...\n```\nIf an argument (except `weight` argument) is `None`, the `EdgeException` is raise.\n\n### Create new bidirectional edge in graph\ncoming soon...\n\n### Remove node\nIf node doesn't exist in graph, `GraphException` is raise.\n```python\ntry:\n    graph.remove_node(\"n2\")\nexcept GraphException as error:\n    pass  # or do something...\n```\n\n### Remove edge\nIf edge doesn't exist in graph, `GraphException` is raise.\n```python\ntry:\n    graph.remove_edge(\"e3\")\nexcept GraphException as error:\n    pass  # or do something...\n```\n\n### Visualize the graph (very simple representation)\nCreate function for display graph\n```python\ndef displayGraph(graph: Graph) -> None:\n    # display the graph's nodes\n    for node in graph.nodes:\n        print(f\"{node.node_id}: {node.node_content}\")\n\n    # display the graph's edges\n    for edge in graph.edges:\n        message: str = (\n            f\"{edge.node_start.node_id} \"\n            f\"--- {edge.edge_id} = {edge.weight} ---> \"\n            f\"{edge.node_end.node_id}\"\n        )\n        print(message)\n\n\n# Display graph\ndisplayGraph(graph)\n```\n\n## Author\nIf you have any questions or suggestions, please don't hesitate to contact me : <belaich.david@outlook.fr>.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "pygraph-tool is a module to create and manipulate graphs.",
    "version": "0.2.0",
    "split_keywords": [
        "graph",
        "pygraph",
        "pygraph-tool",
        "nodes",
        "edges",
        "node",
        "edge"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "071e8759b209198c12a5dc17b1b409b21b552f0d4e3216a2d33b8e310c3a61ac",
                "md5": "7c465f9b524c9c08581d856d56f6315f",
                "sha256": "522f5e5186c184a18084acc7f35b6d4515a2874156c57ba944db82711c776ee5"
            },
            "downloads": -1,
            "filename": "pygraph_tool-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7c465f9b524c9c08581d856d56f6315f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6217,
            "upload_time": "2023-01-31T21:29:44",
            "upload_time_iso_8601": "2023-01-31T21:29:44.045919Z",
            "url": "https://files.pythonhosted.org/packages/07/1e/8759b209198c12a5dc17b1b409b21b552f0d4e3216a2d33b8e310c3a61ac/pygraph_tool-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "db5bb3f9ad0801e6f56e6e2c553af5c5f8282df2043d5c34590cfa0fd9bfabb4",
                "md5": "25f7fce7b6f383d57072462f5e866429",
                "sha256": "43666f5daf6206c872c1270f248ef95419b6662ff33af26fc5e12b70c46d8075"
            },
            "downloads": -1,
            "filename": "pygraph-tool-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "25f7fce7b6f383d57072462f5e866429",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4962,
            "upload_time": "2023-01-31T21:29:45",
            "upload_time_iso_8601": "2023-01-31T21:29:45.607012Z",
            "url": "https://files.pythonhosted.org/packages/db/5b/b3f9ad0801e6f56e6e2c553af5c5f8282df2043d5c34590cfa0fd9bfabb4/pygraph-tool-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-31 21:29:45",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "pygraph-tool"
}
        
Elapsed time: 0.03549s