Skip to main content

Python utilities for interacting with ShorthandAI data

Project description

shorthandai

This package provides a Python SDK for working with the ShorthandAI platform.

Installation

$ pip install shorthandai

Usage

from shorthandai import ShorthandAI

# Token can be passed by setting the environment variable `SHORTHANDAI_TOKEN`.
# token can be generated at https://apiv1.shorthand.ai/console/tokens
SH = ShorthandAI()

# Alternately, pass in the token explicitly
token = 'sh-...' 
SH = ShorthandAI(token)

# Get values
print(SH.get("dev123"))

# Set values
print(SH.set("dev123", 4000))

import datetime
# Get historical
print(SH.geth("dev123", datetime.datetime(2022, 12, 31)))

For example, new users can try out the following:

from shorthandai import ShorthandAI

SH = ShorthandAI('demo')
print(SH.info())
print(SH.GET('dev123', '1659994710026'))
print(SH.GET('dev123', 'notexists'))
print(SH.GET('dev123'))
print(SH.GET('dev444'))

print("\nTesting GET-historical\n")
import datetime
print(SH.GETH('dev123', datetime.datetime(2022, 12, 31)))
print(SH.GETH('dev123', datetime.datetime(2022, 11, 1)))
print(SH.GETH('dev123', datetime.datetime(2023, 2, 24)))

print("\nTesting SET\n")
print(SH.SET('dev555-scalar', 1000))
print(SH.GET('dev555-scalar'))

new_df = pd.DataFrame({
    'Name': ['Tom', 'nick', 'krish', 'jack'],
    'Age': [20, 21, 19, 18]
})
print(new_df)
print(SH.SET('dev777-pd', new_df))
print(SH.GET('dev777-pd'))


geth_many_res = list(SH.GETMANY([
    { "topic_name": "dev123", "asOf": datetime.datetime(2024, 4, 18, 15, 0, 0) },
    { "topic_name": 'dev123', "asOf": datetime.datetime(2022, 12, 31)   },
    { "topic_name": 'dev123', "asOf": datetime.datetime(2022, 11, 1)    },
    { "topic_name": 'dev123', "asOf": datetime.datetime(2023, 2, 24)    }
]))

print(geth_many_res)

# Loading large number of topics
import time
start_ts = time.time()

get_many_res = list(SH.GETMANY([
    {
        "topic_name": "dev123",
        "tag": '1659994710026'
    },
    {
        "topic_name": "dev444",
        "tag": '1659994710026'
    },
    {
        "topic_name": "dev444",
    },
    {
        "topic_name": "dev444",
        "tag": 'latest'
    },
    {
        "topic_name": "dev777-pd",
    },
    {
        "topic_name": "dev555-scalar",
        "tag": 'latest'
    }
] * 100))

end_ts = time.time()
elapsed = end_ts - start_ts
print([ str(type(d)) for d in get_many_res ])
print(f'getmany for {len(get_many_res)} topics in {elapsed}s')
# getmany for 600 topics in 7.065880060195923s

print("\nTesting SET_MANY\n")

new_df = pd.DataFrame({
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Score': [95, 87, 92]
})

set_many_res = SH.set_many([
    {
        "topic_name": "dev101",
        "value": 301
    },
    {
        "topic_name": "dev102",
        "tag": "easy",
        "value": 101
    },
    {
        "topic_name": "dev103-pd",
        "value": new_df
    }
])
print("Set many response:", set_many_res)

# Verify the values were set
get_many_res = list(SH.GETMANY([
    {"topic_name": "dev101", "tag": "latest"},
    {"topic_name": "dev102", "tag": "easy"},
    {"topic_name": "dev103-pd"}
]))

print("Verification get:", get_many_res)

get_res = SH.GET("dev103-pd")
print("Verification get dev103-pd:", get_res)

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

shorthandai-0.0.10.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

shorthandai-0.0.10-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file shorthandai-0.0.10.tar.gz.

File metadata

  • Download URL: shorthandai-0.0.10.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.6

File hashes

Hashes for shorthandai-0.0.10.tar.gz
Algorithm Hash digest
SHA256 bbf232c2bfc2bee30e04ce3b0d7d90f48ca3a98f89296e45f65116fc3c3a65b4
MD5 b1050bd2e72bd3d9db5a2927e467d080
BLAKE2b-256 ce11bb74fd365445373164bc720a9b4db06aa9e780d0db184f506ac1f07d3d76

See more details on using hashes here.

File details

Details for the file shorthandai-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: shorthandai-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.6

File hashes

Hashes for shorthandai-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 1bdad550308ae3105a360f55aa3849e16586b37e6a62e5d033ac92c4213fe9d8
MD5 a30fd563ede1809cf2034fed27f51d28
BLAKE2b-256 b5bd991cce536b101d37d3df6b90a640e6e3ebafbf41c4b7e176d4a761e6cac6

See more details on using hashes here.

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