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",
})


--- 

Metadata

Release files for singlebase 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for singlebase 0.1.1
File Size Uploaded
singlebase-0.1.1.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for singlebase 0.1.1
File Interpreter ABI Platform
singlebase-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / singlebase-0.1.1.tar.gz

Download URL singlebase-0.1.1.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5ecda17f844ba6c492790d260515d073ec57899e2a348f7206038e654c2b4f7c
BLAKE2b-256 checksum
How to use checksums
0b3333372fc9068d04db6b956f25159fe120505806f55dd8212959f534f1f080
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release files / singlebase-0.1.1-py3-none-any.whl

Download URL singlebase-0.1.1-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b822b9271aa5c1545f9f8cec59012f7b5cd00bc20ea559cb61339c0403fa97f
BLAKE2b-256 checksum
How to use checksums
6513c4277c978a474604868d7a34e76d463f293fb71b6eb588f0a891894d4761
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page