Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyword search on Product #1

Open
auphofBSF opened this issue Mar 12, 2020 · 1 comment
Open

Keyword search on Product #1

auphofBSF opened this issue Mar 12, 2020 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@auphofBSF
Copy link
Owner

@lbrolliar asked in peeter123/digikey-api#3 (comment)
Quick question. Is there code for doing a keyword search to find the Digikey part number?

@auphofBSF auphofBSF added enhancement New feature or request good first issue Good for newcomers labels Mar 12, 2020
@auphofBSF
Copy link
Owner Author

A quick question, but unfortunately opens a longer explanation:

The short version

it is there but just depends on how you want to use it.

The longer Version

The lite version of the protocol wraps the swagger generated api, this can be seen in

def product_details(self,digi_key_part_number,**kwargs):

All the digikey api's that have been implemented in https://github.com/auphofBSF/community-digikey-api-codegen-python-clients (Currently ProductInformation and OrderSupport ) will have all supported API calls in the generated python code.

In this case the generated API is import digikey_productinformation. They can be used directly but you have to manage the API instance. Or they are wrapped in the Lite classes such as in class ProductInformation def product_details and the class def __init__() does all the management .
In the case of wanting to do a keyword search using the Lite api import digikey_api_v3_lite A new method needs to be created following the same structure as def product_details . The method name matching the api name for consistency.

the relevant Digikey REST API doc for this keyword search is https://developer.digikey.com/products/product-information/partsearch/keywordsearch

The documentation for the generated API python code can be viewed in the source once generated. If this is installed automatically it will be in the pip install locations ...site_packages... alternatively the various call and the methods documentation can be viewed by doing the following

"""
Example of using finding documentation on python Digikey API calls 
"""
import digikey_api_v3_lite  as digiAPI

# SETUP the Digikey authentication see https://developer.digikey.com/documentation/organization#production
os.environ['DIGIKEY_CLIENT_ID'] = '<DIGIKEY_APPLICATION_ID>'
os.environ['DIGIKEY_CLIENT_SECRET'] = '<DIGIKEY_SECRET>'
os.environ['DIGIKEY_STORAGE_PATH'] = r'<PATH_TO_THE_TOKEN_CACHING_LOCATION>'

product_information_object = digiAPI.ProductInformation()
digikey_api_ProdInfo = product_information_object._api_instance
# list all methods of the generated_api that 
print([method for method in dir(digikey_api_ProdInfo ) if '__' not in method])
# Should print the following 
#['api_client', 'digi_reel_pricing', 'digi_reel_pricing_with_http_info', 'keyword_search', 'keyword_search_with_http_info', 'product_details', 'product_details_with_http_info', 'suggested_parts', 'suggested_parts_with_http_info']

# choose a particular method ie "keyword_search" and retrieve the generated doc's
print(digikey_api_ProdInfo.keyword_search.__doc__)

I am taking the time to describe this as further implementations work needs to be done depending on specific use cases. I have just done some work recently on another API and have got myself more familiar with python decorators. I believe this Lite API can be a set of Decorators to automatically wrap the generated API's. This will reduce the amount of individual code to write and enable rapid integration of all the Digikey API's . I just notice there are now additional API's available [BOM, Taxonomy Search]
Anyone wanting to generate a Decorator that automatically wraps the https://github.com/auphofBSF/community-digikey-api-codegen-python-clients is more than welcome to submit a PR. Alternatively I will also accept PR for just extending the Lite API class as per def product_details shown above.

Additionally python generated API doc set should be automatically generated by something like sphinx and be there to complement the Digikey JSON API documentation. I have raised this as an enhancement auphofBSF/community-digikey-api-codegen-python-clients#1

I am unable to do much more in the next week but may be able to look into some of this in the coming weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant