Graphinate is designed to be used as a library first and foremost.
In addition, it has the following interfaces for ease of use: a CLI and a GraphQL API (using Strawberry GraphQL).
The following code snippet shows basic simple usage of Graphinate.
It demonstrates how to wire a simple source function to a graph model, build graph representation of several types, and
render them. You can check the Tutorial for an in-depth step-by-step walkthrough, and
the Examples section for additional more complex use cases.
importgraphinateN:int=8# First Define a GraphModel instance.# It will be used to hold the graph definitionsgraph_model:graphinate.GraphModel=graphinate.model(name='Octagonal Graph')# Register in the Graph Model the edges' supplier generator function@graph_model.edge()defedge():foriinrange(N):yield{'source':i,'target':i+1}yield{'source':N,'target':0}# Use the NetworkX Builderbuilder=graphinate.builders.NetworkxBuilder(graph_model)# build the NetworkX GraphRepresentation# the output in this case is a nx.Graph instancegraph=builder.build()# this supplied plot method uses matplotlib to display the graphgraphinate.matplotlib.plot(graph,with_edge_labels=True)# or use the Mermaid Builderbuilder=graphinate.builders.MermaidBuilder(graph_model)# to create a Mermaid diagramdiagram:str=builder.build()# and get Markdown or single page HTML to display itmermaid_markdown:str=graphinate.mermaid.markdown(diagram)mermaid_html:str=graphinate.mermaid.html(diagram,title=graph_model.name)# or use the GraphQL Builderbuilder=graphinate.builders.GraphQLBuilder(graph_model)# to create a Strawberry GraphQL schemaschema=builder.build()# and serve it using Uvicorn web servergraphinate.graphql.server(schema)