Skip to main content

python-kicad

python-kicad provides Pydantic models and parsers for KiCad schematic, PCB, and exported netlist files.

  • KiCad 6 and newer
  • Python 3.10 and newer
  • No KiCad installation required
  • MIT licensed

Installation

python -m pip install python-kicad

The distribution is named python-kicad, while the import package remains pykicad:

from pykicad import Pcb, Schematic, read_from_file

document = read_from_file("project.kicad_pcb")
if isinstance(document.model, Pcb):
    print(document.model.version)
    print(len(document.model.footprint))
elif isinstance(document.model, Schematic):
    print(document.model.version)
    print(len(document.model.symbols))

An older, unrelated distribution already uses the pykicad name on PyPI and installs into the same Python import namespace. Do not install pykicad and python-kicad into the same environment.

JSON command line interface

Inspect any supported KiCad document without loading its S-expression syntax into another tool:

pykicad inspect project.kicad_pcb
pykicad json project.kicad_pcb
pykicad json reusable-footprint.kicad_mod

python -m pykicad provides the same commands. Both commands accept - for UTF-8 standard input and --compact for single-line output:

cat project.kicad_sch | pykicad inspect - --compact

Full exports use a versioned envelope:

{
  "schema": "pykicad.document",
  "schema_version": 1,
  "document_type": "pcb",
  "document": {}
}

The semantic document uses plural collection names, omits absent optional fields, and preserves unknown KiCad tags in an extensions object. PCB footprints include resolved reference and value fields, pads include both local position and board-level absolute_position, and PCB net references use consistent code/name objects. Placed schematic symbols similarly expose their resolved reference, value, and footprint.

The same data is available from Python:

from pykicad import export_json_data, inspect_document, read_from_file

document = read_from_file("project.kicad_pcb")
payload = export_json_data(document)
summary = inspect_document(document)

Bundled agent skill

The installed distribution includes a pykicad-cli agent skill with the CLI workflow, query patterns, schema documentation, and a machine-readable JSON Schema. Copy it into a repository's project skills with:

pykicad skill copy .agents/skills

The destination parent defaults to .agents/skills, so pykicad skill copy creates .agents/skills/pykicad-cli. The command refuses to overwrite an existing skill directory.

The complete export is designed to compose with standard JSON tools instead of providing a separate query language. For example:

# Footprint references, values, and positions
pykicad json board.kicad_pcb | jq '.document.footprints[] | {reference, value, position}'

# Pads belonging to U1
pykicad json board.kicad_pcb | jq '.document.footprints[] | select(.reference == "U1") | .pads[]'

# Unique connected net names
pykicad json board.kicad_pcb | jq '[.document.footprints[].pads[].net.name] | map(select(. != null)) | unique'

# Placed schematic symbols
pykicad json design.kicad_sch | jq '.document.symbols[] | {reference, value, footprint, position}'

# Tracks and copper zones
pykicad json board.kicad_pcb | jq '{tracks: .document.tracks, zones: .document.zones}'

Schema version 1 guarantees the envelope and modeled semantic field names. Additional modeled fields may be added compatibly; removing a field or changing its meaning requires a new schema version. Contents of extensions are best-effort and are not part of that compatibility guarantee. JSON export is read-only and does not retain source whitespace, comments, quoting choices, or exact numeric spelling.

Supported documents

read_from_file() and read_from_string() return a KicadDocument containing the parsed model and its original source. They recognize:

  • .kicad_pcb board files as Pcb
  • .kicad_mod footprint files as Footprint
  • .kicad_sch schematic files as Schematic
  • KiCad-exported S-expression netlists as Netlist

The parser uses one Pydantic model family for released KiCad 6 and newer file variants. Unknown enum values and malformed S-expressions remain validation errors.

from pydantic import ValidationError
from pykicad import read_from_string

try:
    document = read_from_string(
        "(kicad_pcb (version 20240101) (generator pcbnew))"
    )
    board = document.model
