Package: grapresso
Caffeinated object-oriented Python graph data structure libraryoriginated from an academical context.Grapresso☕ is like a good espresso among other graph libs:Quickly consumed: Easy-to-learn and setup -just try it!Different flavours: Suit up yourbackend of choiceBeans are first class: Object-oriented approach with nodes as firstclass citizensMake your Macchiato: Extensible by designConcentrated:Clear and concisealgorithmsWell tested ingredients:Integration-testedusinghugegraphsClean and lightweight: Written in purePython 3,no other libraries neededGrapresso works wonderfully with PyPy and is up toup to 4x faster than your regular Python. ⚡This project is in an early state. There are many popular algorithms that arenotyet implemented (at least natively, read below)
Feel free to contribute! Make it feel like home for your own graph algorithms.GoalsGrapresso vs. alternativesThere are many other good graph/network theory libraries.
The most popular Python one is probablyNetworkX.From an algorithmic perspective, Grapresso will never be able to beat this extremely versatile library with a long history.
Instead, it follows a different philosophy and aims to be...Object-orientedinstead of using dicts for everythingAbstracted and modularthrough separation of concernsFinally, ameta libraryto handle other libraries via backends💡 To fully demonstrate the power of abstraction, Grapresso can be used as a middleman for NetworkX.UsageInstall from PyPI, for instance via pip (needs Python >= 3.6):pipinstallgrapressoWant to get the cheapest tour (round-trip) forTSP? Usage is easy:fromgrapressoimportGraph# Build a fully connected graph using InMemoryBackend (default if no backend is given):graph=Graph()\.add_edge("Aachen","Amsterdam",cost=230)\.add_edge("Amsterdam","Brussels",cost=200)\.add_edge("Brussels","Aachen",cost=142)# Now also add Luxembourg - note that every city needs to be connected to it for the graph to stay fully connected:forcity,distinzip(("Aachen","Brussels","Amsterdam"),(200,212,420)):graph.add_edge(city,"Luxembourg",cost=dist)tour=graph.cheapest_tour("Aachen")asserttour.cost==842print(tour)Now, printing to console is not really visually appealing, is it?
Let's install a backend pluginas an extrathat is also capable of drawing the graph:pipinstallgrapresso[backend-networkx]Let's quickly draw our previous graph by first converting it to one that uses NetworkX in the background
and then utilizing NetworkX's natural drawing capabilities:fromgrapresso.backendsimportNetworkXBackendnx_graph=graph.copy_to(Graph(NetworkXBackend(directed=False)))nx_graph.backend.quick_draw(# Map ISO codes to the nodes so that the text fits in the boundaries:labels={'Aachen':'AC','Amsterdam':'AMS','Brussels':'BR','Luxembourg':'LUX'},# Show cost as label:edge_label_selector='cost',# Mark edges that are actually in the tourmark_edges=tour.edges,)The resulting image:Seetests directoryfor more examples and also have a look at theintegration tests!ArchitectureGrapresso provides a clean API so that you can easily extend it to store the graph's structure in your preferred storage format.
Algorithms are implemented completely independent from the backend.BackendsAlgorithms are performed on a so called "backend" which wraps the graph's internal data structure.The API is defined inbackend/api.py. Therewith, backends can easily be added provided that they carefully implement the defined API.ImplementationsImplementationTypeUnderlying data structurePlugin installationInMemoryBackendIn-Memory with Traits{node_name: obj}with obj containing edgesBuilt-inNetworkXBackendNetworkXcompatiblenx.DiGraph with custom NetworkXNode/-Edgepip install grapresso[backend-networkx]DevelopmentThis project has been originated in the subjectMathematical Methods for Computer Science(translated from the German "Mathematische Methoden der Informatik", abbreviatedMMI)
in the study programme Information Systems Engineering (ISE) at the FH Aachen.ContributingContributions are welcome, as long as the threegoalsare followed.Otherwise, you can simply support this project by hitting thebutton.
Thanks!