InvenTree 0.12
introduced a new parameter template system which was not supported until version 0.12.6
came out, see #165 for more details. In short, Ki-nTree currently supports InvenTree 0.11
or older versions, and 0.12.6
and future versions. From 0.13.0
onwards a InvenTree setting needs to be modified for Ki-nTree to work: InvenTree Settings
-> Part Parameters
-> Enforce Parameter Units
-> OFF (requires administrator rights)
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:
- Digi-Key, Mouser, Element14 and LCSC enormous part databases and free APIs
- the awesome open-source InvenTree Inventory Management System built and maintained by @SchrodingersGat and @matmair
- the reliable and SCM-friendly KiCad file parser KiUtils built and maintained by @mvnmgrx
- the amazing Digi-Key API python library built and maintained by @peeter123
- the Mouser Python API built and maintained by @eeintech
⚠️ Important NoteKi-nTree version
1.0.x
and forward support KiCad versions 6 and up.Ki-nTree versions
0.5.x
and0.6.x
only support KiCad version 6 (pip install kintree==0.6.6
).To use with KiCad version 5, use older Ki-nTree
0.4.x
versions (pip install kintree==0.4.8
).
Ki-nTree was developed by @eeintech for SPARK Microsystems, who generously accepted to make it open-source!
- Ki-nTree is currently tested for Python 3.9 to 3.11 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
- Ki-nTree requires a Mouser Search API key. To request one, head over to https://www.mouser.ca/api-search/ and click on "Sign Up for Search API"
- Ki-nTree requires an Element14 Product Search API key to fetch part information for the following suppliers: Farnell (Europe), Newark (North America) and Element14 (Asia-Pacific). To request one, head over to https://partner.element14.com/ and click on "Register"
- Install using Pip
pip install -U kintree
- Run Ki-nTree
kintree
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.
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
Ki-nTree is available on Arch Linux's AUR as python-kintree
.
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: Before running it, make sure you have setup your category tree in yourcategories.yaml
configuration file 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 won't be able to add parts to InvenTree.
Configuration files are stored in the folder pointed by the Configuration Files Folder
path in the "User Settings" window:
Click here to read about configuration files
Ki-nTree uses a number of YAML configuration files to function. New users shouldn't need to worry about them to try out Ki-nTree (except for categories.yaml
as mentioned in the previous section), however they can be modified to customize behavior and workflow.
Below is a summary table of the different configuration files, their function and if they are updated by the GUI:
Filename | Function | GUI Update? |
---|---|---|
categories.yaml |
InvenTree categories hierarchy tree and category codes for IPN generation (see Before Starting section) | ❌ |
general.yaml |
General user settings | ✔️ |
internal_part_number.yaml |
Controls for IPN generation | ✔️ |
inventree_<env>.yaml |
InvenTree login credentials, per environment (<env>=['dev', 'prod'] ) |
✔️ |
kicad.yaml |
KiCad symbol, footprint and library paths | ✔️ |
kicad_map.yaml |
Mapping between InvenTree parent categories and KiCad symbol/footprint libraries and templates | ❌ |
parameters.yaml |
List of InvenTree parameters templates (see InvenTree Part Parameters documentation) | ❌ |
parameters_filters.yaml |
Mapping between InvenTree parent categories and InvenTree parameters templates | ❌ |
search_api.yaml |
Generic controls for Supplier search APIs like cache validity | ✔️ |
supplier_parameters.yaml |
Mapping between InvenTree parameters templates and suppliers parameters/attributes, sorted by InvenTree parent categories (see Part Parameters section) | ❌ |
<supplier>_config.yaml |
Mapping for supplier name and search results fields, to overwrite defaults (<supplier>=['digikey', 'element14', 'lcsc', 'mouser'] ) |
❌ |
<supplier>_api.yaml |
Required supplier API fields, custom to each supplier (<supplier>=['digikey', 'element14', 'lcsc', 'mouser'] ) |
✔️ |
digikey_categories.yaml |
Mapping between InvenTree categories and Digi-Key categories | ❌ |
digikey_parameters.yaml |
Mapping between InvenTree parameters and Digi-Key parameters/attributes | ❌ |
Ki-nTree only supports matching between InvenTree and Digi-Key categories and parameters/attributes (help wanted!)
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.
- With Ki-nTree GUI open, click on "Settings > Supplier > Digi-Key" and fill in both Digi-Key API Client ID and Secret keys (optional: click on "Test" to get an API token)
- Click on "Settings > Supplier > Mouser" and fill in the Mouser part search API key
- Click on "Settings > Supplier > Element14" and fill in the Element14 product search API key (key is shared with Farnell and Newark)
- Click on "Settings > KiCad", browse to the location where KiCad symbol, template and footprint libraries are stored on your computer then click "Save"
- 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 check communication with server)
a. It is possible to define a Proxy Server over which all interactions with InvenTree will be routed. To set a proxy server use the "Enable Proxy Support" switch in "Settings > InvenTree" and define the proxy address in the new input field.
b. Instead of user credential authentication token authentication is also supported. To use a token add it it to the "Password or Token" field and leave the "Username" empty. You can retrieve your personal access token from your InvenTree server by sending an get-request to its api urlapi/user/token/
. c. If needed this tool can try to download the parts datasheet from the suppliers and upload it it to the attachment section of each part. For this just activate "Upload Datasheets to InvenTree" in the InvenTree settings d. It is also possible to sync the prices in InvenTree with the latest supplier prices. For this enable "Upload Pricing Data to InvenTree" - If your InvenTree server requires a IPN in a specific pattern make sure to adjust "Settings > InvenTree > Internal Part Number" to match it or adjust the servers pattern to the one yo set in Ki-nTree
Note: All URLs should start with "http://" if they do not have a valid SSL certificate.
Show steps (click to expand)
Enter your Digi-Key developer 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.
Ki-nTree uses supplier parameters to populate InvenTree parameters. In order to match between supplier and InvenTree, users need to setup the configuration file 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
It is also possible to cross reference the mappings of different categories. To define one or multiple parent categories a parameter named parent
can be added where the items then are the desired parent categories. If a parameter name is present in both parent and child, the childs definition will override the parent.
A template image for an category can be set by using the image
parameter. The sole item in this parameter must the filename of an already existing part image on the the InvenTree server.
Refer to this file as a starting point / example.
Ki-nTree currently supports APIs for the following electronics suppliers: Digi-Key, Mouser, Element14, TME and LCSC.
- In the main window, enter the part number and select the supplier in drop-down list, then click the "Submit" button (arrow). It will start by fetching part data using the supplier's API
- 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
- Once the part data has been successfully fetched from the supplier's API, you can review the part information in the different fields and edit them, if needed.
- Then, go to the Inventree tabl to pick the
Category
andSubcategory
to use for this part - If you desire to add this part to KiCad, click the KiCad tab and select the KiCad symbol library, the template and the footprint library to use for this part
- Finally, go to the Create tab and launch the part creation. It will take some time to complete the process in InvenTree and/or KiCad, once it finishes you'll be notified of the result
If the part was created or found in InvenTree, and if you have selected this option in the settings, your browser will automatically open and navigate to the new Inventree part page.
The automatic part generation in KiCad is controlled via templates:
- Template examples are shipped together with Ki-nTree, these can be adjusted to your liking or you also can create completely new ones.
- Each template has its own library file where the file name defines the templates name.
- The templates can use the parameters and attributes of the InvenTree part on a wildcard base. So you can add for example
Resistance@Tolerance
into a field and the resulting part will then have the resistance and the tolerance value inside this text field. - Using the templates and wildcards without the InvenTree functions enabled is also possible. In this case the library parameter wildcards need to be configured in the
supplier_parameters.yaml
for each library individually.
Enjoy!
For any problem/bug you find, please report an issue.
You need python>=3.9
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.
- Clone this repository
git clone https://github.com/sparkmicro/Ki-nTree
- Install the requirements into a
poetry
-managed virtual environment
poetry install
Installing dependencies from lock file
...
Installing the current project: kintree (1.1.99)
Note: the version is not accurate (placeholder only)
- Run Ki-nTree in the virtual environment
poetry run python -m kintree_gui
or
$ poetry shell
$ python -m kintree_gui
- Make sure you followed the previous installation steps, then run:
$ poetry build
Building kintree (1.1.99)
- Building sdist
- Built kintree-1.1.99.tar.gz
- Building wheel
- Built kintree-1.1.99-py3-none-any.whl
-
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-1.1.99-py3-none-any.whl
- You can now start Ki-nTree by typing
kintree
in the terminal, provided that your python dist path is a part of your$PATH
.
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).