Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Dijkstar

Dijkstar is an implementation of Dijkstra’s single-source shortest-paths algorithm. If a destination node is given, the algorithm halts when that node is reached; otherwise it continues until paths from the source node to all other nodes are found.

Accepts an optional cost (or “weight”) function that will be called on every iteration.

Also accepts an optional heuristic function that is used to push the algorithm toward a destination instead of fanning out in every direction. Using such a heuristic function converts Dijkstra to A* (and this is where the name “Dijkstar” comes from).

Performance is decent on a graph with 100,000+ nodes. Runs in around .5 seconds on average .

Example:

>>> from dijkstar import Graph, find_path
>>> graph = Graph()
>>> graph.add_edge(1, 2, {'cost': 1})
>>> graph.add_edge(2, 3, {'cost': 2})
>>> cost_func = lambda u, v, e, prev_e: e['cost']
>>> find_path(graph, 1, 2, cost_func=cost_func)

The cost function is passed the current node (u), a neighbor (v) of the current node, the edge that connects u to v, and the edge that was traversed previously to get to the current node. In the example above, the cost function simply returns the edge’s cost.

The graph can be saved to disk (pickled) like so:

>>> graph.dump(path)

And read back like this (load is a classmethod that returns a populated Graph instance):

>>> Graph.load(path)

Metadata

Release files for Dijkstar 2.0b2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Dijkstar 2.0b2
File Size Uploaded Provenance Actions
Dijkstar-2.0b2.tar.gz 6.0 kB Without provenance Details for Dijkstar-2.0b2.tar.gz

Release files / Dijkstar-2.0b2.tar.gz

Download URL Dijkstar-2.0b2.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
69ff9b91b979e033134da368030bba1d96ceca8f77803b49ec1188f0f6cfb8b7
BLAKE2b-256 checksum
How to use checksums
c9e45428e42494014e9d505033edbf58751d1b733c35e4dd3f38193efcc28179
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for Dijkstar 2.0b2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page