Skip to main content

Fast part creation in KiCad and InvenTree

Project description

Ki-nTree

Fast part creation in KiCad and InvenTree

License: GPL v3.0 Python Versions PyPI Tests | Linting | Publishing Coverage Status

Demo Videos :fast_forward: Full Demo :fast_forward: KiCad Demo

Introduction

Ki-nTree (pronounced "Key Entry" or "Key 'n' Tree") aims to:

  • automate part creation of KiCad library parts
  • automate part creation of InvenTree parts
  • synchronize parts data between KiCad and InvenTree

Ki-nTree works with:

Important Note

Because of limited maintenance bandwidth, Ki-nTree versions 0.5.x and newer will only support KiCad version 6. To keep using Ki-nTree with KiCad version 5, use older 0.4.x versions (pip install kintree==0.4.8).

Ki-nTree was developped by @eeintech for SPARK Microsystems, who generously accepted to make it open-source!

Get Started

Requirements

  • Ki-nTree is currently tested for Python 3.8 to 3.10 versions.
  • Ki-nTree requires a Digi-Key production API instance. To create one, go to https://developer.digikey.com/. Create an account, an organization and add a production API to your organization. Save both Client ID and Secret keys.

Here is a video to help with the different steps

Installation (system wide)

  1. Install using Pip
pip install -U kintree
  1. Run Ki-nTree
kintree

Run in virtual environment (contained)

Linux / MacOS

Create a virtual environment and activate it with:

$ python3 -m venv env-kintree
$ source env-kintree/bin/activate

Then follow the steps from the installation section.

Windows

In Git Bash, use the following commands to create and activate a virtual environment:

$ python3 -m venv env-kintree
$ source env-kintree/Scripts/activate

For any other Windows terminal, refer to the official documentation

Packages

Arch Linux

Ki-nTree is available on Arch Linux's AUR as python-kintree.

Usage Instructions

:warning: Warning: KiCad library writer is still in development: Make sure to open KiCad libraries inside the symbol editor and save them after adding symbols.

Before Starting

If you intend to use Ki-nTree with InvenTree, this tool offers to setup the InvenTree category tree with a simple script that you can run as follow:

:warning: Warning: Before running it, make sure you have setup your category tree in your category settings file (~/.config/kintree/user/categories.yaml) according to your own preferences, else it will use the default setup.

python3 -m kintree.setup_inventree

If the InvenTree category tree is not setup before starting to use Ki-nTree, you will not be able to add parts to InvenTree.

InvenTree Permissions

Each InvenTree user has a set of permissions associated to them. Please refer to the InvenTree documentation to understand how to setup user permissions.

The minimum set of user/group permission required to add parts to InvenTree is:

  • "Part - Add" to add InvenTree parts
  • "Purchase Orders - Add" to add manufacturers, suppliers and their associated parts

If you wish to automatically add subcategories while creating InvenTree parts, you will need to enable the "Part Categories - Add" permission.

Note that each time you enable the "Add" permission to an object, InvenTree automatically enables the "Change" permission to that object too.

Settings

  1. With Ki-nTree GUI open, click on "Settings > Digi-Key" and fill in both Digi-Key API Client ID and Secret keys (optional: click on "Test" to get an API token)
  2. Click on "Settings > Mouser" and fill in the Mouser part search API key
  3. Click on "Settings > KiCad", browse to the location where KiCad symbol, template and footprint libraries are stored on your computer then click "Save"
  4. If you intend to use InvenTree with this tool, click on "Settings > InvenTree" and fill in your InvenTree server address and credentials then click "Save" (optional: click on "Test" to get an API token)

Get Digi-Key API token

Show steps (click to expand)

Enter your Digi-Key developper account credentials then login. The following page will appear (user@email.com will show your email address):

Click on "Allow", another page will open.
Click on the "Advanced" button, then click on "Proceed to localhost (unsafe)" at the bottom of the page:

On Chrome, if the "Proceed to localhost (unsafe)" link does not appear, enable the following flag: chrome://flags/#allow-insecure-localhost

Lastly, a new page will open with a "You may now close this window." message, proceed to get the token.

Part Parameters

Ki-nTree uses supplier parameters to populate InvenTree parameters. In order to match between supplier and InvenTree, users need to setup the config file ~/.config/kintree/user/supplier_parameters.yaml with the following mapping for each category:

CATEGORY_NAME:
  INVENTREE_PARAMETER_NAME:
    - SUPPLIER_1_PARAMETER_NAME_1
    - SUPPLIER_1_PARAMETER_NAME_2
    - SUPPLIER_2_PARAMETER_NAME_1

Refer to this file as a starting point / example.

Part Number Search

Ki-nTree currently supports APIs for the following electronics suppliers: Digi-Key, Mouser and LCSC.

  1. In the main window, enter the part number and select the supplier in drop-down list, then click "CREATE". It will start by fetching part data using the supplier's API
  2. In the case Digi-Key has been selected and the API token is not found or expired, a browser window will pop-up. To get a new token: follow those steps
  3. Once the part data has been successfully fetched from the supplier's API, you will be prompted to add/confirm/edit the part information, followed by the Category and Subcategory to use for this part (Ki-nTree tries to match them automatically)
  4. Then, you will be prompted with selecting the KiCad symbol library, the template and the footprint library to use for this part
  5. It will take some time to complete the part creation in InvenTree and/or KiCad, once it finishes you'll be notified of the result
  6. Finally, if the part was created or found in InvenTree, your browser will automatically open a new tab with the part information

Enjoy!

For any problem/bug you find, please report an issue.

Development

Requirements

You need python>=3.8 and poetry.

You can install poetry by following the instructions on its official website, by using pip install poetry or by installing a package on your Linux distro.

Setup and run

  1. Clone this repository
git clone https://github.com/sparkmicro/Ki-nTree
  1. Install the requirements into a poetry-managed virtual environment
poetry install
Installing dependencies from lock file
...
Installing the current project: kintree (0.4.99)

Note: the version is not accurate (placeholder only)

  1. Run Ki-nTree in the virtual environment
poetry run python -m kintree_gui

or

$ poetry shell
$ python -m kintree_gui

Build

  1. Make sure you followed the previous installation steps, then run:
$ poetry build
Building kintree (0.6.99)
  - Building sdist
  - Built kintree-0.6.99.tar.gz
  - Building wheel
  - Built kintree-0.6.99-py3-none-any.whl
  1. Exit the virtual environment (Ctrl + D on Linux; you can also close the terminal and reopen it in the same folder).

    Run pip install dist/<wheel_file>.whl with the file name from the previous step. For example:

pip install dist/kintree-0.6.99-py3-none-any.whl
  1. You can now start Ki-nTree by typing kintree in the terminal, provided that your python dist path is a part of your $PATH.

Roadmap

Priority goes to implementing new features over GUI improvements
Open to new ideas and pull requests :smiley:

Versions 0.6.x or later

New Features
  • Revamp category selection based on hierarchical structure from InvenTree (reference)
  • Allow user to decide the category code to use for IPN
  • Add "Synchronize" menu option to pull InvenTree parts data into KiCad
Improvements
GUI
  • Migrate to Qt? (reference)
  • Create loading animation for API searches (asyncio)

License

The Ki-nTree source code is licensed under the GPL3.0 license as it uses source code under that license:

The KiCad templates are licensed under the Creative Commons CC0 1.0 license which means that "you can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission" (reference).

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

kintree-0.6.3.tar.gz (128.7 kB view hashes)

Uploaded Source

Built Distribution

kintree-0.6.3-py3-none-any.whl (150.7 kB view hashes)

Uploaded Python 3

Supported by

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