Skip to main content

enebularのクラウド実行環境上で動作するアプリケーションを開発するためのSDKです。

Project description

enebular-sdk

enebularのクラウド実行環境上で動作するアプリケーションを開発するためのSDKです。 本SDKを利用することにより、enebularのデータストアを利用するアプリケーションを開発できます。

対応環境

  • 実行環境: enebularのクラウド実行環境
  • ランタイム: Python 3.13

インストール

pip install enebular-sdk

クイックスタート

from enebular_sdk import CloudDataStoreClient
import time
import json

datastore = CloudDataStoreClient()

def handler(event, context):
    # データの保存
    datastore.put_item({
        'table_id': 'bec32e12-655b-480b-88a8-6ba7d515aea5',
        'item': {
            'deviceId': 'device-001',
            'timestamp': int(time.time() * 1000),
            'temperature': 25.5
        }
    })

    result = datastore.query({
        'table_id': 'bec32e12-655b-480b-88a8-6ba7d515aea5',
        'expression': '#deviceId = :deviceId',
        'values': {'deviceId': 'device-001'},
        'order': False,  # False = descending
        'limit': 10
    })

    return {
        'statusCode': 200,
        'body': json.dumps(result.get('params', {}).get('Items'))
    }

操作対象のテーブルはテーブルIDで指定します。テーブルIDは以下の手順で取得できます。

  1. enebularにログインする
  2. 左側のメニューからデータストアを選択する
  3. アクセスしたいテーブルを選択する
  4. 設定タブを開く
  5. テーブルIDが表示されるので右側のコピーアイコンをクリックしコピーする

機能

データストア

enebularのデータストアのテーブルに対してデータの読み書き削除等の操作を行います。 主な操作の種類は以下の通りです。

  • CloudDataStoreClient - データストア操作のインスタンス作成
  • get_item - データの取得
  • put_item - データの保存
  • delete_item - データの削除
  • query - データのクエリ

あらかじめenebularで、操作対象のテーブルを作成しておく必要があります。

以下に使い方を示します。

データストア操作のインスタンス作成

from enebular_sdk import CloudDataStoreClient

datastore = CloudDataStoreClient()

以降の使用例ではこのdatastoreインスタンスを利用して、データストアの操作を行います。

データの取得

result = datastore.get_item({
    'table_id': 'bec32e12-655b-480b-88a8-6ba7d515aea5',
    'key': {'deviceId': 'device-001', 'timestamp': 1234567890}
})

if result['result'] == 'success':
    print(result.get('params', {}).get('Item'))

get_itemの戻り値の形式:

{
    "result": "success" | "fail",  # 成功(success)/失敗(fail)を表します
    "error": str,                  # 失敗の場合、エラーメッセージを保持します
    "params": {"Item": any}        # 成功した場合、Itemに取得したデータを保持します
}

データの保存

datastore.put_item({
    'table_id': 'bec32e12-655b-480b-88a8-6ba7d515aea5',
    'item': {
        'deviceId': 'device-001',
        'timestamp': int(time.time() * 1000),
        'temperature': 25.5,
        'humidity': 60
    }
})

put_itemの戻り値の形式:

{
    "result": "success" | "fail",  # 成功(success)/失敗(fail)を表します
    "params": {"Item": any},       # 成功した場合、Itemに登録したデータを保持します
    "error": str                   # 失敗の場合、エラーメッセージを保持します
}

データの削除

datastore.delete_item({
    'table_id': 'bec32e12-655b-480b-88a8-6ba7d515aea5',
    'key': {'deviceId': 'device-001', 'timestamp': 1234567890}
})

delete_itemの戻り値の形式:

{
    "result": "success" | "fail",  # 成功(success)/失敗(fail)を表します
    "error": str,                  # 失敗の場合、エラーメッセージを保持します
    "params": {"Item": any}        # 成功した場合、Itemに削除したデータを保持します
}

データの検索

import time

result = datastore.query({
    'table_id': 'bec32e12-655b-480b-88a8-6ba7d515aea5',
    'expression': '#deviceId = :deviceId and #timestamp > :timestamp',
    'values': {
        'deviceId': 'device-001',
        'timestamp': int(time.time() * 1000) - 86400000  # 過去24時間
    },
    'order': True,  # True=昇順, False=降順
    'limit': 100  # limitを設定しない場合は10とする
})

queryの戻り値の形式:

{
    "result": "success" | "fail",  # 成功(success)/失敗(fail)を表します
    "error": str,                  # 失敗の場合、エラーメッセージを保持します
    "params": {
        "Items": [any],            # 成功した場合、Itemに取得したデータを保持します
        "LastEvaluatedKey": str,   # 今回取得したデータの続きのデータを取得するキーを保持します*1
        "Count": int               # 取得したデータ数を保持します
    }
}

*1: LastEvaluatedKeyの値をquery実行時のパラメーターにstart_keyとして追加することで続きを取得できます

ロガー

ログを出力します。 出力したログは、enebularのクラウド実行環境画面で閲覧できます。

以下に使い方を示します。

from enebular_sdk import Logger

logger = Logger("MyContext")

logger.error("エラーメッセージ", error)
logger.warn("警告メッセージ", data)
logger.info("情報メッセージ", data)
logger.debug("デバッグメッセージ", data)

ログの出力例:

[Dec 19th 2025, 13:00:50]:  2025-12-19T04:00:50.491Z	adfff29c-658d-4c44-9530-9a33298950b6	ERROR	2025-12-19T04:00:50.491Z [enebular-sdk] [ERROR] [MyContext] エラーメッセージ

出力対象のログは環境変数 LOG_LEVEL で設定できます。

  • ERROR: error関数のログのみ出力します
  • WARN: error、warn関数のログを出力します
  • INFO: error、warn、info関数のログを出力します
  • DEBUG: error、warn、info、debug関数のログを出力します
  • TRACE: error、warn、info、debug、trace関数のログを出力します

環境変数は、enebularのクラウド実行環境画面で設定できます。

型ヒントサポート

このSDKは型ヒントを提供しています。IDEでの自動補完やタイプチェックが利用できます。

enebularへのデプロイ

作成したプログラムをenebularのクラウド実行環境にデプロイして実行します。 デプロイする方法については、enebularのチュートリアルをご参照ください。

ライセンス

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

enebular_sdk-1.0.1.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

enebular_sdk-1.0.1-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file enebular_sdk-1.0.1.tar.gz.

File metadata

  • Download URL: enebular_sdk-1.0.1.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for enebular_sdk-1.0.1.tar.gz
Algorithm Hash digest
SHA256 0b867e08a5a440952b4d3766b4d9b5f17c81ee5a5393d8a7f7d67a7bbbd1e206
MD5 930f537d9c4d95effca24c71caf1092b
BLAKE2b-256 ae16756f7b81838aaeb78d01003d34dc898fb8b53678f09e3f42e52175de52cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for enebular_sdk-1.0.1.tar.gz:

Publisher: python-publish.yml on Uhuru-Corporation/enebular-sdk

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

File details

Details for the file enebular_sdk-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: enebular_sdk-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for enebular_sdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 773fc1cd3c19f386bde8eb505ee17b0ac3f675460190a6fb3ee8c9b2904b87b8
MD5 049a817695bb2863701fbfd22eaeeb35
BLAKE2b-256 92e49388d71b59fc42124b46a66e37da08cb93dc555ec3b501b90df415ed425e

See more details on using hashes here.

Provenance

The following attestation bundles were made for enebular_sdk-1.0.1-py3-none-any.whl:

Publisher: python-publish.yml on Uhuru-Corporation/enebular-sdk

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