digikey-api


Namedigikey-api JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/peeter123/digikey-api
SummaryPython client for Digikey API
upload_time2024-11-22 09:09:48
maintainerNone
docs_urlNone
authorPeter Oostewechel
requires_pythonNone
licenseGPL v3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            Python Client for Digikey API
=================================
Search for parts in the Digi-Key catalog by keyword using KeywordSearch. Then make a PartDetails call to retrieve all
real time information about the part including pricing. PartDetails works best with Digi-Key part numbers as some
manufacturers overlap other manufacturer part numbers.

[![Pypi](https://img.shields.io/pypi/v/digikey-api.svg?color=brightgreen)](https://pypi.org/project/digikey-api/)
[![Donate](https://img.shields.io/badge/Donate-PayPal-gold.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=53HWHHVCJ3D4J&currency_code=EUR&source=url)

# What does it do
`digikey-api` is an [Digkey Part Search API](https://api-portal.digikey.com/node/8517) client for Python 3.6+. API response data is returned as Python objects that attempt to make it easy to get the data you want. Not all endpoints have been implemented.

# Quickstart

## Install
```sh
pip install digikey-api

cache_dir="path/to/cache/dir"
mkdir -p $cache_dir

export DIGIKEY_CLIENT_ID="client_id"
export DIGIKEY_CLIENT_SECRET="client_secret"
export DIGIKEY_STORAGE_PATH="${cache_dir}"
```

The cache dir is used to store the OAUTH access and refresh token, if you delete it you will need to login again.

# API V3
## Register
Register an app on the Digikey API portal: [Digi-Key API V3](https://developer.digikey.com/get_started). You will need
the client ID and the client secret to use the API. You will also need a Digi-Key account to authenticate, using the
Oauth2 process.

When registering an app the OAuth Callback needs to be set to `https://localhost:8139/digikey_callback`.

## Use [API V3]
Python will automatically spawn a browser to allow you to authenticate using the Oauth2 process. After obtaining a token
the library will cache the access token and use the refresh token to automatically refresh your credentials.

You can test your application using the sandbox API, the data returned from a Sandbox API may not be complete, but the
structure of the Sandbox API response will be a representation of what to expect in Production.

For valid responses make sure you ue the client ID and secret for a [Production App](https://developer.digikey.com/documentation/organization).
Otherwise, it is possible that dummy data is returned and you will pull your hair as to why it doesn't work.

```python
import os
from pathlib import Path

import digikey
from digikey.v3.productinformation import KeywordSearchRequest
from digikey.v3.batchproductdetails import BatchProductDetailsRequest

CACHE_DIR = Path('path/to/cache/dir')

os.environ['DIGIKEY_CLIENT_ID'] = 'client_id'
os.environ['DIGIKEY_CLIENT_SECRET'] = 'client_secret'
os.environ['DIGIKEY_CLIENT_SANDBOX'] = 'False'
os.environ['DIGIKEY_STORAGE_PATH'] = CACHE_DIR

# Query product number
dkpn = '296-6501-1-ND'
part = digikey.product_details(dkpn)

# Search for parts
search_request = KeywordSearchRequest(keywords='CRCW080510K0FKEA', record_count=10)
result = digikey.keyword_search(body=search_request)

# Only if BatchProductDetails endpoint is explicitly enabled
# Search for Batch of Parts/Product
mpn_list = ["0ZCK0050FF2E", "LR1F1K0"] #Length upto 50
batch_request = BatchProductDetailsRequest(products=mpn_list)
part_results = digikey.batch_product_details(body=batch_request)
```

## Logging [API V3]
Logging is not forced upon the user but can be enabled according to convention:
```python
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

digikey_logger = logging.getLogger('digikey')
digikey_logger.setLevel(logging.DEBUG)

handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
digikey_logger.addHandler(handler)
```

## Top-level APIs

#### Product Information
All functions from the [PartSearch](https://developer.digikey.com/products/product-information/partsearch/) API have been implemented.
* `digikey.keyword_search()`
* `digikey.product_details()`
* `digikey.digi_reel_pricing()`
* `digikey.suggested_parts()`
* `digikey.manufacturer_product_details()`

#### Batch Product Details
The one function from the [BatchProductDetailsAPI](https://developer.digikey.com/products/batch-productdetails/batchproductdetailsapi) API has been implemented.
* `digikey.batch_product_details()`

#### Order Support
All functions from the [OrderDetails](https://developer.digikey.com/products/order-support/orderdetails/) API have been implemented.
* `digikey.salesorder_history()`
* `digikey.status_salesorder_id()`

#### Barcode
TODO

## API Limits
The API has a limited amount of requests you can make per time interval [Digikey Rate Limits](https://developer.digikey.com/documentation/shared-concepts#rate-limits).

It is possible to retrieve the number of max requests and current requests by passing an optional api_limits kwarg to an API function:
```python
api_limit = {}
search_request = KeywordSearchRequest(keywords='CRCW080510K0FKEA', record_count=10)
result = digikey.keyword_search(body=search_request, api_limits=api_limit)
```

The dict will be filled with the information returned from the API:
```python
{
    'api_requests_limit': 1000,
    'api_requests_remaining': 139
}
```
Sometimes the API does not return any rate limit data, the values will then be set to None.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/peeter123/digikey-api",
    "name": "digikey-api",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Peter Oostewechel",
    "author_email": "peter_oostewechel@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/5c/a4/3c6e1fb570b730c4c70d8bf410d5b321cf3a7b4f3d3ede3dcd8e3295f4e4/digikey_api-1.1.0.tar.gz",
    "platform": null,
    "description": "Python Client for Digikey API\r\n=================================\r\nSearch for parts in the Digi-Key catalog by keyword using KeywordSearch. Then make a PartDetails call to retrieve all\r\nreal time information about the part including pricing. PartDetails works best with Digi-Key part numbers as some\r\nmanufacturers overlap other manufacturer part numbers.\r\n\r\n[![Pypi](https://img.shields.io/pypi/v/digikey-api.svg?color=brightgreen)](https://pypi.org/project/digikey-api/)\r\n[![Donate](https://img.shields.io/badge/Donate-PayPal-gold.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=53HWHHVCJ3D4J&currency_code=EUR&source=url)\r\n\r\n# What does it do\r\n`digikey-api` is an [Digkey Part Search API](https://api-portal.digikey.com/node/8517) client for Python 3.6+. API response data is returned as Python objects that attempt to make it easy to get the data you want. Not all endpoints have been implemented.\r\n\r\n# Quickstart\r\n\r\n## Install\r\n```sh\r\npip install digikey-api\r\n\r\ncache_dir=\"path/to/cache/dir\"\r\nmkdir -p $cache_dir\r\n\r\nexport DIGIKEY_CLIENT_ID=\"client_id\"\r\nexport DIGIKEY_CLIENT_SECRET=\"client_secret\"\r\nexport DIGIKEY_STORAGE_PATH=\"${cache_dir}\"\r\n```\r\n\r\nThe cache dir is used to store the OAUTH access and refresh token, if you delete it you will need to login again.\r\n\r\n# API V3\r\n## Register\r\nRegister an app on the Digikey API portal: [Digi-Key API V3](https://developer.digikey.com/get_started). You will need\r\nthe client ID and the client secret to use the API. You will also need a Digi-Key account to authenticate, using the\r\nOauth2 process.\r\n\r\nWhen registering an app the OAuth Callback needs to be set to `https://localhost:8139/digikey_callback`.\r\n\r\n## Use [API V3]\r\nPython will automatically spawn a browser to allow you to authenticate using the Oauth2 process. After obtaining a token\r\nthe library will cache the access token and use the refresh token to automatically refresh your credentials.\r\n\r\nYou can test your application using the sandbox API, the data returned from a Sandbox API may not be complete, but the\r\nstructure of the Sandbox API response will be a representation of what to expect in Production.\r\n\r\nFor valid responses make sure you ue the client ID and secret for a [Production App](https://developer.digikey.com/documentation/organization).\r\nOtherwise, it is possible that dummy data is returned and you will pull your hair as to why it doesn't work.\r\n\r\n```python\r\nimport os\r\nfrom pathlib import Path\r\n\r\nimport digikey\r\nfrom digikey.v3.productinformation import KeywordSearchRequest\r\nfrom digikey.v3.batchproductdetails import BatchProductDetailsRequest\r\n\r\nCACHE_DIR = Path('path/to/cache/dir')\r\n\r\nos.environ['DIGIKEY_CLIENT_ID'] = 'client_id'\r\nos.environ['DIGIKEY_CLIENT_SECRET'] = 'client_secret'\r\nos.environ['DIGIKEY_CLIENT_SANDBOX'] = 'False'\r\nos.environ['DIGIKEY_STORAGE_PATH'] = CACHE_DIR\r\n\r\n# Query product number\r\ndkpn = '296-6501-1-ND'\r\npart = digikey.product_details(dkpn)\r\n\r\n# Search for parts\r\nsearch_request = KeywordSearchRequest(keywords='CRCW080510K0FKEA', record_count=10)\r\nresult = digikey.keyword_search(body=search_request)\r\n\r\n# Only if BatchProductDetails endpoint is explicitly enabled\r\n# Search for Batch of Parts/Product\r\nmpn_list = [\"0ZCK0050FF2E\", \"LR1F1K0\"] #Length upto 50\r\nbatch_request = BatchProductDetailsRequest(products=mpn_list)\r\npart_results = digikey.batch_product_details(body=batch_request)\r\n```\r\n\r\n## Logging [API V3]\r\nLogging is not forced upon the user but can be enabled according to convention:\r\n```python\r\nimport logging\r\n\r\nlogger = logging.getLogger(__name__)\r\nlogger.setLevel(logging.DEBUG)\r\n\r\ndigikey_logger = logging.getLogger('digikey')\r\ndigikey_logger.setLevel(logging.DEBUG)\r\n\r\nhandler = logging.StreamHandler()\r\nhandler.setLevel(logging.DEBUG)\r\nlogger.addHandler(handler)\r\ndigikey_logger.addHandler(handler)\r\n```\r\n\r\n## Top-level APIs\r\n\r\n#### Product Information\r\nAll functions from the [PartSearch](https://developer.digikey.com/products/product-information/partsearch/) API have been implemented.\r\n* `digikey.keyword_search()`\r\n* `digikey.product_details()`\r\n* `digikey.digi_reel_pricing()`\r\n* `digikey.suggested_parts()`\r\n* `digikey.manufacturer_product_details()`\r\n\r\n#### Batch Product Details\r\nThe one function from the [BatchProductDetailsAPI](https://developer.digikey.com/products/batch-productdetails/batchproductdetailsapi) API has been implemented.\r\n* `digikey.batch_product_details()`\r\n\r\n#### Order Support\r\nAll functions from the [OrderDetails](https://developer.digikey.com/products/order-support/orderdetails/) API have been implemented.\r\n* `digikey.salesorder_history()`\r\n* `digikey.status_salesorder_id()`\r\n\r\n#### Barcode\r\nTODO\r\n\r\n## API Limits\r\nThe API has a limited amount of requests you can make per time interval [Digikey Rate Limits](https://developer.digikey.com/documentation/shared-concepts#rate-limits).\r\n\r\nIt is possible to retrieve the number of max requests and current requests by passing an optional api_limits kwarg to an API function:\r\n```python\r\napi_limit = {}\r\nsearch_request = KeywordSearchRequest(keywords='CRCW080510K0FKEA', record_count=10)\r\nresult = digikey.keyword_search(body=search_request, api_limits=api_limit)\r\n```\r\n\r\nThe dict will be filled with the information returned from the API:\r\n```python\r\n{\r\n    'api_requests_limit': 1000,\r\n    'api_requests_remaining': 139\r\n}\r\n```\r\nSometimes the API does not return any rate limit data, the values will then be set to None.\r\n",
    "bugtrack_url": null,
    "license": "GPL v3",
    "summary": "Python client for Digikey API",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/peeter123/digikey-api"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "80caae3fed270d0bb2cb7ef156063f9d0c03485d8805d3ab3693c6a77a1a81be",
                "md5": "5c42bc7e4e483125182965061193ade1",
                "sha256": "001b450b754469cfd2dd4b7b71dd08f4fd44b0fb4b9c295f7d1d0d3532195fb0"
            },
            "downloads": -1,
            "filename": "digikey_api-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5c42bc7e4e483125182965061193ade1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 180673,
            "upload_time": "2024-11-22T09:09:47",
            "upload_time_iso_8601": "2024-11-22T09:09:47.717319Z",
            "url": "https://files.pythonhosted.org/packages/80/ca/ae3fed270d0bb2cb7ef156063f9d0c03485d8805d3ab3693c6a77a1a81be/digikey_api-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5ca43c6e1fb570b730c4c70d8bf410d5b321cf3a7b4f3d3ede3dcd8e3295f4e4",
                "md5": "60133426d5f6a067a90ec70741760f25",
                "sha256": "2615205f89320219a8d92bedf449f2572b33271aad57519d279bc37128d623a4"
            },
            "downloads": -1,
            "filename": "digikey_api-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "60133426d5f6a067a90ec70741760f25",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 114856,
            "upload_time": "2024-11-22T09:09:48",
            "upload_time_iso_8601": "2024-11-22T09:09:48.850138Z",
            "url": "https://files.pythonhosted.org/packages/5c/a4/3c6e1fb570b730c4c70d8bf410d5b321cf3a7b4f3d3ede3dcd8e3295f4e4/digikey_api-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-22 09:09:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "peeter123",
    "github_project": "digikey-api",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "requirements": [],
    "lcname": "digikey-api"
}
        
Elapsed time: 0.37951s