Skip to main content

A comprehensive Python library for parsing and manipulating KiCad file formats

Project description

KiCadFiles

A comprehensive Python library for parsing and manipulating KiCad file formats.

Python 3.9+ CI/CD License: MIT PyPI version Documentation codecov

📚 View Full Documentation - Complete API reference and examples

Features

  • Complete KiCad S-expression support: >200 classes representing KiCad tokens (missing tokens? create an issue with examples)
  • Type-safe parsing: Full Python type hints for all classes and methods
  • Flexible error handling: Three strictness modes (STRICT, FAILSAFE, SILENT)
  • Round-trip parsing: Parse KiCad files and convert back to S-expressions
  • Minimal dependencies: Self-contained S-expression parsing (no external dependencies)
  • Extensive testing: Comprehensive test suite ensuring reliability

Installation

pip install kicadfiles

Quick Start

Main File Format Classes

from kicadfiles import (
    KicadPcb, KicadSch, Footprint, KicadWks, KicadSymbolLib,
    KicadProject, KiCadDesignRules, FpLibTable, SymLibTable,
    KiCadTemplates
)

# PCB board (.kicad_pcb)
pcb = KicadPcb.from_file("board.kicad_pcb")
# pcb.save_to_file("output.kicad_pcb")

# Schematic (.kicad_sch)
schematic = KicadSch.from_file("schematic.kicad_sch")
# schematic.save_to_file("output.kicad_sch")

# Footprint (.kicad_mod)
footprint = Footprint.from_file("component.kicad_mod")
# footprint.save_to_file("output.kicad_mod")

# Symbol library (.kicad_sym)
symbol_lib = KicadSymbolLib.from_file("library.kicad_sym")
# symbol_lib.save_to_file("output.kicad_sym")

# Worksheet (.kicad_wks)
worksheet = KicadWks.from_file("template.kicad_wks")
# worksheet.save_to_file("output.kicad_wks")

# Project settings (.kicad_pro)
project = KicadProject.from_file("project.kicad_pro")
# project.save_to_file("output.kicad_pro")

# Design rules (.kicad_dru)
design_rules = KiCAdDesignRules.from_file("rules.kicad_dru")
# design_rules.save_to_file("output.kicad_dru")

# Footprint library table
fp_lib_table = FpLibTable.from_file("fp-lib-table")
# fp_lib_table.save_to_file("output-fp-lib-table")

# Symbol library table
sym_lib_table = SymLibTable.from_file("sym-lib-table")
# sym_lib_table.save_to_file("output-sym-lib-table")

Working with PCB Files

from kicadfiles import KicadPcb, KiCadTemplates

# Load and modify existing PCB
pcb = KicadPcb.from_file("board.kicad_pcb")

# Access elements
for footprint in pcb.footprints:
    print(f"Footprint: {footprint.library_link} at ({footprint.at.x}, {footprint.at.y})")

# Create new PCB from template
new_pcb = KiCAdTemplates.pcb()
new_pcb.setup.pad_to_mask_clearance(0.05)
new_pcb.save_to_file("new_board.kicad_pcb")

API Overview

Core Classes

  • KiCadObject: Base class for all KiCad objects
  • ParseStrictness: Enum controlling error handling (STRICT, FAILSAFE, SILENT)

Main File Format Classes

These classes represent complete KiCad file formats and support both from_file() and save_to_file() methods:

  • KicadSymbolLib: Symbol library files (.kicad_sym)
  • KicadPcb: PCB board files (.kicad_pcb)
  • KicadSch: Schematic files (.kicad_sch)
  • KicadWks: Worksheet files (.kicad_wks)
  • Footprint: Individual footprint files (.kicad_mod)
  • KicadProject: Project settings files (.kicad_pro)

Main Object Categories

  • Base Types: At, Size, Layer, Stroke, etc.
  • Text and Documents: TitleBlock, Page, Comment, etc.
  • Pad and Drill: Pad, Drill, Via, etc.
  • Graphics: Line, Circle, Arc, Polygon, etc.
  • Symbol Library: Symbol, Pin, Property, etc.
  • Footprint Library: Footprint, Model, Tags, etc.
  • Zone System: Zone, Hatch, FilledPolygon, etc.
  • Board Layout: General, Layers, Nets, etc.
  • Schematic System: Wire, Junction, Label, etc.

Error Handling with Strictness Modes

from kicadfiles import At, ParseStrictness

# STRICT mode: Raises exceptions for any parsing errors
try:
    at_obj = At.from_sexpr("(at 10.0 20.0)", ParseStrictness.STRICT)
except ValueError as e:
    print(f"Parsing failed: {e}")

# FAILSAFE mode: Logs warnings and uses defaults for missing fields
at_obj = At.from_sexpr("(at 10.0 20.0)", ParseStrictness.FAILSAFE)
print(f"Angle defaulted to: {at_obj.angle}")  # Output: 0.0

# SILENT mode: Silently uses defaults for missing fields
at_obj = At.from_sexpr("(at 10.0 20.0)", ParseStrictness.SILENT)
Mode Behavior
STRICT Raises ValueError on errors
FAILSAFE Logs warnings, uses defaults
SILENT Uses defaults silently

For a complete overview of all classes and their module organization, see kicadfiles/CLASSES.md.

Development

Setting up Development Environment

git clone https://github.com/Steffen-W/KiCadFiles.git
cd KiCadFiles
pip install -e ".[dev]"

Running Tests

pytest tests/ -v

Code Quality

# Format code
black .
isort .

# Linting
flake8 kicadfiles/

# Type checking
mypy kicadfiles/
pyright kicadfiles/

Documentation with sphinx

cd docs && make clean && make html && cd ..
# Open docs/build/html/index.html in browser

Coverage

pytest --cov=kicadfiles --cov-report=html tests/
# Open htmlcov/index.html in browser

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any problems or have questions, please open an issue on the GitHub repository.

Project details


Download files

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

Source Distribution

kicadfiles-1.0.4.tar.gz (103.5 kB view details)

Uploaded Source

Built Distribution

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

kicadfiles-1.0.4-py3-none-any.whl (83.8 kB view details)

Uploaded Python 3

File details

Details for the file kicadfiles-1.0.4.tar.gz.

File metadata

  • Download URL: kicadfiles-1.0.4.tar.gz
  • Upload date:
  • Size: 103.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kicadfiles-1.0.4.tar.gz
Algorithm Hash digest
SHA256 68bac9eff391177f98fbe3e40824dbf6364a1012bdcbe320fc01f3ae4a3c7055
MD5 2fe9e64acd116923319e13dad85b9f3d
BLAKE2b-256 16914b43c5adf2bb4357b9522e8e7438c9c59c958270d10f424c016020b787b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for kicadfiles-1.0.4.tar.gz:

Publisher: publish.yml on Steffen-W/KiCadFiles

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

File details

Details for the file kicadfiles-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: kicadfiles-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 83.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kicadfiles-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 bbcac175ed7c8afaf8fda8003efef5d80a3d89d1df58ea7c57ce8303bb69b96f
MD5 e36c439a9522cb59191ab2b5a3ac2af8
BLAKE2b-256 92ea74710fb8d700af146b95689ec300a916407a0e15a95e1978f54cbd2b24a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for kicadfiles-1.0.4-py3-none-any.whl:

Publisher: publish.yml on Steffen-W/KiCadFiles

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page