{"id":8054,"library":"cyclic","title":"Cyclic","description":"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.","status":"maintenance","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/neurobin/cyclic","tags":["cyclic relations","dependency detection","graph","utility"],"install":[{"cmd":"pip install cyclic","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"Cyclic","correct":"from cyclic import Cyclic"}],"quickstart":{"code":"from cyclic import Cyclic\n\n# Initialize the Cyclic checker\ncy = Cyclic()\n\n# Let's define some objects (can be anything hashable)\nA = 'Object A'\nB = 'Object B'\nC = 'Object C'\nD = 'Object D'\n\n# Add relationships: A is parent of B, B is parent of C\ncy.add(B, A)\ncy.add(C, B)\n\n# Check for cycles (C -> B -> A, no cycle yet)\nprint(f\"Is C in a cyclic relation? {cy.is_cyclic(C)}\")\n\n# Introduce a cycle: C is parent of A (now A -> B -> C -> A)\ncy.add(A, C)\n\n# Check for cycles again\nprint(f\"Is C now in a cyclic relation? {cy.is_cyclic(C)}\")\nprint(f\"Is A now in a cyclic relation? {cy.is_cyclic(A)}\")\n\n# Adding a non-cyclic relationship to D\ncy.add(D, C)\nprint(f\"Is D in a cyclic relation? {cy.is_cyclic(D)}\")","lang":"python","description":"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."},"warnings":[{"fix":"For Python circular import issues, refactor your module structure to break the dependency cycle (e.g., move shared code to a common module, use lazy imports, or reorganize responsibilities).","message":"The `cyclic` library is designed to *detect* circular dependencies based on added relationships, not to prevent Python's own circular import errors during module loading. If you encounter `ImportError` due to modules importing each other, this library will not resolve that underlying architectural issue.","severity":"gotcha","affected_versions":"1.0.0"},{"fix":"Assess the stability and compatibility in your specific Python environment. For new projects requiring robust dependency management, evaluate more actively maintained alternatives or be prepared to fork and maintain the library yourself.","message":"The `cyclic` library has not been updated since 2018. While it appears stable for its specific use case, its long-term maintenance and compatibility with very recent Python versions (beyond 3.6/3.7 for which it was likely current) are uncertain. Consider this when integrating into new projects.","severity":"deprecated","affected_versions":"All versions (1.0.0)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install cyclic` to install the package.","cause":"The `cyclic` package has not been installed in your Python environment.","error":"from cyclic import Cyclic; ModuleNotFoundError: No module named 'cyclic'"},{"fix":"Use the correct method `cy.add(child_object, parent_object)` to establish a dependency.","cause":"Incorrect method name used. The primary method for adding relationships is `add(child, parent)`.","error":"AttributeError: 'Cyclic' object has no attribute 'add_relation' (or similar method name)"},{"fix":"Ensure that the objects you are tracking with `cyclic.Cyclic` are immutable and thus hashable (e.g., strings, numbers, tuples, or custom objects with a `__hash__` method). If you need to track mutable objects, use a unique immutable identifier for each object instead.","cause":"The `cyclic` library internally uses sets for tracking relationships, requiring that the objects involved in dependencies (both child and parent) are hashable. Mutable types like lists or dictionaries are not hashable by default.","error":"TypeError: unhashable type: 'list' (or other mutable type) when using `add()` or `is_cyclic()`"}]}