Skip to main content

Singlebase Python SDK

Singlebase's Python SDK

Usage

Install

pip install singlebase

Create Client

from singlebase import Client as create_client

API_URL = "https://cloud.singlebaseapis.com/api/[[ACCESS-PATH-KEY]]"
API_KEY = "[[YOUR-SECURE-API-KEY]]"

# create client
sb_client = create_client(
    api_url=API_URL, 
    api_key=API_KEY
)

Methods

Sync

  • client.dispatch(payload:dict)
  • client.db(action:str, collection:str, payload:dict={})
  • client.auth(action:str, payload:dict={})
  • client.storage(action:str, payload:dict={})
  • client.genai(action:str, payload:dict={})
  • client.vectordb(action:str, payload:dict={})

Async

  • client.dispatch_async(payload:dict)
  • client.db_async(action:str, collection:str, payload:dict={})
  • client.auth_async(action:str, payload:dict={})
  • client.storage_async(action:str, payload:dict={})
  • client.genai_async(action:str, payload:dict={})
  • client.vectordb_async(action:str, payload:dict={})

Examples

### === Datastore

# db.fetch (fetch all)
res = sbc_client.db("fetch", "articles") 

# res:Result|ResultOK|ResultError
if res.ok:
  for entry:dict in res.data: # res.data:[dict, ...]
    _key = entry.get("_key")
    title = entry.get("title")
    print(f" Article _key: {_key} - Title: {title}")

# db.fetch by _key 
res = sbc_client.db("fetch", "articles", {"_key": 1234}) 

# db.fetch by criteria. returns 5 entries
res = sbc_client.db("fetch", "articles", {
  "filter": {
    "author": "author-name",
  },
  "limit": 5
}) 


# db.insert
res = sb_client.db('insert', 'articles', {"title": "Hello", "content": "..."})

# res:Result|ResultOK|ResultError
if res.ok:
  print("Document created. _key: %s" % res.data[0].get("_key"))

# db.update
sb_client.db("update", 'articles', {"_key": "124", "summary": "something"})

# db.upsert
sb_client.db("upsert", 'articles', {
    "filter": { 
      "slug": "my-unique-slug"
    },
    "update": {
      "count:$inc": True
    },
    "insert": {
      "slug": "my-unique-slug",
      "title": "Hello",
      "content": "World"
    }
  })

# db.count
sb_client.db("count", 'articles')

# db.delete
sb_client.db("delete", 'articles', {"_key": "124"})

# db.archive
sb_client.db("archive", 'articles', {"_key": "124"})

# db.restore
sb_client.db("restore", 'articles', {"_key": "124"})

# ------------

### === Auth

# auth.signin
sb_client.auth('signin', {"email": "", "password": ""})
# all other methods follow the same pattern

# ------------

### === Storage

# storage.get
sbc_client.storage('get', {"_key": 1234})

# storage.delete
sbc_client.storage('delete', {"_key": 1234})

sbc_client.storage('convert_to_md', {"_key": 1234})

# ------------

### === GenAI

# genai.summarize
sbc_client.genai('summarize', {"input": "long-text..."})

# genai.gentext 
sbc_client.genai('gentext', {"input": "the prompt"})

# genai.qna - Knowledge Base/Q&A
sbc_client.genai('qna', {
  "collection": "articles",
  "_key": "datakey",
  "input": "the question",
})


--- 

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

singlebase-0.1.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

singlebase-0.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file singlebase-0.1.1.tar.gz.

File metadata

  • Download URL: singlebase-0.1.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for singlebase-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5ecda17f844ba6c492790d260515d073ec57899e2a348f7206038e654c2b4f7c
MD5 ebc8ce6e7bfe94c8c2c4b044fe160aa3
BLAKE2b-256 0b3333372fc9068d04db6b956f25159fe120505806f55dd8212959f534f1f080

See more details on using hashes here.

File details

Details for the file singlebase-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: singlebase-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for singlebase-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7b822b9271aa5c1545f9f8cec59012f7b5cd00bc20ea559cb61339c0403fa97f
MD5 058198e7e4aa2a510c0c5ac4e2111d5b
BLAKE2b-256 6513c4277c978a474604868d7a34e76d463f293fb71b6eb588f0a891894d4761

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

0.0.1

2 files

Supported by

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