Metadata-Version: 2.4
Name: altium-monkey
Version: 2026.11.26
Summary: A toolkit for manipulating Altium files
Project-URL: Homepage, https://github.com/wavenumber-eng/altium_monkey
Project-URL: Documentation, https://wavenumber-eng.github.io/altium_monkey/
Project-URL: Repository, https://github.com/wavenumber-eng/altium_monkey
Project-URL: Issues, https://github.com/wavenumber-eng/altium_monkey/issues
Author-email: Eli Hughes <ehughes@wavenumber.net>
License-Expression: AGPL-3.0-or-later
License-File: LICENSE
License-File: NOTICE.md
License-File: licenses/freetype/FTL.TXT
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: <3.15,>=3.12
Requires-Dist: fonttools>=4.63.0
Requires-Dist: freetype-py
Requires-Dist: jsonschema-rs<0.49,>=0.48.1
Requires-Dist: lxml==6.0.2
Requires-Dist: lz4>=4.4.5
Requires-Dist: msgspec==0.21.1
Requires-Dist: numpy
Requires-Dist: pillow==12.3.0
Requires-Dist: rfc8785==0.1.4
Requires-Dist: shapely==2.1.2
Requires-Dist: skia-python==144.0.post2
Requires-Dist: uharfbuzz
Requires-Dist: wn-geometer==2026.11.22
Provides-Extra: examples
Requires-Dist: cadquery; extra == 'examples'
Requires-Dist: casadi<3.8; (sys_platform == 'win32' and python_version >= '3.14') and extra == 'examples'
Provides-Extra: release
Requires-Dist: build>=1.2; extra == 'release'
Requires-Dist: pytest>=8.0; extra == 'release'
Requires-Dist: twine>=5.0; extra == 'release'
Provides-Extra: test
Requires-Dist: jsonschema>=4.20; extra == 'test'
Requires-Dist: pytest>=8.0; extra == 'test'
Description-Content-Type: text/markdown

# altium-monkey

```text
          ▓▓▓▓▓▓▓▓▓▓
        ▓▓▓▓▓▓▓▓▓▓▓▓▓▓
      ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
    ▓▓▓▓░░░░░░▓▓░░░░░░▓▓▓▓
░░░░▓▓░░░░░░░░░░░░░░░░░░▓▓░░░░
░░░░▓▓░░    ░░░░░░    ░░▓▓░░░░
  ░░▓▓░░██  ░░░░░░██  ░░▓▓░░
    ▓▓░░░░░░░░░░░░░░░░░░▓▓
      ▓▓░░░░░░░░░░░░░░▓▓
        ▓▓▓▓░░░░░░▓▓▓▓
            ▓▓▓▓▓▓        ░░
          ▓▓▓▓▓▓▓▓▓▓      ▓▓
          ▓▓▓▓▓▓▓▓▓▓    ▓▓▓▓
        ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
        ▓▓▓▓░░▓▓░░▓▓▓▓
```

`altium-monkey` is a Python toolkit for reading, writing, analyzing, and
rendering Altium files directly from automation.

It is designed for engineers who want to build their own command-line tools,
CI/CD checks, visualization pipelines, library generators, BOM workflows, and
design-review helpers without driving the Altium GUI for every operation.

## What It Supports

Core file types:

1. `.SchDoc`
2. `.SchLib`
3. `.PcbDoc`
4. `.PcbLib`
5. `.PrjPcb`
6. `.OutJob`
7. `.IntLib` extraction
8. `.PCBDwf` Draftsman files, currently experimental

Common workflows:

1. create and mutate schematic documents
2. create schematic symbols and PCB footprints
3. insert SchLib symbols and PcbLib footprints
4. extract SchLib and PcbLib data from projects
5. render logical schematic SVGs, compiled physical schematic SVGs, and PCB SVGs
6. inspect PCB layers, drills, board outlines, nets, and net classes
7. author and mutate PCB vias, including IPC-4761 protection metadata
8. extract embedded fonts and 3D models
9. generate project containers and, on Windows with Altium Designer installed,
   run associated OutJobs within the limitations below
10. create experimental Draftsman pages with notes, text, pictures, and
    generated board-assembly-view highlight artwork

## Known OutJob Automation Limitation

`prj.outjob().run(...)` drives Altium Designer through its scripting API. It is
a best-effort Windows integration, not a headless release service.

