digikey-api


Namedigikey-api JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/peeter123/digikey-api
SummaryPython client for Digikey API
upload_time2022-08-13 08:38:19
maintainer
docs_urlNone
authorPeter Oostewechel
requires_python
licenseGPL v3
keywords
VCS
bugtrack_url
requirements inflection certauth requests retrying urllib3 responses six certifi setuptools
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

export DIGIKEY_CLIENT_ID="client_id"
export DIGIKEY_CLIENT_SECRET="client_secret"
export DIGIKEY_STORAGE_PATH="cache_dir"
```

# 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 use the client ID and secret for a [Production App](https://developer.digikey.com/documentation/organization)

```python
import os
import digikey
from digikey.v3.productinformation import KeywordSearchRequest

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)
```

## 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": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Peter Oostewechel",
    "author_email": "peter_oostewechel@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/64/63/6ed79fa29d1ee35610b8d9a6d6d0d22c1e984caaa67b1753bd3fc100b4f8/digikey-api-1.0.0.tar.gz",
    "platform": null,
    "description": "Python Client for Digikey API\n=================================\nSearch for parts in the Digi-Key catalog by keyword using KeywordSearch. Then make a PartDetails call to retrieve all \nreal time information about the part including pricing. PartDetails works best with Digi-Key part numbers as some \nmanufacturers overlap other manufacturer part numbers.\n\n[![Pypi](https://img.shields.io/pypi/v/digikey-api.svg?color=brightgreen)](https://pypi.org/project/digikey-api/) \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)\n\n# What does it do\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.\n\n# Quickstart\n\n## Install\n```sh\npip install digikey-api\n\nexport DIGIKEY_CLIENT_ID=\"client_id\"\nexport DIGIKEY_CLIENT_SECRET=\"client_secret\"\nexport DIGIKEY_STORAGE_PATH=\"cache_dir\"\n```\n\n# API V3\n## Register\nRegister an app on the Digikey API portal: [Digi-Key API V3](https://developer.digikey.com/get_started). You will need \nthe client ID and the client secret to use the API. You will also need a Digi-Key account to authenticate, using the \nOauth2 process.\n\nWhen registering an app the OAuth Callback needs to be set to `https://localhost:8139/digikey_callback`.\n\n## Use [API V3]\nPython will automatically spawn a browser to allow you to authenticate using the Oauth2 process. After obtaining a token\nthe library will cache the access token and use the refresh token to automatically refresh your credentials.\n\nYou can test your application using the sandbox API, the data returned from a Sandbox API may not be complete, but the \nstructure of the Sandbox API response will be a representation of what to expect in Production.\n\nFor valid responses make sure you use the client ID and secret for a [Production App](https://developer.digikey.com/documentation/organization)\n\n```python\nimport os\nimport digikey\nfrom digikey.v3.productinformation import KeywordSearchRequest\n\nos.environ['DIGIKEY_CLIENT_ID'] = 'client_id'\nos.environ['DIGIKEY_CLIENT_SECRET'] = 'client_secret'\nos.environ['DIGIKEY_CLIENT_SANDBOX'] = 'False'\nos.environ['DIGIKEY_STORAGE_PATH'] = 'cache_dir'\n\n# Query product number\ndkpn = '296-6501-1-ND'\npart = digikey.product_details(dkpn)\n\n# Search for parts \nsearch_request = KeywordSearchRequest(keywords='CRCW080510K0FKEA', record_count=10)\nresult = digikey.keyword_search(body=search_request)\n```\n\n## Logging [API V3]\nLogging is not forced upon the user but can be enabled according to convention:\n```python\nimport logging\n\nlogger = logging.getLogger(__name__)\nlogger.setLevel(logging.DEBUG)\n\ndigikey_logger = logging.getLogger('digikey')\ndigikey_logger.setLevel(logging.DEBUG)\n\nhandler = logging.StreamHandler()\nhandler.setLevel(logging.DEBUG)\nlogger.addHandler(handler)\ndigikey_logger.addHandler(handler)\n```\n\n## Top-level APIs\n\n#### Product Information\nAll functions from the [PartSearch](https://developer.digikey.com/products/product-information/partsearch/) API have been implemented.\n* `digikey.keyword_search()`\n* `digikey.product_details()`\n* `digikey.digi_reel_pricing()`\n* `digikey.suggested_parts()`\n* `digikey.manufacturer_product_details()`\n\n#### Batch Product Details\nThe one function from the [BatchProductDetailsAPI](https://developer.digikey.com/products/batch-productdetails/batchproductdetailsapi) API has been implemented.\n* `digikey.batch_product_details()`\n\n#### Order Support\nAll functions from the [OrderDetails](https://developer.digikey.com/products/order-support/orderdetails/) API have been implemented.\n* `digikey.salesorder_history()`\n* `digikey.status_salesorder_id()`\n\n#### Barcode\nTODO\n\n## API Limits\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). \n\nIt is possible to retrieve the number of max requests and current requests by passing an optional api_limits kwarg to an API function:\n```python\napi_limit = {}\nsearch_request = KeywordSearchRequest(keywords='CRCW080510K0FKEA', record_count=10)\nresult = digikey.keyword_search(body=search_request, api_limits=api_limit)\n```\n\nThe dict will be filled with the information returned from the API:\n```python\n{ \n    'api_requests_limit': 1000, \n    'api_requests_remaining': 139\n}\n```\nSometimes the API does not return any rate limit data, the values will then be set to None.\n\n\n",
    "bugtrack_url": null,
    "license": "GPL v3",
    "summary": "Python client for Digikey API",
    "version": "1.0.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "3160c15daf4839d8c959e8fb936fc799",
                "sha256": "3e5c825aa17a61b1c79df0d3ec7162bbd298f0b655f478cd4b0534bf0a68138a"
            },
            "downloads": -1,
            "filename": "digikey_api-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3160c15daf4839d8c959e8fb936fc799",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 180068,
            "upload_time": "2022-08-13T08:38:15",
            "upload_time_iso_8601": "2022-08-13T08:38:15.797381Z",
            "url": "https://files.pythonhosted.org/packages/f5/41/8d647378e6a4e5d37368a914d42251d1206bf192498f56a7da16254fee42/digikey_api-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "36e5fe1a462fcd75d6d837aa856351e5",
                "sha256": "18bf4b7f5c69f83d1f717d3b70df68579353c40225c99ed5b9554af6f148e41b"
            },
            "downloads": -1,
            "filename": "digikey-api-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "36e5fe1a462fcd75d6d837aa856351e5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 100327,
            "upload_time": "2022-08-13T08:38:19",
            "upload_time_iso_8601": "2022-08-13T08:38:19.596818Z",
            "url": "https://files.pythonhosted.org/packages/64/63/6ed79fa29d1ee35610b8d9a6d6d0d22c1e984caaa67b1753bd3fc100b4f8/digikey-api-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-08-13 08:38:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "peeter123",
    "github_project": "digikey-api",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "requirements": [
        {
            "name": "inflection",
            "specs": []
        },
        {
            "name": "certauth",
            "specs": []
        },
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "retrying",
            "specs": []
        },
        {
            "name": "urllib3",
            "specs": []
        },
        {
            "name": "responses",
            "specs": []
        },
        {
            "name": "six",
            "specs": []
        },
        {
            "name": "certifi",
            "specs": []
        },
        {
            "name": "setuptools",
            "specs": []
        }
    ],
    "lcname": "digikey-api"
}
        
Elapsed time: 0.03612s