Package: kintree
Ki-nTreeFast part creation forKiCadandInvenTree:warning: InvenTree CompatibilityInvenTree0.12introduced a new parameter template system which was not supported until version0.12.6came out, seehttps://github.com/sparkmicro/Ki-nTree/issues/165for more details. In short, Ki-nTree currently supports InvenTree0.11or older versions, and0.12.6and future versions. From0.13.0onwards a InvenTree setting needs to be modified for Ki-nTree to work:InvenTree Settings->Part Parameters->Enforce Parameter Units->OFF(requires administrator rights):fast_forward:Demo VideoIntroductionKi-nTree (pronounced "Key Entry" or "Key 'n' Tree") aims to:automate part creation of KiCad library partsautomate part creation of InvenTree partssynchronize parts data between KiCad and InvenTreeKi-nTree works with:Digi-Key,Mouser,Element14andLCSCenormouspart databases and free APIsthe awesome open-sourceInvenTree Inventory Management Systembuilt and maintained by@SchrodingersGatand@matmairthe reliable and SCM-friendly KiCad file parserKiUtilsbuilt and maintained by@mvnmgrxthe amazingDigi-Key API python librarybuilt and maintained by@peeter123theMouser Python APIbuilt and maintained by@eeintech:warning:Important NoteKi-nTree version1.0.xand forward support KiCad versions6 and up.Ki-nTree versions0.5.xand0.6.xonly support KiCad version6(pip install kintree==0.6.6).To use with KiCad version5, use older Ki-nTree0.4.xversions (pip install kintree==0.4.8).Ki-nTree was developed by@eeintechforSPARK Microsystems, who generously accepted to make it open-source!Get StartedRequirementsKi-nTree is currently tested for Python 3.9 to 3.11 versions.Ki-nTree requires a Digi-KeyproductionAPI instance. To create one, go tohttps://developer.digikey.com/. Create an account, an organization and add aproductionAPI to your organization. Save both Client ID and Secret keys.Here is a videoto help with the different stepsKi-nTree requires a Mouser Search API key. To request one, head over tohttps://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 tohttps://partner.element14.com/and click on "Register"Installation (system wide)Install using Pippipinstall-UkintreeRun Ki-nTreekintreeRun in virtual environment (contained)Linux / MacOSCreate a virtual environment and activate it with:$python3-mvenvenv-kintree
$sourceenv-kintree/bin/activateThen follow the steps from theinstallation section.WindowsIn Git Bash, use the following commands to create and activate a virtual environment:$python3-mvenvenv-kintree
$sourceenv-kintree/Scripts/activateFor any other Windows terminal, refer to theofficial documentationPackagesArch LinuxKi-nTree isavailable on Arch Linux's AURaspython-kintree.Usage InstructionsBefore StartingIf 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 yourcategories.yamlconfiguration file according to your own preferences, else it will use thedefault setup.python3-mkintree.setup_inventreeIf the InvenTree category tree isnot setupbefore starting to use Ki-nTree, youwon't be able to add partsto InvenTree.Advanced ConfigurationConfiguration files are stored in the folder pointed by theConfiguration Files Folderpath in the "User Settings" window:Click here to read about configuration filesKi-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 forcategories.yamlas 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:FilenameFunctionGUI Update?categories.yamlInvenTree categories hierarchy tree and category codes for IPN generation (seeBefore Starting section):x:general.yamlGeneral user settings:heavy_check_mark:internal_part_number.yamlControls for IPN generation:heavy_check_mark:inventree_<env>.yamlInvenTree login credentials, per environment (<env>=['dev', 'prod']):heavy_check_mark:kicad.yamlKiCad symbol, footprint and library paths:heavy_check_mark:kicad_map.yamlMapping between InvenTree parent categories and KiCad symbol/footprint libraries and templates:x:parameters.yamlList of InvenTree parameters templates (seeInvenTree Part Parameters documentation):x:parameters_filters.yamlMapping between InvenTree parent categories and InvenTree parameters templates:x:search_api.yamlGeneric controls for Supplier search APIs like cache validity:heavy_check_mark:supplier_parameters.yamlMapping between InvenTree parameters templates and suppliers parameters/attributes, sorted by InvenTree parent categories (seePart Parameters section):x:<supplier>_config.yamlMapping for supplier name and search results fields, to overwrite defaults (<supplier>=['digikey', 'element14', 'lcsc', 'mouser']):x:<supplier>_api.yamlRequired supplier API fields, custom to each supplier (<supplier>=['digikey', 'element14', 'lcsc', 'mouser']):heavy_check_mark:digikey_categories.yamlMapping between InvenTree categories and Digi-Key categories:x:digikey_parameters.yamlMapping between InvenTree parameters and Digi-Key parameters/attributes:x:Ki-nTree only supports matching between InvenTree and Digi-Key categories and parameters/attributes (help wanted!)InvenTree PermissionsEach InvenTree user has a set of permissions associated to them.
Please refer to theInvenTree documentationto 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 partsIf 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.SettingsWith 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" toget an API token)Click on "Settings > Supplier > Mouser" and fill in the Mouser part search API keyClick 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-nTreeGet Digi-Key API tokenShow steps (click to expand)Enter your Digi-Key developer account credentials then login. The following page will appear (user@email.comwill 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-localhostLastly, a new page will open with a "You may now close this window." message, proceed to get the token.Part ParametersKi-nTree usessupplierparameters to populateInvenTreeparameters. In order to match between supplier and InvenTree, users need to setup the configuration filesupplier_parameters.yamlwith 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_1Refer tothis fileas a starting point / example.Part Number SearchKi-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 "CREATE". It will start by fetching part data using the supplier's APIIn 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 stepsOnce 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 theCategoryandSubcategoryto use for this part (Ki-nTree tries to match them automatically)Then, you will be prompted with selecting the KiCad symbol library, the template and the footprint library to use for this partIt will take some time to complete the part creation in InvenTree and/or KiCad, once it finishes you'll be notified of the resultFinally, if the part was created or found in InvenTree, your browser will automatically open a new tab with the part informationKicad TemplatesThe 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 exampleResistance@Toleranceinto 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 thesupplier_parameters.yamlfor each library individually.Enjoy!For any problem/bug you find, pleasereport an issue.DevelopmentRequirementsYou needpython>=3.9andpoetry.You can install poetry by following the instructionson its official website, by usingpip install poetryor by installing a package on your Linux distro.Setup and runClone this repositorygitclonehttps://github.com/sparkmicro/Ki-nTreeInstall the requirements into apoetry-managed virtual environmentpoetryinstall
Installingdependenciesfromlockfile
...
Installingthecurrentproject:kintree(1.0.99)Note: the version is not accurate (placeholder only)Run Ki-nTree in the virtual environmentpoetryrunpython-mkintree_guior$poetryshell
$python-mkintree_guiBuildMake sure you followed the previous installation steps, then run:$poetrybuild
Buildingkintree(1.0.99)-Buildingsdist-Builtkintree-1.0.99.tar.gz-Buildingwheel-Builtkintree-1.0.99-py3-none-any.whlExit the virtual environment (Ctrl + Don Linux; you can also close the
terminal and reopen it in the same folder).Runpip install dist/<wheel_file>.whlwith the file name from the previous
step. For example:pipinstalldist/kintree-1.0.99-py3-none-any.whlYou can now start Ki-nTree by typingkintreein the terminal, provided
that your python dist path is a part of your$PATH.LicenseThe Ki-nTree source code is licensed under theGPL3.0 licenseas it uses source code under that license:https://github.com/mvnmgrx/kiutilshttps://github.com/peeter123/digikey-apiTheKiCad templatesare licensed under theCreative Commons CC0 1.0 licensewhich means that "you can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission" (reference).