Package: inventree-part-import
InvenTree Part ImportThis project offers a command line interface to easily import parts from suppliers like
DigiKey, LCSC, Mouser, etc. into your InvenTree instance.Installationpipx install inventree-part-import(pipshould also work, butpipxis the new recommended way
to install standalone applications)Getting StartedInitial ConfigurationWhen using the CLI tool for the first time, it will guide you through creating your own
configuration.When configuring suppliers, it'shighly recommendedto always enable the DigiKey API:select the suppliers you want to setup: (SPACEBAR to toggle, ENTER to confirm)> [x] DigiKey[ ] LCSC[ ] Mouser[ ] Reichelt[ ] TMEDefault categories/parameters configurationsetup default categories/parameters configuration:> Copy categories from InvenTreeCopy default categories configurationCreate empty configuration (manual setup)If you have already been using InvenTree for some time (so you already have setup your category
structure, parts, etc.), select theCopy categories from InvenTreeoption, to automatically
setup a configuration which matches your InvenTree database.If you are a new user, you can select theCopy default categories configurationto create
a basic configuration which you can extend in the future.You can also create your own configuration from scratch (or manually copysomeones existing configuration) by selecting theCreate empty configuration (manual setup)option.Basic UsageTo import parts, simply use theinventree-part-importcommand, followed by the supplier or
manufacturer part numbers of the parts you want to import.$inventree-part-import<part_number_1><part_number_2>...You can also batch import multiple parts from tabular data files (.csv,.xlsx, etc.) like
so:$inventree-part-importparts.csvConfigurationinventree.yamlThis file is used to configure authentication to your InvenTree host.
It has two parameters:host: the host url to connect to (including port, if required)token: the user token to authenticate with (this will be retrieved automatically by the CLI)config.yamlThis file is used to configure general settings of the CLI tool, as well as default locales.
The following parameters have to be set:currency: the default currency to use when searching suppliers (ISO4217 code)language: the default language to use when searching suppliers (ISO639 code)location: the default location to use when searching suppliers (ISO3166 code)scrape: whether or not web page scraping is allowed (this can get you temporarily blocked)max_results: the maximum number of results to display in interactive mode
(set to null to disable)suppliers.yamlThis file is used to configure supplier specific behavior.
The following parameters are always available:currency: overrides the currency for searching this supplier (seeconfig.yaml)language: overrides the language for searching this supplier (seeconfig.yaml)location: overrides the location for searching this supplier (seeconfig.yaml)Additionally suppliers can have extra parameters for authentifcation to their respective APIs.
These can be set via the CLI like so:inventree-part-import --configure <supplier>.DigiKeyFor getting a DigiKey API key, follow the instructionshere.
Be sure to use aProduction App,not the Sandbox API!MouserRequest aSearch APIkey from theMouser API Hub.TMERequest an API key at theDevelopers Page.categories.yamlThis file should specify all your InvenTree categories, as well as metadata like category
aliases, parameters, etc. for them.It's defined as hierarchical tree structure where every 'node' represents a category.
For example:Electronics:Capacitors:Ceramic:Electrolytic:Products:Additionally you can define the following meta attributes (starting with_):_aliaseshas to be a list of supplier category names which will be mapped to that category_descriptionspecifies the categories description (defaults to category name)_ignoremakesinventree-part-importignore that category, as well as any subcategories_parametershas to be a list of parameter names (for parameters defined inparameters.yaml) this category usesnote: parameters get inherited by sub categories_structuralcan be set totrueto make the category structuralHere's an example for a config with special attributes:Electronics:_description:Electronic Components# custom description_structural:true# no parts are allowed to be directly in this categoryCapacitors:_parameters:# parameters for both the 'Ceramic' and 'Electrolytic' categories-Capacitance-ToleranceCeramic:Electrolytic:_aliases:# category names mapped to this category from various suppliers-Aluminum Electrolytic Capacitors-Aluminum Electrolytic Capacitors - SMD-Aluminum Electrolytic Capacitors - Leaded-Electrolyte CapacitorsProducts:_ignore:true# this category contains our own products, so we won't import anything into itparameters.yamlThis file should specify all your InvenTree parameters, as well as metadata for them.The following meta attributes are available:_aliaseshas to be a list of supplier parameter names which will be mapped to that parameter_descriptionspecifies the parameters description (defaults to parameter name)_unitspecifies the parameters unit (experimental)Here's an example for a single parameter:Input Voltage:_aliases:-Voltage - Input-Voltage - Input (Max)-Maximum Input Voltage_description:Max Input Voltage# optional_unit:V# experimental, this can lead to import problemsPre Creation Hooks (hooks.py)Pre creation hooks are functions that get run after part information has been parsed from a
supplier, but before the InvenTree part gets created. They basically let you modify a part,
before it gets imported. This can be very useful in some cases.For example, here's one that assigns transistors into different categories, based on their type:deffix_transistor_categories(api_part):if"BJT"inapi_part.category_path[-1]or"Bipolar (BJT)"inapi_part.category_path:transistor_type=api_part.parameters.get("Transistor Type","")if"NPN"intransistor_type:api_part.category_path.append("NPN")elif"PNP"intransistor_type:api_part.category_path.append("PNP")You can define any number of them in ahooks.pyfile in your configuration directory.
They'll get called in the order they're defined in.For more examples, checkout myconfig repository.GoalThe end goal of this project is to not exist anymore in it's current form. Ideally everything
the CLI tool does would be directly available from the InvenTree web interface. This will most
likely be done by implementing plugins which offer the required functionality for each supplier.CreditsInvenTree(@SchrodingersGatand@matmair)
This project wouldn't exist without their brilliant work on creating the awesome open-source
inventory management solution.Ki-nTree(@eeintech)
This project is inspired by Ki-nTree and aims to fix most of the issues I've had with it.
It only provides the part importing functionality, but tries to improve it in every way.Thanks to@atanisoftfor extensive beta testing!LicenseThis project is licensed under theMITlicense.