Cyclic

1.0.0 · maintenance · verified Thu Apr 16

The `cyclic` Python library, currently at version 1.0.0, is designed to handle and detect cyclic relations between objects. It allows you to add parent-child relationships and then query if a specific object is part of a cyclic dependency. The library has a low release cadence, with its last update in 2018.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Cyclic` checker, add parent-child relationships, and then use `is_cyclic()` to determine if an object is part of a cyclic dependency. It shows a clear example of how to introduce and detect a cycle.

from cyclic import Cyclic

# Initialize the Cyclic checker
cy = Cyclic()

# Let's define some objects (can be anything hashable)
A = 'Object A'
B = 'Object B'
C = 'Object C'
D = 'Object D'

# Add relationships: A is parent of B, B is parent of C
cy.add(B, A)
cy.add(C, B)

# Check for cycles (C -> B -> A, no cycle yet)
print(f"Is C in a cyclic relation? {cy.is_cyclic(C)}")

# Introduce a cycle: C is parent of A (now A -> B -> C -> A)
cy.add(A, C)

# Check for cycles again
print(f"Is C now in a cyclic relation? {cy.is_cyclic(C)}")
print(f"Is A now in a cyclic relation? {cy.is_cyclic(A)}")

# Adding a non-cyclic relationship to D
cy.add(D, C)
print(f"Is D in a cyclic relation? {cy.is_cyclic(D)}")

view raw JSON →