- The verified scope is folder-based `GeneratedFiles` manufacturing output,
  such as Gerber, NC Drill, ODB++, IPC-2581, and some netlist outputs. Exact
  behavior remains dependent on the installed Altium version.
- PDF/Publish document containers, including schematic prints, PCB prints, and
  Draftsman output, are not currently supported reliably. The runner also does
  not iterate every output container in a mixed-media OutJob.
- The OutJob must be listed as a document in the `.PrjPcb`, not merely stored
  beside it. When running a disposable project copy, use its project-bound
  OutJob with `stage_outjob_copy=False`; copying only the OutJob to a temporary
  path can break the project-document identity required by Altium.
- `OutJobRunResult.success` means the Altium script returned its completion
  marker without a reported script error. Altium can still generate zero
  files, so automation must verify its expected artifacts before accepting a
  run.

For document/PDF output, use Altium's OutJob editor to generate each container
or use the Project Releaser, which can target a local folder or a connected
Workspace. Altium's own documentation states that direct OutJob generation is
per container; there is no single batch command for every output container.
See [Preparing Manufacturing Data with Output Jobs](https://www.altium.com/documentation/altium-designer/preparing-for-manufacture/output-jobs)
and [Design Project Release](https://www.altium.com/documentation/altium-designer/preparing-for-manufacture/design-release).

Tracked reports: [#33](https://github.com/wavenumber-eng/altium_monkey/issues/33),
[#34](https://github.com/wavenumber-eng/altium_monkey/issues/34), and
[#61](https://github.com/wavenumber-eng/altium_monkey/issues/61).
See the [Launcher & OutJobs guide](docs/launcher_outjob.md) for the full
automation boundary, operational caveats, and when to use `board.fab()` instead.

## Install

This repository publishes **two separate PyPI wheels** that version and evolve
together:

- **`altium-monkey`** — the core Python library
- **`altium-cruncher`** — the companion CLI (`acr`, `altium-cruncher`, `ad`)

Normal GIL-enabled CPython 3.12 through Python 3.14 are supported for both
packages. Free-threaded Python builds are not currently part of the support
contract.

Install the Python library:

```powershell
pip install altium-monkey
# or with uv
uv add altium-monkey
```

Install the companion CLI (`acr`):

```powershell
uv tool install altium-cruncher
uv tool update-shell
acr version
```

See [Installation & Packages](docs/install.md) for the full Python/OS matrix
and CLI setup details, and [CLI Quick Start](docs/cli/index.md) for `acr`
workflows (`acr fab`, `acr pcb-svg`, `acr toon`, `acr bom`, `acr pnp`, and
more).

Install the optional example dependencies before running the full example set:

```powershell
pip install "altium-monkey[examples]"
```

With `uv`, use `uv run --extra examples ...` so examples that synthesize STEP
geometry receive CadQuery without changing the core runtime environment.

The package includes dependencies for SVG text shaping and STEP-model bounds.
STEP bounds use the required `wn-geometer==2026.11.22` dependency, which
publishes wheels for Windows amd64, macOS arm64, and Linux x86_64/aarch64 using
`manylinux_2_35`; other platforms are not currently part of the install support
boundary. See [RELEASE_NOTES.md](RELEASE_NOTES.md) for platform and
Python-version boundaries. CadQuery is needed only by examples that synthesize
new STEP models.

## Public API Compatibility

We strive to maintain compatibility for documented public APIs between
releases. The API surface may still change as more Altium capabilities are
modeled, especially in areas that are currently marked as release boundaries or
advanced usage. Compatibility-affecting changes and migration notes will be
documented in release notes.

## Quick Start

Parse a project and emit the public design JSON contract:

```python
from altium_monkey import AltiumDesign

design = AltiumDesign.from_prjpcb("example.PrjPcb")
payload = design.to_json(include_pnp=False)  # Schematic-only; no board parse.
```

Project loading is proportional to the requested work. The default `FULL`
mode loads the schematic/compiler context but does not parse any referenced
PcbDoc. Use `METADATA_ONLY` when a tool needs project parameters, variants, or
document discovery without loading either schematics or boards:

```python
from altium_monkey import AltiumDesign, AltiumProjectLoadMode

design = AltiumDesign.from_prjpcb(
    "example.PrjPcb",
    load_mode=AltiumProjectLoadMode.METADATA_ONLY,
)
board = design.load_pcbdoc()  # The board is parsed only when requested.
```

Create or modify a schematic, then save it:

```python
from altium_monkey import AltiumSchDoc, SchFontSpec, SchRectMils, make_sch_note

schdoc = AltiumSchDoc("input.SchDoc")
note = make_sch_note(
    bounds_mils=SchRectMils.from_corners_mils(1000, 3000, 2600, 2400),
    text="Added by altium-monkey",
    font=SchFontSpec(name="Arial", size=10),
)
schdoc.add_object(note)
schdoc.save("output.SchDoc")
```

Create a simple PCB primitive:

```python
from altium_monkey import AltiumPcbDoc, PcbLayer

pcbdoc = AltiumPcbDoc()
pcbdoc.add_track(
    (1000, 1000),
    (2500, 1000),
    width_mils=8,
    layer=PcbLayer.TOP,
    net="GND",
)
pcbdoc.save("output.PcbDoc")
```

## Documentation

Documentation is authored in Markdown under `docs/` and can also be built into
a self-contained Monkey-themed static HTML site (`uv run python tools/build_docs.py`):

1. **Getting Started & Core Patterns** —
   [Overview](docs/index.md), [Installation & Packages](docs/install.md),
   [Core API Patterns](docs/api_patterns/index.md),
   [Asset & Library Extraction](docs/api_patterns/assets.md), and
   [Text & Font Rendering](docs/fonts.md).
2. **Domain Guides** — organized by domain:
   - **PCB Domain**: [PcbDoc](docs/pcbdoc.md),
     [PCB Layers & Stackups](docs/pcb_layer_stacks.md),
     [PcbLib](docs/pcblib.md),
     [Fab & FabView](docs/fab.md) (Gerber X2/X1, NC drill, IPC-2581B, PCB SVG,
     PnP, BOM; ODB++ planned on `FabView`), and
     [Virtual Fab Layers](docs/virtual_layers.md).
   - **Schematic Domain**: [SchDoc](docs/schdoc.md),
     [SchLib](docs/schlib.md), and
     [Schematic Rendering & Paint IR](docs/sch_paint_ir.md).
   - **Projects, Design & Multi-Board**: [PrjPcb](docs/prjpcb.md),
     [AltiumDesign & Compiled Design](docs/altium_design.md),
     [Multi-Board Systems](docs/multiboard.md), and [IntLib](docs/intlib.md).
   - **Draftsman & Desktop**: [Draftsman](docs/draftsman.md) and
     [Launcher & OutJobs](docs/launcher_outjob.md).
3. **CLI (`altium-cruncher` / `acr`)** —
   [CLI Quick Start & Config](docs/cli/index.md),
   [Fabrication & Outputs](docs/cli/fab.md),
   [Rendering & Design Review](docs/cli/rendering.md),
   [Monkey Change Orders (MCO)](docs/cli/mco.md), and
   [Full Command Reference](docs/cli/commands.md).
4. **Examples Showcase & Python API Reference** — runnable Python workflows in
   [`examples/`](examples/) ([Examples](docs/examples/index.md)) plus the
   auto-generated Python API Reference inside the HTML site build.
5. **Output & Wire Contracts** —
   [Format Contracts](docs/format_contracts/index.md) (Gerber, SVG, Schematic
   JSON Interop) and the unified
   [JSON Schemas & TypeSpec](docs/schemas/index.md) guide.
6. **Altium Output Differences (AOD) & Releases** — standalone
   [AOD Register](docs/altium_output_differences.md), per-version
   [Release Notes](docs/releases/index.md), and
   [Style Foundation](docs/style.md).

## Schematic SVG Fonts

Schematic SVG rendering uses installed fonts when it can resolve the requested
Altium font family. On macOS, the resolver searches the standard system font
locations, including Supplemental fonts. Callers can also set
`ALTIUM_FONT_DIRS` to one or more additional font directories.

When a common Altium/Windows family is unavailable, schematic rendering can use
bundled open-source fallback fonts. Arial and Microsoft Sans Serif-style
families substitute Arimo, Times New Roman-style families substitute Tinos, and
Courier New or monospace families substitute Cousine. Schematic SVG now uses
Paint IR A0 and `SchPaintSvgOptions`:

```python
from altium_monkey import SchPaintSvgOptions

svg = schdoc.to_svg(options=SchPaintSvgOptions())
outlined_svg = schdoc.to_svg(options=SchPaintSvgOptions(text_mode="paths"))
```

The default keeps text as SVG text. Use `text_mode="paths"` to outline text when
viewers may lack the selected font. The current Paint IR SVG adapter does not
embed fallback font files; `embed_bundled_fallback_fonts=True` is unsupported.
A compact SVG viewed on a machine without the selected fallback family may not
reproduce the renderer's text metrics exactly.

See [Schematic Rendering & Paint IR](docs/sch_paint_ir.md#migrating-from-legacy-gotir)
for the current API and removed GOTIR surface.

## PCB Fonts

PCB TrueType text in the Gerber, IPC-2581 and SVG outputs is drawn in the font
Altium draws, by Altium's own rule. On Linux and macOS the standard Windows
fonts are drawn with the same open stand-ins (Arimo, Tinos, Cousine) the
schematic uses. A font report lists each font a board uses and what to do
about it. See [Fonts](docs/fonts.md).

## Contributing

This repository is a published mirror. Issues, minimal reproduction cases,
documentation fixes, API feedback, and focused pull requests are welcome, but
PRs may be adapted or reimplemented in the upstream development workspace before
they are mirrored back here. See [CONTRIBUTING.md](CONTRIBUTING.md).

## API Shape

The schematic side uses a higher-level object system:

1. `AltiumSchDoc` and `AltiumSymbol` own `ObjectCollection` instances.
2. Typed views such as `schdoc.notes` and `symbol.pins` are live query views.
3. Structural mutations should go through `add_object(...)`,
   `insert_object(...)`, or `remove_object(...)`.

The PCB document side is helper-oriented rather than `ObjectCollection`-based:

1. `AltiumPcbDoc` and `AltiumPcbFootprint` expose high-level `add_*` methods.
2. `AltiumPcbDoc` covers common authoring workflows including board setup,
   nets, primitives, components, footprint insertion, component bodies, and
   embedded 3D model placement. Via support includes IPC-4761 type metadata,
   feature rows, propagation delay, tenting, and testpoint flags.
3. Parsed primitives are available through typed record lists such as
   `pcbdoc.tracks`, `pcbdoc.pads`, `pcbdoc.vias`, and `pcbdoc.components`.
4. Direct record-list mutation is possible but should be treated as advanced
   usage until PcbDoc grows a generic object API.

See [API patterns](docs/api_patterns/index.md) for units, object ownership,
public vs careful APIs, and internal Altium unit guidance.

## Testing And Interoperability

`altium-monkey` is validated against real-world Altium files spanning multiple
Altium eras from "Summer '08" to present day, covering round-trip parsing,
binary serialization, SVG rendering, and comparisons against Altium Designer
captures.

No tool can prove perfect compatibility with every historical Altium file. If
you find a parsing, serialization, SVG, or interoperability issue, please file
an issue with the smallest representative `.SchDoc`, `.SchLib`, `.PcbDoc`, or
`.PcbLib` that reproduces the problem.

## Release Boundaries

Known release boundaries include:

1. PcbDoc does not yet use `ObjectCollection`; it remains a typed-list plus
   helper-oriented API.
2. PcbDoc does not yet have a public generic object deletion API.
3. IntLib support is extract-only, with fallback source-stream extraction when
   component cross-reference metadata cannot be parsed.
4. Variant processing supports DNP handling and parameter overrides; alternate
   fitted component replacement is not applied semantically yet.
5. Complex hierarchical channels route through the compiled design model for
   design JSON, netlist JSON, and physical schematic SVG/IR output. Rich
   consumers should use the required Design b0 `compiled_schematic_graph` and
   select pages by canonical page occurrence id instead of assuming one source
   SVG ID maps to one physical component.
6. Project design JSON emits `altium_monkey.design.b0` (with required
   `altium_monkey.compiled_schematic_graph.a0` and opt-in compile metadata via
   `to_json(include_compile_metadata=True)`). For strict recursive electrical
   membership, Net Tie bridges, authored field-impact tracing, and Paint IR
   occurrence bindings, use the checked C0 compilation surface
   (`AltiumCompilation` / `AltiumCompiledView`, emitting
   `altium_monkey.compilation.c0`, `compiled_view.c0`, `structural_graph.c0`,
   `compiled_schematic_graph.b0`, and `paint_bindings.c0`).
7. Windows remains the primary validation platform. macOS font discovery and
   bundled schematic font substitution have focused coverage; Linux coverage
   remains limited and may rely more heavily on bundled substitutions.

See [RELEASE_NOTES.md](RELEASE_NOTES.md) for the full current support boundary.

## License

`altium-monkey` is licensed under the GNU Affero General Public License v3.0 or
later. See [LICENSE](LICENSE).
