{"id":16130568,"url":"https://github.com/a-r-j/graphtype","last_synced_at":"2025-03-18T14:31:01.752Z","repository":{"id":45207370,"uuid":"513098478","full_name":"a-r-j/graphtype","owner":"a-r-j","description":"Type hinting for networkx Graphs","archived":false,"fork":false,"pushed_at":"2022-07-13T11:51:43.000Z","size":21,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-16T21:02:59.602Z","etag":null,"topics":["data-science","graph","graph-algorithms","graph-theory","network-analysis","networkx","pydata","python","scientific-computing","typehinting","typehints"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/graphtype/","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a-r-j.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-12T10:31:12.000Z","updated_at":"2024-12-24T01:29:42.000Z","dependencies_parsed_at":"2022-09-26T21:21:46.795Z","dependency_job_id":null,"html_url":"https://github.com/a-r-j/graphtype","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-r-j%2Fgraphtype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-r-j%2Fgraphtype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-r-j%2Fgraphtype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-r-j%2Fgraphtype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a-r-j","download_url":"https://codeload.github.com/a-r-j/graphtype/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244240071,"owners_count":20421395,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-science","graph","graph-algorithms","graph-theory","network-analysis","networkx","pydata","python","scientific-computing","typehinting","typehints"],"created_at":"2024-10-09T22:16:46.135Z","updated_at":"2025-03-18T14:31:01.428Z","avatar_url":"https://github.com/a-r-j.png","language":"Jupyter Notebook","readme":"# graphtype\n\nType hinting for networkx Graphs\n\n## Installation\n\n```python\npip install graphtype\n```\n\n## Usage\n\nThere are two parts in graphtype: the type-hinting part, and the validation. You can use type-hinting with the provided class to indicate attributes graphs should possess, and the validation decorator to additionally ensure the format is respected in every function call.\n\n### Type-Hinting `Graph`\n\n```python\nfrom graphtype import Graph\n\ndef do_something_to_graph(g: Graph)\n    pass\n```\n\n### Type-Hinting Graph Attributes `GraphData`\n\n```python\nfrom graphtype import Graph, GraphData\n\n\ndef do_something_to_graph(g: Graph[GraphData[\"name\"]])\n    pass\n\n# The graph must have a \"name\" attribute\n\ndef do_something_to_graph(g: Graph[GraphData[\"name\": str]])\n    pass\n\n# type(g.graph[\"name\"]) == str must be True\n```\n\n### Type-Hinting Node Attributes `NodeData`\n\n```python\nfrom graphtype import Graph, NodeData\n\ndef do_something_to_graph(g: Graph[NodeData[\"feature\"]])\n    pass\n\n# Each node must have a \"feature\" attribute\n\ndef do_something_to_graph(g: Graph[NodeData[\"feature\": np.ndarray]])\n    pass\n\n# for n, d in g.nodes(data=True):\n#   type(d[\"feature\"]) == np.ndarray must be True\n```\n\n### Type-Hinting Edge Attributes `EdgeData`\n\n```python\nfrom graphtype import Graph, EdgeData\n\ndef do_something_to_graph(g: Graph[EdgeData[\"feature\"]])\n    pass\n\n# Each edge must have a \"feature\" attribute\n\ndef do_something_to_graph(g: Graph[EdgeData[\"feature\": pd.DataFrame]])\n    pass\n\n# for u, v, d in g.edges(data=True):\n#   type(d[\"feature\"]) == pd.DataFrame must be True\n```\n\n## Enforcing: `@validate`\n\nThe `@validate` decorator ensures that input `Graphs` have the right format when the function is called, otherwise raises `TypeError`.\n\n```python\n@validate\ndef func(g: Graph[NodeData[\"feature1\": pd.DataFrame, \"feature2\": int],\n                  EdgeData[\"length\": float, \"counts\": np.ndarray],\n                  GraphData[\"name\": str]],\n         h: Graph[NodeData[\"feature1\": pd.DataFrame, \"feature2\": int]],\n         ):\n    pass\n```\n\nThis package is heavily inspired by [Dataenforce](https://github.com/CedricFR/dataenforce).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-r-j%2Fgraphtype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa-r-j%2Fgraphtype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-r-j%2Fgraphtype/lists"}