Skip to main content

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 メソッド)。

インストール

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.tomlGITHUB_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)。

関連

License

Apache License 2.0. See LICENSE for details.

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

originaiagent_core_master_sdk_python-0.1.0a2.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file originaiagent_core_master_sdk_python-0.1.0a2.tar.gz.

File metadata

File hashes

Hashes for originaiagent_core_master_sdk_python-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 0da6c58144ed8dad09157cb0b83f442af8dfbbc8bf11cf287e48e42059254631
MD5 82621dcff05d8b07c78768dbe5e555d7
BLAKE2b-256 d0cef7dc54f336f00c2b2bd5d00ad4abdac6597182ef2cee3a3127bb812e1baf

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file originaiagent_core_master_sdk_python-0.1.0a2-py3-none-any.whl.

File metadata

File hashes

Hashes for originaiagent_core_master_sdk_python-0.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 722a69d5328bd59cf5c18a25c6bfb1e1bb51557cdd256116215261d95816cf17
MD5 70e2c74925e3cd83c61067c38d961f64
BLAKE2b-256 c9d4fff9b6b06603e24a2700c7ce95e8375baab885e7128b569338a3a3ec7b6e

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page