Skip to main content

canonaut (Python)

Graph canonicalization and automorphism groups: Python bindings for canonaut, a safe Rust port of nauty. The PyPI package and the Rust crate share the name.

Install

pip install canonaut

Usage

Nodes can be any hashable value — ints, strings, tuples, whatever you already have. No need to relabel your graph to 0..n-1 first.

import canonaut

# Canonize a 4-cycle with arbitrary node labels
r = canonaut.canonize([("a","b"), ("b","c"), ("c","d"), ("d","a")])
print(r.num_orbits)          # 1  (vertex-transitive)
print(r.group_size1, r.group_size2)  # |Aut| ~= group_size1 * 10**group_size2
print(r.canonical_edges)     # edges of the canonical form (0..n-1 index space)

# Vertex colors (partition): vertices with different colors are never mapped
# onto each other by any automorphism, and the canonical form respects it.
r = canonaut.canonize(
    [(0,1), (1,2), (2,3)],
    colors={0: "red", 1: "red", 2: "blue", 3: "blue"},
)
print(r.num_orbits)          # 4 (colors broke the path's end-to-end symmetry)

# Automorphism generators, as {node: image_node} maps
r = canonaut.canonize([("a","b"),("b","c"),("c","d"),("d","a")], generators=True)
print(r.generators)

# Orbits, grouped by original node label
print(r.orbits)               # [['a','b','c','d']] for the 4-cycle

# Isomorphism test — works with different label sets on each side
canonaut.are_isomorphic(
    [("p","q"),("q","r"),("r","s"),("s","p")],
    [(1,2),(2,3),(3,4),(4,1)],
)  # True

# Hashable canonical key for deduplication — equal iff the graphs are isomorphic
key = r.canonical_bytes()

# networkx graphs work directly (duck-typed, no hard dependency)
import networkx as nx
r = canonaut.canonize(nx.petersen_graph())

Isolated vertices

nodes= includes vertices with no edges at all:

canonaut.canonize([("a","b")], nodes=["a", "b", "isolated"])

Directed graphs

canonaut.canonize(edges, directed=True)

Detected automatically for graph-like objects exposing .is_directed() (e.g. networkx.DiGraph).

Low-level API

canonaut.raw exposes the compiled extension directly: 0..n-1 integer vertex indices only, no node-label translation. Use it if you already have integer-labeled graphs and want to skip that overhead:

r = canonaut.raw.canonize(4, [(0,1),(1,2),(2,3)], colors=[0,0,1,1])

CanonResult

Attribute Type Meaning
labeling list Original nodes in canonical order — labeling[i] is the node placed at canonical position i
orbits list[list] Automorphism-group orbits, as groups of original nodes
canonical_edges list[tuple[int,int]] Edges of the canonical form, in canonical-position (0..n-1) space
group_size1, group_size2 float, int |Aut(G)| ~= group_size1 * 10**group_size2
num_orbits, num_generators int
generators list[dict] Automorphism generators as {node: image_node} maps (only when generators=True)
.canonical_bytes() bytes Hashable canonical key

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

canonaut-1.0.0.tar.gz (275.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

canonaut-1.0.0-cp39-abi3-win_amd64.whl (200.7 kB view details)

Uploaded CPython 3.9+Windows x86-64

canonaut-1.0.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (288.7 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

canonaut-1.0.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (274.0 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

canonaut-1.0.0-cp39-abi3-macosx_11_0_arm64.whl (263.9 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

canonaut-1.0.0-cp39-abi3-macosx_10_12_x86_64.whl (275.8 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file canonaut-1.0.0.tar.gz.

File metadata

  • Download URL: canonaut-1.0.0.tar.gz
  • Upload date:
  • Size: 275.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for canonaut-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7fb5a0469d4aac4d46bbd3fc62b992ea8c52d2b19f710580b2d8c8a70f273a94
MD5 791100deb548e423ced9ffbe88a26eb2
BLAKE2b-256 df86bd6101666d087ae97099a260e9cdfab9f665b6aec9c8ef61dc6c2fa74872

See more details on using hashes here.

Provenance

The following attestation bundles were made for canonaut-1.0.0.tar.gz:

Publisher: release-python.yml on um-univie/canonaut

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file canonaut-1.0.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: canonaut-1.0.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 200.7 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for canonaut-1.0.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9de63b336510e99727f8ca6ba5a305442c7f96f01fc0640c5e6042bb6ca8e30e
MD5 af82404a4b00ef7abcca14f8c9acc382
BLAKE2b-256 7efd7be6991770fc35cd1f88edebdaa86e1f5299ceb88ac14e6a3d3fc5f9b238

See more details on using hashes here.

Provenance

The following attestation bundles were made for canonaut-1.0.0-cp39-abi3-win_amd64.whl:

Publisher: release-python.yml on um-univie/canonaut

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file canonaut-1.0.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for canonaut-1.0.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bae514596a9d454ff00ea2b191d85a9f42b2c1e7127635d98a75f5a4062b5923
MD5 75fc1d6598dd2bc4e02ccaceb5e79b39
BLAKE2b-256 f3f597be168d7f5e72b690ed496931479bba93313626bcd6bdaf7a42a51e1857

See more details on using hashes here.

Provenance

The following attestation bundles were made for canonaut-1.0.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-python.yml on um-univie/canonaut

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file canonaut-1.0.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for canonaut-1.0.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a5ecfde6f2a9d65f11aa1e0049715468fed9079f7467c5a93746eae2c9a48c06
MD5 ae30c5c23abb9df8162a83dacf1da9c8
BLAKE2b-256 723008b1a59d7a213ac92da799c57017d3f6e04ee91df6bf9e4e900356d931aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for canonaut-1.0.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release-python.yml on um-univie/canonaut

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file canonaut-1.0.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for canonaut-1.0.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7bd85c664b4ebb81974e8586262cd147bd6cb7062930084aa4c305e0473dceea
MD5 b75ce80303e160b694fbb278d51e9382
BLAKE2b-256 286b84d082e3111c7653f2aa5c58be49368ce51294d2dc7235029701b25db560

See more details on using hashes here.

Provenance

The following attestation bundles were made for canonaut-1.0.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release-python.yml on um-univie/canonaut

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file canonaut-1.0.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for canonaut-1.0.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c9c93873a904979df28012deb468d14f2a0c37a3580b7b412da78be5fef28db9
MD5 40d5c7877362115cb90e31a0ccc03066
BLAKE2b-256 b762024654cba314bbdd49337d354e8138ccfc65509e03005d8758455d7fca50

See more details on using hashes here.

Provenance

The following attestation bundles were made for canonaut-1.0.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release-python.yml on um-univie/canonaut

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.0 This release

6 files

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