Kicost Distributor Key and ID

I have installed Kicost and I keep getting the error:
WARNING:(WC017) Can’t enable Digi-Key without a client_id, client_secret and cache_path (kicost.distributors - log.py:107)
WARNING:(WC017) Can’t enable Mouser without a key (kicost.distributors - log.py:107)
WARNING:(WC017) Can’t enable Elemen14 without a key (kicost.distributors - log.py:107)
WARNING:(WC017) Can’t enable TME without a token and an app_secret (kicost.distributors - log.py:107)
WARNING:(WC017) Can’t enable Nexar without a client_id, client_secret and cache_path (kicost.distributors - log.py:107)

Getting a key and ID isn’t the issue.

My question is where do I enter these parameters?
If there is a config file to add them where is it located, if I need to create one where would I save it.?

Thanks.

You may get an answer here, but I’d also encourage you to ask the KiCost developers as all the plugins are entirely independent of KiCad proper. In this case, looks like the info is here:
https://hildogjr.github.io/KiCost/docs/_build/singlehtml/index.html#document-configuration

1 Like

Ill see if I can get some one over there, but I thought I would give it a shot here.
Thanks,
–Brian

I think @hildogjr took over when the original coder, who’s handle escapes me but I know the avatar ( :wink: ), started to lose interest in maintaining this because of the keys issue.

I can see where it would become an overload after while. I think its a good tool, I will get running sooner or later.

You might just need to apply for your own keys. I think the shared key might have been the problem. I just don’t really remember.

I do have a key but I am sure where to enter the data.

Did you have a read through the docs in the link. The first line mentions the config file.

Yes I went through them a few times. I did manage to get it.
What I had to do was create a new environment variable to put that data in.
I couldn’t find that information in the docs, but I did find it in the api.py file.

Hi Brian, I’m currently getting the same issuse.
Could you walk me through the process of creating an environment variable in which the data is contained? I assume you’re referring to the .yaml type file containings keys.
Which api.py file are you talking?

It’d be great to get this working for future projects.

Under Windows, mine is in C:\Users\craig\.config\kicost\config.yaml

I documented my journey to get KiCost running here. It wasn’t easy, but was worth it.

It was suggested to me that I also look at KiBot which uses KiCost for some of its output. Same maintainer for both.

Good Luck!

Hi Craig, I’ve a similar structure: C:\Users\Administrator.config\kicost\config.yaml
Two things I’ve to note about this:

  1. I created the .config and kicost folders containing the config.yaml file myself, because it wasn’t there after installing. I’m not sure whether that’s normal practice.
  2. I saved the config .yaml file as .yaml in studio code.

Yet when I run kicost --debug 10 I get DEBUG:No config file found (C:\Users\Administrator\.config\kicost\config.yaml) (kicost - log.py:115)
When I paste the entire path in the file explorer search bar it says the file can’t be found.
The config file gets the .yml file type not .yaml.

Are you running KiCost in a KiCad CMD window? Or are you trying to run it in a plain vanilla Windows CMD window? It should work in the first, won’t in the second. The KiCost CMD window is not the same as a Window cmd window and they aren’t interchangeable.

Did you read the link I posted above? " I documented my journey to get KiCost running here " (click on the blue [here])

Okay I’d made a mistake by using the wrong CMD. I followed the steps in your other post in Kicad cmd as admin, yet the same error persists: .config/kicost/config.yaml can’t be located.



Message modified per @paulvdh suggestion for Preformatted text (below). Now I think everything shows correctly.

Is that “.config” with a period on the front or “config” without the period?

Try doing a directory listing:

C:\Users\craig>dir
Volume in drive C is Local Disk
Volume Serial Number is 0281-30FA

Directory of C:\Users\craig

03/14/2024 01:08 PM .
02/18/2024 07:39 PM …
12/07/2023 12:49 PM 10,816 .bash_history
07/17/2022 12:31 PM .cache
02/04/2024 02:05 PM .config

Notice the period in front of “config”. I notice in your listing above, extensions are hidden. You might try turning off hidden so you can see what’s going on in your file system.

When I run debug at level 3, the first line tells me where kicost is looking for the config file. Do you have file permissions set in your OS so kicost can read the config file?

