Name | inventree-part-import JSON |
Version |
1.8
JSON |
| download |
home_page | None |
Summary | CLI to import parts from suppliers like DigiKey, LCSC, Mouser, etc. to InvenTree |
upload_time | 2025-02-05 16:01:05 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | None |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[](https://pypi.org/project/inventree-part-import/)
[](https://www.python.org/)
[](LICENSE)
# InvenTree Part Import
This project offers a command line interface to easily import parts from suppliers like
DigiKey, LCSC, Mouser, etc. into your InvenTree instance.
## Installation
```console
pipx install inventree-part-import
```
*(`pip` should also work, but [`pipx`](https://github.com/pypa/pipx) is the new recommended way
to install standalone applications)*
### Arch Linux
Latest version from PyPI is available on AUR as
[python-inventree-part-import](https://aur.archlinux.org/packages/python-inventree-part-import).<br>
Git master version is available as
[python-inventree-part-import-git](https://aur.archlinux.org/packages/python-inventree-part-import-git).<br>
(Thanks to [@randrej](https://github.com/randrej)!)
## Getting Started
### Initial Configuration
When using the CLI tool for the first time, it will guide you through creating your own
configuration.
When configuring suppliers, it's **highly recommended** to always enable the DigiKey API:
```console
select the suppliers you want to setup: (SPACEBAR to toggle, ENTER to confirm)
> [x] DigiKey
[ ] LCSC
[ ] Mouser
[ ] Reichelt
[ ] TME
```
#### Default categories/parameters configuration
```console
setup default categories/parameters configuration:
> Copy categories from InvenTree
Copy default categories configuration
Create 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 the `Copy categories from InvenTree` option, to automatically
setup a configuration which matches your InvenTree database.
If you are a new user, you can select the `Copy default categories configuration` to create
a basic configuration which you can extend in the future.
You can also create your own configuration from scratch (or manually copy
[someones existing configuration](https://github.com/30350n/inventree_part_import_config)
) by selecting the `Create empty configuration (manual setup)` option.
### Basic Usage
To import parts, simply use the `inventree-part-import` command, followed by the supplier or
manufacturer part numbers of the parts you want to import.
```console
$ 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:
```console
$ inventree-part-import parts.csv
```
## Configuration
### `inventree.yaml`
This 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.yaml`
This 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)
- `interactive_part_matches`: the maximum number of parts to display in interactive mode
(set to null to disable)
- `interactive_category_matches`: the maximum number of categories to display in interactive mode
- `interactive_parameter_matches`: the maximum number of parameters to display in interactive mode
- `part_selection_format`: standard python format str used to format each line of the
interactive part selection menu (any fields from the `ApiPart` dataclass can be used,
defaults to: `"{MPN} | {manufacturer} | {SKU} | {supplier_link}"`)
- `auto_detect_columns`: list of column names in tabular data files that will be automatically
detected (defaults to `["Manufacturer Part Number", "MPN", "part_id"]`)
### `suppliers.yaml`
This file is used to configure supplier specific behavior.
The following parameters are always available:
- `currency`: overrides the currency for searching this supplier (see [`config.yaml`](#configyaml))
- `language`: overrides the language for searching this supplier (see [`config.yaml`](#configyaml))
- `location`: overrides the location for searching this supplier (see [`config.yaml`](#configyaml))
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>`.
#### DigiKey
For getting a DigiKey API key, follow the instructions
[here](https://github.com/peeter123/digikey-api#register).
Be sure to use a [Production App](https://developer.digikey.com/documentation/organization),
**not the Sandbox API!**
#### Mouser
Request a **Search API** key from the [Mouser API Hub](https://www.mouser.com/api-hub/).
#### TME
Request an API key at the [Developers Page](https://developers.tme.eu/).
### `categories.yaml`
This 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:
```yaml
Electronics:
Capacitors:
Ceramic:
Electrolytic:
Products:
```
Additionally you can define the following meta attributes (starting with `_`):
- `_aliases` has to be a list of supplier category names which will be mapped to that category
- `_description` specifies the categories description (defaults to category name)
- `_ignore` makes `inventree-part-import` ignore that category, as well as any subcategories
- `_parameters` has to be a list of parameter names (for parameters defined in
[`parameters.yaml`](#parametersyaml)) this category uses<br>
**note: parameters get inherited by sub categories**
- `_omit_parameters` has to be a list of parameters names defined in parent categories that
get omitted from the category
- `_structural` can be set to `true` to make the category structural
Here's an example for a config with special attributes:
```yaml
Electronics:
_description: Electronic Components # custom description
_structural: true # no parts are allowed to be directly in this category
Capacitors:
_parameters: # parameters for both the 'Ceramic' and 'Electrolytic' categories
- Capacitance
- Tolerance
Ceramic:
Electrolytic:
_aliases: # category names mapped to this category from various suppliers
- Aluminum Electrolytic Capacitors
- Aluminum Electrolytic Capacitors - SMD
- Aluminum Electrolytic Capacitors - Leaded
- Electrolyte Capacitors
Products:
_ignore: true # this category contains our own products, so we won't import anything into it
```
### `parameters.yaml`
This file should specify all your InvenTree parameters, as well as metadata for them.
The following meta attributes are available:
- `_aliases` has to be a list of supplier parameter names which will be mapped to that parameter
- `_description` specifies the parameters description (defaults to parameter name)
- `_unit` specifies the parameters unit (experimental)
Here's an example for a single parameter:
```yaml
Input Voltage:
_aliases:
- Voltage - Input
- Voltage - Input (Max)
- Maximum Input Voltage
_description: Max Input Voltage # optional
_unit: V # experimental, this can lead to import problems
```
### Pre 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:
```py
def fix_transistor_categories(api_part):
if "BJT" in api_part.category_path[-1] or "Bipolar (BJT)" in api_part.category_path:
transistor_type = api_part.parameters.get("Transistor Type", "")
if "NPN" in transistor_type:
api_part.category_path.append("NPN")
elif "PNP" in transistor_type:
api_part.category_path.append("PNP")
```
You can define any number of them in a `hooks.py` file in your configuration directory.
They'll get called in the order they're defined in.
For more examples, checkout my [config repository](https://github.com/30350n/inventree_part_import_config).
## Goal
The 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.
## Credits
- [InvenTree](https://inventree.org/) ([@SchrodingersGat](https://github.com/SchrodingersGat) and [@matmair](https://github.com/matmair))
This project wouldn't exist without their brilliant work on creating the awesome open-source
inventory management solution.
- [Ki-nTree](https://github.com/sparkmicro/Ki-nTree) ([@eeintech](https://github.com/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 [@atanisoft](https://github.com/atanisoft) for extensive beta testing!
## License
- This project is licensed under the [MIT](LICENSE) license.
Raw data
{
"_id": null,
"home_page": null,
"name": "inventree-part-import",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Bobbe <mail@30350n.de>",
"download_url": "https://files.pythonhosted.org/packages/b2/1e/c992bfa6d2ae220ad2d719f7277e1877481d9bcac5ee3b06828a772118a2/inventree_part_import-1.8.tar.gz",
"platform": null,
"description": "[](https://pypi.org/project/inventree-part-import/)\n[](https://www.python.org/)\n[](LICENSE)\n\n# InvenTree Part Import\n\nThis project offers a command line interface to easily import parts from suppliers like\nDigiKey, LCSC, Mouser, etc. into your InvenTree instance.\n\n## Installation\n\n```console\npipx install inventree-part-import\n```\n\n*(`pip` should also work, but [`pipx`](https://github.com/pypa/pipx) is the new recommended way\nto install standalone applications)*\n\n### Arch Linux\n\nLatest version from PyPI is available on AUR as\n[python-inventree-part-import](https://aur.archlinux.org/packages/python-inventree-part-import).<br>\nGit master version is available as\n[python-inventree-part-import-git](https://aur.archlinux.org/packages/python-inventree-part-import-git).<br>\n(Thanks to [@randrej](https://github.com/randrej)!)\n\n## Getting Started\n\n### Initial Configuration\n\nWhen using the CLI tool for the first time, it will guide you through creating your own\nconfiguration.\n\nWhen configuring suppliers, it's **highly recommended** to always enable the DigiKey API:\n\n```console\nselect the suppliers you want to setup: (SPACEBAR to toggle, ENTER to confirm)\n> [x] DigiKey\n [ ] LCSC\n [ ] Mouser\n [ ] Reichelt\n [ ] TME\n```\n\n#### Default categories/parameters configuration\n\n```console\nsetup default categories/parameters configuration:\n> Copy categories from InvenTree\n Copy default categories configuration\n Create empty configuration (manual setup)\n```\n\nIf you have already been using InvenTree for some time (so you already have setup your category\nstructure, parts, etc.), select the `Copy categories from InvenTree` option, to automatically\nsetup a configuration which matches your InvenTree database.\n\nIf you are a new user, you can select the `Copy default categories configuration` to create\na basic configuration which you can extend in the future.\n\nYou can also create your own configuration from scratch (or manually copy\n[someones existing configuration](https://github.com/30350n/inventree_part_import_config)\n) by selecting the `Create empty configuration (manual setup)` option.\n\n### Basic Usage\n\nTo import parts, simply use the `inventree-part-import` command, followed by the supplier or\nmanufacturer part numbers of the parts you want to import.\n\n```console\n$ inventree-part-import <part_number_1> <part_number_2> ...\n```\n\nYou can also batch import multiple parts from tabular data files (`.csv`, `.xlsx`, etc.) like\nso:\n\n```console\n$ inventree-part-import parts.csv\n```\n\n## Configuration\n\n### `inventree.yaml`\n\nThis file is used to configure authentication to your InvenTree host.\nIt has two parameters:\n\n- `host`: the host url to connect to (including port, if required)\n- `token`: the user token to authenticate with (this will be retrieved automatically by the CLI)\n\n### `config.yaml`\n\nThis file is used to configure general settings of the CLI tool, as well as default locales.\nThe following parameters have to be set:\n\n- `currency`: the default currency to use when searching suppliers (ISO4217 code)\n- `language`: the default language to use when searching suppliers (ISO639 code)\n- `location`: the default location to use when searching suppliers (ISO3166 code)\n- `scrape`: whether or not web page scraping is allowed (this can get you temporarily blocked)\n- `interactive_part_matches`: the maximum number of parts to display in interactive mode\n (set to null to disable)\n- `interactive_category_matches`: the maximum number of categories to display in interactive mode\n- `interactive_parameter_matches`: the maximum number of parameters to display in interactive mode\n- `part_selection_format`: standard python format str used to format each line of the\n interactive part selection menu (any fields from the `ApiPart` dataclass can be used,\n defaults to: `\"{MPN} | {manufacturer} | {SKU} | {supplier_link}\"`)\n- `auto_detect_columns`: list of column names in tabular data files that will be automatically\n detected (defaults to `[\"Manufacturer Part Number\", \"MPN\", \"part_id\"]`)\n\n### `suppliers.yaml`\n\nThis file is used to configure supplier specific behavior.\nThe following parameters are always available:\n\n- `currency`: overrides the currency for searching this supplier (see [`config.yaml`](#configyaml))\n- `language`: overrides the language for searching this supplier (see [`config.yaml`](#configyaml))\n- `location`: overrides the location for searching this supplier (see [`config.yaml`](#configyaml))\n\nAdditionally suppliers can have extra parameters for authentifcation to their respective APIs.\nThese can be set via the CLI like so: `inventree-part-import --configure <supplier>`.\n\n#### DigiKey\n\nFor getting a DigiKey API key, follow the instructions\n[here](https://github.com/peeter123/digikey-api#register).\nBe sure to use a [Production App](https://developer.digikey.com/documentation/organization),\n**not the Sandbox API!**\n\n#### Mouser\n\nRequest a **Search API** key from the [Mouser API Hub](https://www.mouser.com/api-hub/).\n\n#### TME\n\nRequest an API key at the [Developers Page](https://developers.tme.eu/).\n\n### `categories.yaml`\n\nThis file should specify all your InvenTree categories, as well as metadata like category\naliases, parameters, etc. for them.\n\nIt's defined as hierarchical tree structure where every 'node' represents a category.\nFor example:\n\n```yaml\nElectronics:\n Capacitors:\n Ceramic:\n Electrolytic:\nProducts:\n```\n\nAdditionally you can define the following meta attributes (starting with `_`):\n\n- `_aliases` has to be a list of supplier category names which will be mapped to that category\n- `_description` specifies the categories description (defaults to category name)\n- `_ignore` makes `inventree-part-import` ignore that category, as well as any subcategories\n- `_parameters` has to be a list of parameter names (for parameters defined in\n [`parameters.yaml`](#parametersyaml)) this category uses<br>\n **note: parameters get inherited by sub categories**\n- `_omit_parameters` has to be a list of parameters names defined in parent categories that\n get omitted from the category\n- `_structural` can be set to `true` to make the category structural\n\nHere's an example for a config with special attributes:\n\n```yaml\nElectronics:\n _description: Electronic Components # custom description\n _structural: true # no parts are allowed to be directly in this category\n Capacitors:\n _parameters: # parameters for both the 'Ceramic' and 'Electrolytic' categories\n - Capacitance\n - Tolerance\n Ceramic:\n Electrolytic:\n _aliases: # category names mapped to this category from various suppliers\n - Aluminum Electrolytic Capacitors\n - Aluminum Electrolytic Capacitors - SMD\n - Aluminum Electrolytic Capacitors - Leaded\n - Electrolyte Capacitors\nProducts:\n _ignore: true # this category contains our own products, so we won't import anything into it\n```\n\n### `parameters.yaml`\n\nThis file should specify all your InvenTree parameters, as well as metadata for them.\n\nThe following meta attributes are available:\n\n- `_aliases` has to be a list of supplier parameter names which will be mapped to that parameter\n- `_description` specifies the parameters description (defaults to parameter name)\n- `_unit` specifies the parameters unit (experimental)\n\nHere's an example for a single parameter:\n\n```yaml\nInput Voltage:\n _aliases:\n - Voltage - Input\n - Voltage - Input (Max)\n - Maximum Input Voltage\n _description: Max Input Voltage # optional\n _unit: V # experimental, this can lead to import problems\n```\n\n### Pre Creation Hooks (`hooks.py`)\n\nPre creation hooks are functions that get run after part information has been parsed from a\nsupplier, but before the InvenTree part gets created. They basically let you modify a part,\nbefore it gets imported. This can be very useful in some cases.\n\nFor example, here's one that assigns transistors into different categories, based on their type:\n\n```py\ndef fix_transistor_categories(api_part):\n if \"BJT\" in api_part.category_path[-1] or \"Bipolar (BJT)\" in api_part.category_path:\n transistor_type = api_part.parameters.get(\"Transistor Type\", \"\")\n if \"NPN\" in transistor_type:\n api_part.category_path.append(\"NPN\")\n elif \"PNP\" in transistor_type:\n api_part.category_path.append(\"PNP\")\n```\n\nYou can define any number of them in a `hooks.py` file in your configuration directory.\nThey'll get called in the order they're defined in.\n\nFor more examples, checkout my [config repository](https://github.com/30350n/inventree_part_import_config).\n\n## Goal\n\nThe end goal of this project is to not exist anymore in it's current form. Ideally everything\nthe CLI tool does would be directly available from the InvenTree web interface. This will most\nlikely be done by implementing plugins which offer the required functionality for each supplier.\n\n## Credits\n\n- [InvenTree](https://inventree.org/) ([@SchrodingersGat](https://github.com/SchrodingersGat) and [@matmair](https://github.com/matmair))\n This project wouldn't exist without their brilliant work on creating the awesome open-source\n inventory management solution.\n\n- [Ki-nTree](https://github.com/sparkmicro/Ki-nTree) ([@eeintech](https://github.com/eeintech))\n This project is inspired by Ki-nTree and aims to fix most of the issues I've had with it.\n It only provides the part importing functionality, but tries to improve it in every way.\n\n- Thanks to [@atanisoft](https://github.com/atanisoft) for extensive beta testing!\n\n## License\n\n- This project is licensed under the [MIT](LICENSE) license.\n",
"bugtrack_url": null,
"license": null,
"summary": "CLI to import parts from suppliers like DigiKey, LCSC, Mouser, etc. to InvenTree",
"version": "1.8",
"project_urls": {
"Homepage": "https://github.com/30350n/inventree_part_import"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "0b30edbe1e7ef4eaba8b53cb09d6c821f3887c5f57e8708b12e454711d2db24d",
"md5": "46770e2edd96af552ff9d3265492ca54",
"sha256": "3613d5e75f26d85dfa0ad53ec19beb13f8c66ce3732145595d8f6af6c2f38649"
},
"downloads": -1,
"filename": "inventree_part_import-1.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "46770e2edd96af552ff9d3265492ca54",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 45952,
"upload_time": "2025-02-05T16:01:04",
"upload_time_iso_8601": "2025-02-05T16:01:04.101958Z",
"url": "https://files.pythonhosted.org/packages/0b/30/edbe1e7ef4eaba8b53cb09d6c821f3887c5f57e8708b12e454711d2db24d/inventree_part_import-1.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "b21ec992bfa6d2ae220ad2d719f7277e1877481d9bcac5ee3b06828a772118a2",
"md5": "275a8f964bc76e205a6e649f93c40cda",
"sha256": "d7d0c4d2ad5a54562a1c342638b30b21498ced6ca74974a282621cd43174a9ed"
},
"downloads": -1,
"filename": "inventree_part_import-1.8.tar.gz",
"has_sig": false,
"md5_digest": "275a8f964bc76e205a6e649f93c40cda",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 36202,
"upload_time": "2025-02-05T16:01:05",
"upload_time_iso_8601": "2025-02-05T16:01:05.586652Z",
"url": "https://files.pythonhosted.org/packages/b2/1e/c992bfa6d2ae220ad2d719f7277e1877481d9bcac5ee3b06828a772118a2/inventree_part_import-1.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-05 16:01:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "30350n",
"github_project": "inventree_part_import",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "inventree-part-import"
}