Skip to main content

@contiguity/base

Contiguity's official Python SDK for Contiguity Base

Installation 🏗 & Setup 🛠

You can install the SDK using pip:

$ pip install contiguity_base

Then, import & initialize it like this:

from contiguity_base import connect

db = connect("your-api-key", "your-project-id")

You can get an API key by fetching it in the dashboard, and a project ID is given to you when creating a project.

Deta Logo For those moving from Deta Space Deta Logo

Contiguity Base is a one-to-one replacement for the old Deta Base API, Deta Base JavaScript SDK, Deta Base Python SDK, and Deta Base Go SDK. The only thing that has changed is initialization.

Instead of deta = Deta(project_key), you'll use db = connect(api_key, project_id)

The rest stays the same, because at Contiguity, we think it's crazy for a cloud provider to give you 45 days to move dozens of apps from their proprietary database.

If you're transitioning from Deta Space to Contiguity, welcome!

Creating your first "base" 📊

To start working with a base, you can create a Base instance:

my_base = db.Base("my-awesome-base")

Now you're ready to perform some cool database operations!

Putting data into your base 📥

To add an item to your base, use the put method:

item = {
    "name": "Contiguity",
    "is_awesome": True,
    "coolness_level": 9000
}

my_base.put(item)

You can also specify a key for your item:

my_base.put(item, "unique-key-1")

Batch putting 📦

Need to add multiple items at once? No problem! Just pass a list of items:

items = [
    {"name": "Item 1", "value": 100},
    {"name": "Item 2", "value": 200},
    {"name": "Item 3", "value": 300, "key": "some-unique-key"}
]

my_base.put(items)

Inserting data into your base 🚀

To insert an item into your base, use the insert method. This is useful when you want to ensure you're not overwriting existing data:

new_item = {
    "name": "New Product",
    "price": 49.99
}

my_base.insert(new_item, "product-1")

If an item with the same key already exists, the insert operation will fail, preventing accidental overwrites.

Getting data from your base 🔍

To retrieve an item, use the get method:

my_item = my_base.get("unique-key-1")
print(my_item["name"])  # Outputs: Contiguity

Updating data in your base 🔄

Need to update an item? Use the update method:

my_base.update({"coolness_level": 9001}, "unique-key-1")

Deleting data from your base 🗑️

To remove an item, use the delete method:

my_base.delete("unique-key-1")

Querying (fetching) your base 🕵️‍♀️

You can perform complex queries using the fetch method like so:

results = my_base.fetch({
    "is_awesome": True,
    "profile.name?contains": "John"
})

Query Operators

Equal

{
  "age": 22, 
  "name": "Sarah"
}
  • Hierarchical
{
  "user.profile.age": 22, 
  "user.profile.name": "Sarah"
}
  • Array
{
  "fav_numbers": [2, 4, 8]
}
  • Nested Object
{
  "time": { 
    "day": "Tuesday", 
    "hour": "08:00"
  }
}

Not Equal

{
  "user.profile.age?ne": 22
}

Less Than

{
  "user.profile.age?lt": 22
}

Greater Than

{
  "user.profile.age?gt": 22
}

Less Than or Equal

{
  "user.profile.age?lte": 22
}

Greater Than or Equal

{
  "user.profile.age?gte": 22
}

Prefix (String starts with)

{
  "user.id?pfx": "afdk"
}

Range

{
  "user.age?r": [22, 30]
}

Contains

  • String contains a substring
{
  "user.email?contains": "@contiguity.co"
}
  • List contains an item
{
  "user.places_lived_list?contains": "Miami"
}

Not Contains

  • String does not contain a substring
{
  "user.email?not_contains": "@contiguity.co"
}
  • List does not contain an item
{
  "user.places_lived_list?not_contains": "Miami"
}

Utility operations 🛠️

Contiguity provides some cool utility operations for updating your data:

Increment a value

my_base.update({"views": my_base.util.increment(1)}, "blog-post-1")

Decrement a value

my_base.update({"days": my_base.util.increment(-1)}, "countdown")

Append to an array

my_base.update({"tags": my_base.util.append("awesome")}, "product-1")

Prepend to an array

my_base.update({"recent_visitors": my_base.util.prepend("Alice")}, "website-stats")

Trim a string

my_base.update({"description": my_base.util.trim()}, "user-bio")

Debug mode 🐛

If you enable debug mode during initialization, the SDK will log detailed information about your requests. This can be super helpful for troubleshooting!

db = connect("your-api-key", "your-project-id", debug=True)

Error handling 🚨

The SDK won't throw errors when things don't go as planned. Instead, it will return None in most cases, like if you attempt to GET a non-existent key. However, it is always recommended to put database calls in a try/except block:

try:
    my_base.get("non-existent-key")
except Exception as error:
    print("Oops!", str(error))

Roadmap 🚦

  • Support for more complex query operations
  • Batch operations for deleting multiple items
  • "Deta Drive" support (file storage)
  • And many more exciting features!

Metadata

Release files for contiguity-base 1.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 contiguity-base 1.1.1
File Size Uploaded
contiguity_base-1.1.1.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for contiguity-base 1.1.1
File Interpreter ABI Platform
contiguity_base-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.3 kB

Release files / contiguity_base-1.1.1.tar.gz

Download URL contiguity_base-1.1.1.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
48729680e593c56e89a3946c73454ef81152e7cf7c0796da1e7cbe523f76313c
BLAKE2b-256 checksum
How to use checksums
35b8feae0bb88608dbe93782b0a502dd26ea4d077d45a9974ad7dd0d3660c1d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.1

Release files / contiguity_base-1.1.1-py3-none-any.whl

Download URL contiguity_base-1.1.1-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe1d55c067590ee7426b2c09192eed3fe3c5ac79351e88add2c3078fa4bc23b4
BLAKE2b-256 checksum
How to use checksums
9c509b975fc67b1c0d95145b75e27e70aff66421be1a988985fb034dc25a158e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.1

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

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