C:\Users\craig\Desktop\kicad8>kicost --debug 3
DEBUG:Loading config from: C:\Users\craig\.config\kicost\config.yaml (kicost - log.py:115)

You might also try forcing where KiCost looks for the config file with the options:

-c [CONFIG.YAML], --config [CONFIG.YAML]

Update: I read your post above where it shows


If you’ve verified your config file exists in this location (notice the period before “config”, in the path), and it’s readable, the only thing left I can think of is, does your config file follow the format described in the config documentation?
There really isn’t anything else that can be wrong. Check these things -carefully-. When I set mine up, I copied and pasted the documented config.yaml and modified from there.

Try running KiCost from its GUI by launching just “kicost” without any options from the command line.

Then if you still can’t find the issue, it might be worth a post in the KiCost github issue area asking for help.

There is a bit of interference for this forum software here. In a path name like below, the forum software eats the backslash before the .config, unless you use the Preformatted text

Same quote, but now modified as preformatted text (with back ticks):

And a screenshot of how it looks during editing:
image

I made a copy of the .yml file, opened it in notepad and saved it as .yaml from notepad.
This seemed to be the fix for locating the config file.
Visual Studio Code converts the file to .yml instead of .yaml for some reason.

Now I’ve some bug where the price string can’t be converted to float, but I’ll figure this one out myself :slight_smile: .

Thank you Craig for pointing out that I was using the wrong CMD, that led me on the right path.
Thanks for your help Craig and Paul.

1 Like

Hi guys, late on I have being the main maintainer of KiCost, after @devbisme allow me to take this position. I having counted with contributions of programmers (thank you @set and others) to keep it running and add new APIs of services that allow, (by use of personal keys), to request the part information/prices. (Previous, KiCost used the scrape of each distributor webpage as methodoly to catch the information, which became a cumbersome due HTML page changes and anti-robot page implementations).

In actual status KiCost still need some refactor to be easy to add, by Python classes/modules, new APIs and services that became available on the Internet (new kicost/distributor/api_*.py files, that respond with a bunch of distributor page information). APIs to unique distributions website are also kept as kicost/distributor/dist_*.py files).

I recommend to configure the personal user key for just one api_*.py API’s module. If you configure, for example, the general module API PARTINFO, that give information of a lot of distributors, and Digikey, the Digikey API response will overwrite the Digikey information give by Partinfo (because the direct response of one distributor is update compared to the general one). It also a way to use a visual tool or configure as BOM script to Eschema by kicost --setup / kicost --unsetup

KiCost could also be benefited with some cache implementation of this data (maybe some Python mySQL DB, with registry expiration). User case: most of time we get one BoM spreadsheet and realize that we missed some components.

And other issues and milestones that could improve the tool.

In this last days I have been busy in my work, also couldn’t log into Github due Microsoft 2-factor authentication restriction that didn’t make available SMS t o my country. I am try to bypass this issue.

In the meantime, I thanks the work the older users have be done here, explaining to new user how to configure the tool. And we also appreciate code contributions to the repository in the sense of new APIs.

1 Like

Quote the documentation:

Currently all the APIs needs some kind of key/token, lamentably we no longer have an API that doesn’t need it.

The Nexar API provides access to various distributors. It has a free option, with a current limit of 1000 parts/month. This is free and you just need to register yourself and an application at Nexar.

The other APIs are provided by each distributor, and they usually offer a free service with a generous limit.

I already used Digikey, Mouse and TME for my personal projects. Wich KiCost spreadsheet have the resource of copy (the last part of spreadsheet) and past at those web sites for assembly a cart and shop, with the ability of generate a BOM of 2 or more KiCad project and purchase in once with project identification printed into the bag labels (we used to save shipping).

Spreadsheet use workflow:

  1. Fill the pretended board quantity → The Qty column will update the colors (legend): purchased all, missing available, …;
  2. Fill the Purch of each Distributor (the Green mark the shipper) → Qty colors will be updated;
  3. Copy and past the code for bulk shop as the comment that I wrote before.

I case of BOM of multiple project the “Purchase description:” fill of each individual project can be filled to curtail the bag with component of each one (in same mail package / purchase shipping).