Origin Core Master SDK (Python port of @originaiagent/core-master-sdk)
Project description
originaiagent-core-master-sdk-python
全 Python ツール共通の origin-core マスタ参照 SDK。TS 版 @originaiagent/core-master-sdk の Python ポート (v0.1.0-alpha.1 と機能同等 / read-only 14 メソッド)。
- 設計書: core-master-sdk-python-design.md
- TS-Python 対応表: core-master-sdk-python-parity.md
- Python 要件: 3.11 以降
インストール
Private repo のため GITHUB_TOKEN を環境変数に設定した上で pip から git URL で取得する。
# 最新 alpha をインストール
pip install "git+https://${GITHUB_TOKEN}@github.com/originaiagent/origin-core.git@core-master-sdk-python-v0.1.0-alpha.1#subdirectory=packages/core-master-sdk-python"
# pandas ヘルパもまとめて
pip install "originaiagent-core-master-sdk-python[pandas] @ git+https://${GITHUB_TOKEN}@github.com/originaiagent/origin-core.git@core-master-sdk-python-v0.1.0-alpha.1#subdirectory=packages/core-master-sdk-python"
Streamlit Cloud では .streamlit/secrets.toml に GITHUB_TOKEN を置き、requirements.txt に上記 URL を 1 行追加するだけで導入できる。
環境変数
| 変数 | 必須 | 用途 |
|---|---|---|
CORE_MASTER_BASE_URL |
必須 | Core API のベース URL (例: https://your-core-api.example.com) |
CORE_MASTER_INTERNAL_API_KEY |
必須 | INTERNAL API キー。INTERNAL_API_KEY も後方互換フォールバックとして読むが、両方設定時は CORE_MASTER_* を優先し warnings.warn を出す |
使用例
1. sync で products を取得して DataFrame 表示
from core_master_sdk import create_core_master
from core_master_sdk.pandas_helpers import products_to_df
# 引数を省略すると環境変数から自動読み込み
with create_core_master() as client:
products = client.products.search("配線カバー", limit=50)
df = products_to_df(products)
print(df[["id", "product_name", "jan_code"]].head())
2. async で ASIN を一括逆引き
import asyncio
from core_master_sdk import create_async_core_master
async def map_asins() -> None:
async with create_async_core_master() as client:
result = await client.mall_identifiers.amazon_asin_map(
["B000000001", "B000000002", "B000000003"]
)
print(result) # {"B000000001": 422, "B000000002": 423, "B000000003": None}
asyncio.run(map_asins())
3. エラーハンドリング
from core_master_sdk import (
create_core_master,
CoreMasterNotFound,
CoreMasterAuthError,
)
with create_core_master() as client:
try:
product = client.products.get_by_id(999999)
except CoreMasterNotFound:
product = None # 静かに握りつぶして OK
except CoreMasterAuthError:
raise # env 設定ミスなので上位で止める
Streamlit アプリに組み込む
examples/streamlit_demo.py 参照。streamlit run examples/streamlit_demo.py で動作する。
提供リソース (14 メソッド × sync+async)
| リソース | メソッド |
|---|---|
products |
list / get_by_id / by_ids / search / get_by_logi_id |
product_groups |
list / get_by_id |
product_costs |
list_by_product_id / get_latest_by_product_id |
mall_identifiers |
list_by_product_id / lookup / lookup_bulk / amazon_asin_map |
mall_code_definitions |
list / get_by_mall_id |
malls |
list / get_by_id |
詳細は TS-Python 対応表 (parity.md) を参照。
例外階層
CoreMasterError (Exception)
├── CoreMasterAuthError (401/403, retryable=False)
├── CoreMasterNotFound (404, retryable=False)
├── CoreMasterValidationError (400/422, retryable=False)
├── CoreMasterRateLimitError (429, retryable=True)
└── CoreMasterUpstreamError (5xx/network/timeout, retryable=True)
GET は retries=2 で retry (指数バックオフ + jitter)。429 / 5xx / タイムアウト / ネットワーク断が retry 対象。
開発
cd packages/core-master-sdk-python
python3.11 -m venv .venv
.venv/bin/pip install -e '.[dev]'
.venv/bin/pytest --cov
バージョニング
0.1.0a1 (= TS 版 0.1.0-alpha.1 と同マイルストーン)。TS 版と機能マイルストーンで一致させるが、patch レベルでは独立インクリメントされることがある (設計書 §10.1)。
関連
- 設計書: docs/core-master-sdk-design.md (TS 版共通設計)
- Core API:
server/routes/masterV1.ts(13 GET エンドポイント)
License
Apache License 2.0. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
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 originaiagent_core_master_sdk_python-0.1.0a2.tar.gz.
File metadata
- Download URL: originaiagent_core_master_sdk_python-0.1.0a2.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0da6c58144ed8dad09157cb0b83f442af8dfbbc8bf11cf287e48e42059254631
|
|
| MD5 |
82621dcff05d8b07c78768dbe5e555d7
|
|
| BLAKE2b-256 |
d0cef7dc54f336f00c2b2bd5d00ad4abdac6597182ef2cee3a3127bb812e1baf
|
Provenance
The following attestation bundles were made for originaiagent_core_master_sdk_python-0.1.0a2.tar.gz:
Publisher:
publish-python-sdk.yml on originaiagent/origin-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
originaiagent_core_master_sdk_python-0.1.0a2.tar.gz -
Subject digest:
0da6c58144ed8dad09157cb0b83f442af8dfbbc8bf11cf287e48e42059254631 - Sigstore transparency entry: 1361068433
- Sigstore integration time:
-
Permalink:
originaiagent/origin-core@4472084f74c814e5517b13b84be7f722d2b93a73 -
Branch / Tag:
refs/tags/core-master-sdk-python-v0.1.0-alpha.2 - Owner: https://github.com/originaiagent
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python-sdk.yml@4472084f74c814e5517b13b84be7f722d2b93a73 -
Trigger Event:
push
-
Statement type:
File details
Details for the file originaiagent_core_master_sdk_python-0.1.0a2-py3-none-any.whl.
File metadata
- Download URL: originaiagent_core_master_sdk_python-0.1.0a2-py3-none-any.whl
- Upload date:
- Size: 34.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
722a69d5328bd59cf5c18a25c6bfb1e1bb51557cdd256116215261d95816cf17
|
|
| MD5 |
70e2c74925e3cd83c61067c38d961f64
|
|
| BLAKE2b-256 |
c9d4fff9b6b06603e24a2700c7ce95e8375baab885e7128b569338a3a3ec7b6e
|
Provenance
The following attestation bundles were made for originaiagent_core_master_sdk_python-0.1.0a2-py3-none-any.whl:
Publisher:
publish-python-sdk.yml on originaiagent/origin-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
originaiagent_core_master_sdk_python-0.1.0a2-py3-none-any.whl -
Subject digest:
722a69d5328bd59cf5c18a25c6bfb1e1bb51557cdd256116215261d95816cf17 - Sigstore transparency entry: 1361068447
- Sigstore integration time:
-
Permalink:
originaiagent/origin-core@4472084f74c814e5517b13b84be7f722d2b93a73 -
Branch / Tag:
refs/tags/core-master-sdk-python-v0.1.0-alpha.2 - Owner: https://github.com/originaiagent
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python-sdk.yml@4472084f74c814e5517b13b84be7f722d2b93a73 -
Trigger Event:
push
-
Statement type: