Mouser Python API
January 5, 2023 ยท View on GitHub
Setup
Requirements
Mouser API Keys
Mouser provides two separate API keys:
- one for the cart and orders
- one for part searches.
Go to Mouser's API hub to request the keys.
To store the keys, two options:
- create two environmental variables
MOUSER_ORDER_API_KEYandMOUSER_PART_API_KEYwith the respective values of each key - create a file named
mouser_api_keys.yamlwith the order API key on the first line and the part API key on a second line.
:warning: Using the
mouser_api_keys.yamlfile method, make sure to runmousercommands in the same folder!
The keys will be automatically loaded for each API request.
Install
Pip
pip install mouser
Manually
- Create virtual environment and activate it
- Run
pip install -r requirements.txt
Poetry
- Install
poetrypackage:pip install poetry - Run
poetry install
Run
Pip
mouser
Manually
python mouser_cli.py
Poetry
poetry run mouser
Usage
This command line tool reflects the usage from Mouser's API structure documented here.
The first positional argument is the category of the request: cart (for MouserCart), order, history (for MouserOrderHistory) and search (for SearchAPI).
The second argument is the type of operation from the list of operations for each category.
Run mouser --help for more information about the usage.
Examples
The examples below assume this package was installed using Pip (for more options, see above)
Part Number Search
mouser search partnumber --number XXX
Export order to CSV
mouser order get --number XXX --export