except (ValueError, ValidationError) as error:
    print(f"Invalid KiCad document: {error}")

Writing

Exact PCB round-tripping is available for an unchanged KicadDocument loaded through read_from_file() or read_from_string(). New and modified PCB models are written using canonical KiCad S-expression formatting:

from pykicad import read_from_file, write_to_file

document = read_from_file("project.kicad_pcb")
write_to_file(document, "copy.kicad_pcb")

Use PcbBuilder.create() to construct an empty KiCad 10 board. Standalone .kicad_mod footprints can also be read and written. Models remain declarative data structures; document I/O, serialization, and authoring live in dedicated modules. Schematic writing is not implemented.

Common authoring operations are available through builders:

from pykicad import BoardSide, FootprintBuilder, PcbBuilder, write_to_file
from pykicad.models.base import Point
from pykicad.models.pcb import Position

board = PcbBuilder.create(copper_layer_count=4)
ground = board.ensure_net("GND")
board.add_via(Position(x=10, y=10), size=0.6, drill=0.3, net=ground)
board.add_graphic_rect(
    Point(x=0, y=0), Point(x=20, y=20), layer="Edge.Cuts"
)

footprint = FootprintBuilder.create("Example:Part")
footprint.set_reference("U1", at=Position(x=0, y=-2), layer="F.SilkS")
footprint.place(Position(x=5, y=5), side=BoardSide.BACK)
board.add_footprint(footprint.build())

write_to_file(board.build(), "authored.kicad_pcb")

Place a .kicad_mod file directly onto a board with a reference and pad-net mapping. Each placement receives fresh identifiers, so the same file can be reused safely:

from pykicad import BoardSide, PcbBuilder, write_to_file
from pykicad.models.pcb import Position

board = PcbBuilder.create()
board.add_footprint_file(
    "Package_SO.pretty/SOIC-8.kicad_mod",
    reference="U1",
    at=Position(x=25, y=40, angle=90),
    side=BoardSide.BACK,
    pad_nets={"1": "GND", "8": "VCC"},
)
write_to_file(board.build(), "placed.kicad_pcb")

Development

Create an environment and install the development dependencies:

python -m pip install -e ".[dev]"
python -m pytest

Build and validate release artifacts with:

python -m build
python -m twine check dist/*
python scripts/check_distribution.py dist/*

See RELEASING.md for the trusted-publishing release process.

Download files

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

Source Distribution

python_kicad-0.6.0.tar.gz (162.4 kB view details)

Uploaded Source

Built Distribution

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

python_kicad-0.6.0-py3-none-any.whl (45.3 kB view details)

Uploaded Python 3

File details

Details for the file python_kicad-0.6.0.tar.gz.

File metadata

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

File hashes

Hashes for python_kicad-0.6.0.tar.gz
Algorithm Hash digest
SHA256 580c497a6e2cc6f786cef8312e3c7e12b93b44bd8a20f8bf368c77bb123cfcb7
MD5 2708e154eeebe75319e0bae3f6b77ecc
BLAKE2b-256 fad2674b76e9c1f297c16e446d419eacd47d4bf537d17879aeac121ce1605704

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_kicad-0.6.0.tar.gz:

Publisher: publish.yml on esophagoose/python-kicad

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

File details

Details for the file python_kicad-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: python_kicad-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 45.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for python_kicad-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6bd97e3e462caeb9b02635eddd7cba3b96dbd57137da6e5a2e68f0a729885cdb
MD5 9012c6ceba92f92f8a397fbd49a56715
BLAKE2b-256 1f3dc9d75ed763931cf00d1a3c02b4e59cf16a672dbf036adc37090be826cb74

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_kicad-0.6.0-py3-none-any.whl:

Publisher: publish.yml on esophagoose/python-kicad

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

Release history Release notifications | RSS feed

0.6.1

2 files

This release

0.6.0 This release

2 files

0.5.0

2 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