Skip to main content

1 Welcome to KiClearance

This Python program converts a given table of voltage distances into KiCad design rules.

docs/source/figures/overview.png

1.1 Installation

Install KiClearance directly from pyPI:

pip install kiclearance

1.2 Usage

1.2.1 Define net classes in your KiCad project

Add the net classes to each connection in the circuit diagram.

docs/source/figures/net_class_directive_labels.png

Add the same net classes in the net classes of the PCB editor: KiCad PCB Editor: File -> Board Setup -> Design Rules -> Net classes

docs/source/figures/board_setup.png

1.2.2 Run KiClearance to initially generate the clearance table

Navigate to the project folder with the KiCad project. Open a terminal and execute :

python -m kiclearance

Now a file clearance.ods is generated, which contains the human-readable clearance table. As of now, the table has been generated using fantasy values.

1.2.3 Adapt the table ‘clearance.ods/xls/csv’ containing clearance distances

Update the table (clearance.ods/xls/csv) in your KiCad project directory with voltage clearances defined by your requirements (e.g. standards).

The table contains the distances from a potential to another in mm. The same net distance is optional.

docs/source/figures/table.png

1.2.4 Run KiClearance again, to generate the final set of rules for KiCad

Navigate to the project folder with the KiCad project and the clearance.ods/.xls/.csv file. Open a terminal and execute :

python -m kiclearance

Now a file yourprojectname.kicad_dru is generated, which contains the rule sets.

Open your KiCad project, the rule sets are now stored and you can start the routing.

As the inner layers are exposed to less dirt and no air, the distance in the inner layers can be set as optional with a scaling factor (defaults to 1). If this factor is to be set differently, this can be set with the following command (in the example: inner distance to 75% of outer distance):

python -m kiclearance -i 0.75

To see help and options, run

python -m kiclearance --help
The following arguments are possible:
-h, --help: Prints this information,
-f, --project_folder (Optional): Path to the folder in which the project is located. Default: Folder in which this python script is located.
-n, --project_name (Optional): Name of the kicad project (file prefix). Default: Script will look for a file with .kicad_pro in the set folder.
-t, --table_file (Optional): Name (and ending) of the file containing the distance values. Default name: 'clearance'.
-i, --factor_inner_layers (Optional): Reduced factor for the inner layers. Default: 1.0
-d, --min_track_distance (Optional): minimum track distance between two tracks on the same potential. Default: 0.15 mm.

1.3 Tips and tricks

Requires KiCad 9 or higher.

If two network classes are assigned to a connection by mistake, KiClearance raises an error.

KiCad works through the rules from bottom to top: Once an applicable rule has been found, KiCad will not search for further rules. Keep this in mind when adding more own rules except from this script here.

Connections in the circuit diagram without a NetClass are automatically assigned to the default NetClass. To avoid careless errors due to missing NetClasses, the default NetClass should not be used and the distance from default to other NetClasses should also be set to an unrealistically high value (e.g. 100mm). This means that missing NetClasses are immediately noticeable in the layout and can then be assigned.

1.4 Example

A complete example can be found here.

1.5 Documentation

Find the documentation here.

1.6 Troubleshooting

  • This program has so far been tested only on Linux and Windows.

  • For performance reasons when routing, the number of NetClasses should be less than 10 (or not exceed this to any significant degree)

  • Using another factor for the inner layers than 1 increases the rules and routing might be slower

Metadata

Release files for kiclearance 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kiclearance 0.2.1
File Size Uploaded Provenance
kiclearance-0.2.1.tar.gz 49.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kiclearance 0.2.1
File Interpreter ABI Platform
kiclearance-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 56.6 kB

Release files / kiclearance-0.2.1.tar.gz

Download URL kiclearance-0.2.1.tar.gz
Size 49.0 kB
Tags Source
SHA-256 checksum
How to use checksums
af306187d947280b7637a0e5c1ec63e557679a85d8fb1beaf4ec80c3ee51db3b
BLAKE2b-256 checksum
How to use checksums
c5b22b87c6c6766fd7661bb2cfc454cbd57452b4f355529313ea00ca4ed4c186
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

Release files / kiclearance-0.2.1-py3-none-any.whl

Download URL kiclearance-0.2.1-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
107692d617f64806807ba16176acf2d4ec3241a1a520fa9c77141f2ade295bb8
BLAKE2b-256 checksum
How to use checksums
e2328875ae0bed09f3ccd17599f20b03e1576742adda9a522574c721827c6e77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

Security for kiclearance 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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