DigiKey Product Information V4 API Client
Project description
ff-digikey-api
DigiKey Product Information V4 API Python 클라이언트.
OAuth 2.0 인증, 토큰 자동 갱신, KRW/한국어 로케일을 지원합니다.
Quick Start
1. 설치
pip install ff-digikey-api
.env 파일 로딩이 필요하면:
pip install ff-digikey-api[dotenv]
2. DigiKey 개발자 등록
- DigiKey API Portal에서 앱 생성
- Product Information V4 API를 구독
- Callback URL을
https://localhost:8139/digikey_callback으로 설정
3. 환경변수 설정
.env 파일 생성:
DIGIKEY_CLIENT_ID=your_client_id
DIGIKEY_CLIENT_SECRET=your_client_secret
DIGIKEY_LANGUAGE=ko
DIGIKEY_CURRENCY=KRW
DIGIKEY_SITE=KR
4. 사용
from ff_digikey_api import DigiKeyClient
client = DigiKeyClient.from_env(".env")
# 최초 1회: 브라우저에서 DigiKey 로그인 (토큰은 자동 저장/갱신)
client.authorize()
# 부품 검색
result = client.search("STM32F407", limit=5)
for p in result.products:
print(p.manufacturer_product_number, p.unit_price, "KRW")
client.close()
최초
authorize()시 브라우저에 "연결이 비공개" 경고가 뜹니다. 자체 서명 인증서 때문이며, "고급 → localhost로 계속"을 클릭하면 됩니다.
초기화
직접 전달
from ff_digikey_api import DigiKeyClient, DigiKeyLocale
client = DigiKeyClient(
client_id="...",
client_secret="...",
locale=DigiKeyLocale(language="ko", currency="KRW", site="KR"),
)
환경변수
client = DigiKeyClient.from_env(".env")
Context Manager
with DigiKeyClient.from_env(".env") as client:
result = client.search("LM358")
옵션
| 파라미터 | 기본값 | 설명 |
|---|---|---|
sandbox |
False |
Sandbox API 사용 |
storage_path |
"token_storage.json" |
토큰 저장 파일 경로 |
callback_port |
8139 |
OAuth 콜백 포트 |
redirect_uri |
"https://localhost:8139/digikey_callback" |
OAuth 리디렉트 URI |
auth_timeout |
120 |
콜백 대기 타임아웃 (초) |
API Reference
authorize()
OAuth 2.0 최초 인증. 브라우저가 열리고, 로그인 후 토큰이 자동 저장됩니다. 이후 호출에서는 저장된 토큰을 사용하며, 만료 시 자동 갱신됩니다.
client.authorize()
search(keywords, limit, offset, filters, sort)
키워드로 부품을 검색합니다.
Input
| 파라미터 | 타입 | 기본값 | 설명 |
|---|---|---|---|
keywords |
str |
(필수) | 검색 키워드 |
limit |
int |
50 |
반환 개수 (최대 50) |
offset |
int |
0 |
페이지 오프셋 |
filters |
FilterOptions |
None |
필터 (제조사, 카테고리 등) |
sort |
SortOptions |
None |
정렬 옵션 |
Output — KeywordSearchResponse
| 필드 | 타입 | 설명 |
|---|---|---|
products |
list[Product] |
검색 결과 목록 |
products_count |
int |
전체 결과 수 |
exact_matches |
list[Product] |
정확히 일치하는 결과 |
filter_options |
dict |
사용 가능한 필터 옵션 |
raw_data |
dict |
API 원본 응답 |
예시
from ff_digikey_api import FilterOptions, SortOptions
# 기본 검색
result = client.search("STM32F407", limit=10)
print(f"총 {result.products_count}건")
for p in result.products:
print(f"{p.manufacturer_product_number} | {p.manufacturer.name} | {p.unit_price} KRW")
# 필터 + 정렬
result = client.search(
"capacitor 100uF",
limit=10,
filters=FilterOptions(manufacturer_ids=[13]),
sort=SortOptions(field="UnitPrice", sort_order="Ascending"),
)
product_details(product_number)
제조사 부품번호(MPN)로 상세 정보를 조회합니다.
Input
| 파라미터 | 타입 | 설명 |
|---|---|---|
product_number |
str |
제조사 부품번호 |
Output — Product
| 필드 | 타입 | 설명 |
|---|---|---|
manufacturer_product_number |
str |
MPN |
manufacturer |
Manufacturer |
제조사 (.id, .name) |
description |
str |
짧은 설명 |
detailed_description |
str |
상세 설명 |
unit_price |
float |
단가 |
product_url |
str |
DigiKey 제품 페이지 URL |
datasheet_url |
str | None |
데이터시트 URL |
photo_url |
str | None |
제품 이미지 URL |
product_status |
str |
상태 (Active, Obsolete 등) |
category |
Category | None |
카테고리 (.id, .name, .children) |
parameters |
list[Parameter] |
사양 목록 (.name, .value) |
product_variations |
list[ProductVariation] |
포장 변형 목록 |
raw_data |
dict |
API 원본 응답 |
ProductVariation 필드:
| 필드 | 타입 | 설명 |
|---|---|---|
digi_key_product_number |
str |
DigiKey 부품번호 |
package_type |
str |
포장 타입 (Cut Tape, Tape & Reel 등) |
standard_pricing |
list[PriceBreak] |
수량별 단가 |
quantity_available |
int |
재고 수량 |
min_order_quantity |
int |
최소 주문 수량 |
PriceBreak 필드: break_quantity, unit_price, total_price
예시
detail = client.product_details("STM32F407VET6TR")
print(f"{detail.manufacturer_product_number} - {detail.description}")
print(f"제조사: {detail.manufacturer.name}")
print(f"상태: {detail.product_status}")
print(f"카테고리: {detail.category.name}")
for param in detail.parameters:
print(f" {param.name}: {param.value}")
for v in detail.product_variations:
print(f" {v.digi_key_product_number} | 재고: {v.quantity_available}")
for pb in v.standard_pricing:
print(f" {pb.break_quantity}개: {pb.unit_price} KRW")
pricing(product_number)
부품의 가격 정보만 조회합니다.
Input
| 파라미터 | 타입 | 설명 |
|---|---|---|
product_number |
str |
제조사 부품번호 |
Output — ProductPricingResponse
| 필드 | 타입 | 설명 |
|---|---|---|
products |
list[Product] |
가격 정보가 포함된 제품 목록 |
products_count |
int |
결과 수 |
raw_data |
dict |
API 원본 응답 |
예시
pricing = client.pricing("STM32F407VET6TR")
for p in pricing.products:
for v in p.product_variations:
print(f"{v.digi_key_product_number} ({v.package_type})")
for pb in v.standard_pricing:
print(f" {pb.break_quantity}개: {pb.unit_price} KRW")
associations(product_number)
연관 부품 목록을 조회합니다.
Input
| 파라미터 | 타입 | 설명 |
|---|---|---|
product_number |
str |
제조사 부품번호 |
Output — list[Product]
예시
assocs = client.associations("STM32F407VET6TR")
for p in assocs:
print(f"{p.manufacturer_product_number} | {p.description}")
substitutions(product_number)
대체 가능한 부품 목록을 조회합니다.
Input
| 파라미터 | 타입 | 설명 |
|---|---|---|
product_number |
str |
제조사 부품번호 |
Output — list[Product]
예시
subs = client.substitutions("STM32F407VET6TR")
for p in subs:
print(f"{p.manufacturer_product_number} | {p.manufacturer.name}")
recommended_products(product_number)
추천 부품 목록을 조회합니다.
Input
| 파라미터 | 타입 | 설명 |
|---|---|---|
product_number |
str |
제조사 부품번호 |
Output — list[Product]
예시
recs = client.recommended_products("STM32F407VET6TR")
for p in recs:
print(f"{p.manufacturer_product_number} | {p.unit_price} KRW")
alternate_packaging(product_number)
동일 부품의 다른 포장 형태를 조회합니다.
Input
| 파라미터 | 타입 | 설명 |
|---|---|---|
product_number |
str |
제조사 부품번호 |
Output — list[Product]
예시
alts = client.alternate_packaging("STM32F407VET6TR")
for p in alts:
for v in p.product_variations:
print(f"{v.digi_key_product_number} | {v.package_type} | 재고: {v.quantity_available}")
media(product_number)
부품의 미디어 리소스(이미지, 동영상 등)를 조회합니다.
Input
| 파라미터 | 타입 | 설명 |
|---|---|---|
product_number |
str |
제조사 부품번호 |
Output — dict (API 원본 응답)
예시
media = client.media("STM32F407VET6TR")
for link in media.get("MediaLinks", []):
print(f"{link['MediaType']}: {link['Url']}")
manufacturers()
DigiKey에 등록된 전체 제조사 목록을 조회합니다.
Input — 없음
Output — list[Manufacturer]
| 필드 | 타입 | 설명 |
|---|---|---|
id |
int |
제조사 ID |
name |
str |
제조사 이름 |
예시
mfrs = client.manufacturers()
for m in mfrs[:10]:
print(f"[{m.id}] {m.name}")
categories()
전체 카테고리 트리를 조회합니다.
Input — 없음
Output — list[Category]
| 필드 | 타입 | 설명 |
|---|---|---|
id |
int |
카테고리 ID |
name |
str |
카테고리 이름 |
children |
list[Category] |
하위 카테고리 |
예시
cats = client.categories()
for c in cats[:5]:
print(f"[{c.id}] {c.name}")
for child in c.children[:3]:
print(f" └ [{child.id}] {child.name}")
에러 처리
from ff_digikey_api.Core.HttpClient.ApiError import ApiError
from ff_digikey_api.Core.HttpClient.RateLimitError import RateLimitError
from ff_digikey_api.Service.TokenManager.TokenExpiredError import TokenExpiredError
try:
result = client.search("STM32")
except RateLimitError as e:
print(f"요청 한도 초과. {e.retry_after}초 후 재시도")
except TokenExpiredError:
print("토큰 만료. client.authorize() 재실행 필요")
except ApiError as e:
print(f"API 에러 [{e.status_code}]: {e.message}")
모든 Struct에 raw_data
모든 응답 객체는 raw_data 필드에 API 원본 JSON을 보존합니다.
라이브러리가 파싱하지 않는 필드가 필요하면 raw_data에서 직접 접근할 수 있습니다.
detail = client.product_details("STM32F407VET6TR")
# 라이브러리가 파싱하지 않는 필드
print(detail.raw_data["QuantityAvailable"])
print(detail.raw_data["ManufacturerLeadWeeks"])
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ff_digikey_api-0.0.1.tar.gz.
File metadata
- Download URL: ff_digikey_api-0.0.1.tar.gz
- Upload date:
- Size: 19.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2e9d4073846607dac9de81aed56638f323675a7cbeefab2335aa67ad8cdfb68
|
|
| MD5 |
58838608d0e8e466913021a8fd28ddd8
|
|
| BLAKE2b-256 |
fd203fefedff4d250d4608afb4df31d39514a92d18f122c4ff5e16d54b99e35a
|
File details
Details for the file ff_digikey_api-0.0.1-py3-none-any.whl.
File metadata
- Download URL: ff_digikey_api-0.0.1-py3-none-any.whl
- Upload date:
- Size: 25.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e10e1787fa1f793383038521073c68fdba1ecca4d0bb2159195459bebf38979
|
|
| MD5 |
30ad8c8b51208b607c8e4a4c7ef0d8ca
|
|
| BLAKE2b-256 |
d53be0b0ed79cf39c34363848067809253a06364fcdbc0c4c00e77b20cd5fff9
|