Basic information
About library
How the Faebryk component library is structured, how `_F.py` is generated, and the conventions/invariants for adding new library modules.
library is an agent skill listed in the AddMCP.net directory, published by atopile. Runtime: Python. License: MIT. The repository has 4,034 GitHub stars. Source code is hosted on github.com. Related topics: agent, ai, cad, eda, electronics.
Overview
What is library?
name: library description: "How the Faebryk component library is structured, how _F.py is generated, and the conventions/invariants for adding new library modules. Use when adding or modifying library components, traits, or module definitions."
Library Module
The library module (located in src/faebryk/library/) contains the collection of reusable components, traits, and interfaces that form the "standard library" of the hardware design language.
How to use library?
Core Concepts
- Traits vs Components: Use Traits for behavior (what it can do like
can_bridge) and Components for physical things (what it is likeResistor). - Export model:
_F.pyis a generated “barrel” module; importing it is intentionally convenient but can be heavyweight.
Development Workflow
- New Component: Create a new file
MyComponent.pyinsrc/faebryk/library/. Inherit fromNode(or a more specific base). - Naming Convention: Class names should match the file basename (usually).
- Regenerate
_F.py: runpython tools/library/gen_F.pyand commit the updatedsrc/faebryk/library/_F.py.
Testing
- Library tests live under
test/library/(includingtest/library/nodes/). - A good smoke test for new modules is:
ato dev test --llm test/library/test_instance_library_modules.py -q
Quick Start
import faebryk.core.faebrykpy as fbrk
import faebryk.core.graph as graph
import faebryk.library._F as F
g = graph.GraphView.create()
tg = fbrk.TypeGraph.create(g=g)
resistor = F.Resistor.bind_typegraph(tg=tg).create_instance(g=g)Relevant Files
- Facade (auto-generated):
src/faebryk/library/_F.py - Eagerly imports and re-exports library modules/types for the
import faebryk.library._F as Fpattern. - This file is generated; do not hand-edit it.
- Generator:
tools/library/gen_F.py - Scans
src/faebryk/library/*.py, detects whether the file contains a same-named class, and writes_F.py. - Orders exports via a topological sort of
F.<Name>references to avoid import-order cycles. - Components:
src/faebryk/library/contains specific component definitions (e.g.Resistor.py,Capacitor.py,LED.py). - Traits/Interfaces: Also contains trait definitions (e.g.
can_bridge.py,is_power.py).
Dependants (Call Sites)
- User Code: atopile projects heavily import from
faebryk.library._F(aliased asF). - Compiler: The compiler maps
atobuilt-ins to these classes.
Best Practices
- Atomic Parts: Mark leaf components (specifically verified part numbers) with the
is_atomic_parttrait. - Parameters: Use
F.Parametersto define physical properties likeresistance,capacitance, etc. - Documentation: Add docstrings to components explaining their ports and parameters.
Comments
No comments yet
Be the first to share feedback about this listing. Sign in to leave a comment.
Sign In