Name | contiguity-base JSON |
Version |
1.1.1
JSON |
| download |
home_page | None |
Summary | The official Python SDK for Contiguity Base |
upload_time | 2024-10-01 15:20:00 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT License Copyright (c) 2024 Contiguity Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
python
contiguity
deta
base
database
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<p align='center'><img src="https://contiguity.co/assets/icon-black.png" height="150px"/></p>
<h1 align='center'>@contiguity/base</h1>
<p align='center'>
<img display="inline-block" src="https://img.shields.io/pypi/v/contiguity_base?style=for-the-badge" /> <img display="inline-block" src="https://img.shields.io/badge/Made%20with-Python-green?style=for-the-badge" />
</p>
<p align='center'>Contiguity's official Python SDK for Contiguity Base</p>
## Installation 🏗 & Setup 🛠
You can install the SDK using pip:
```shell
$ pip install contiguity_base
```
Then, import & initialize it like this:
```python
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](https://base.contiguity.co), and a project ID is given to you when creating a project.
## <img src="https://avatars.githubusercontent.com/u/47275976?s=280&v=4" alt="Deta Logo" style="vertical-align: middle;" height="30"> For those moving from Deta Space <img src="https://avatars.githubusercontent.com/u/47275976?s=280&v=4" alt="Deta Logo" style="vertical-align: middle;" height="30">
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:
```python
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:
```python
item = {
"name": "Contiguity",
"is_awesome": True,
"coolness_level": 9000
}
my_base.put(item)
```
You can also specify a key for your item:
```python
my_base.put(item, "unique-key-1")
```
## Batch putting 📦
Need to add multiple items at once? No problem! Just pass a list of items:
```python
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:
```python
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:
```python
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:
```python
my_base.update({"coolness_level": 9001}, "unique-key-1")
```
## Deleting data from your base 🗑️
To remove an item, use the `delete` method:
```python
my_base.delete("unique-key-1")
```
## Querying (fetching) your base 🕵️♀️
You can perform complex queries using the `fetch` method like so:
```python
results = my_base.fetch({
"is_awesome": True,
"profile.name?contains": "John"
})
```
### Query Operators
#### Equal
```python
{
"age": 22,
"name": "Sarah"
}
```
- **Hierarchical**
```python
{
"user.profile.age": 22,
"user.profile.name": "Sarah"
}
```
- **Array**
```python
{
"fav_numbers": [2, 4, 8]
}
```
- **Nested Object**
```python
{
"time": {
"day": "Tuesday",
"hour": "08:00"
}
}
```
#### Not Equal
```python
{
"user.profile.age?ne": 22
}
```
#### Less Than
```python
{
"user.profile.age?lt": 22
}
```
#### Greater Than
```python
{
"user.profile.age?gt": 22
}
```
#### Less Than or Equal
```python
{
"user.profile.age?lte": 22
}
```
#### Greater Than or Equal
```python
{
"user.profile.age?gte": 22
}
```
#### Prefix (String starts with)
```python
{
"user.id?pfx": "afdk"
}
```
#### Range
```python
{
"user.age?r": [22, 30]
}
```
#### Contains
- **String contains a substring**
```python
{
"user.email?contains": "@contiguity.co"
}
```
- **List contains an item**
```python
{
"user.places_lived_list?contains": "Miami"
}
```
#### Not Contains
- **String does not contain a substring**
```python
{
"user.email?not_contains": "@contiguity.co"
}
```
- **List does not contain an item**
```python
{
"user.places_lived_list?not_contains": "Miami"
}
```
## Utility operations 🛠️
Contiguity provides some cool utility operations for updating your data:
### Increment a value
```python
my_base.update({"views": my_base.util.increment(1)}, "blog-post-1")
```
### Decrement a value
```python
my_base.update({"days": my_base.util.increment(-1)}, "countdown")
```
### Append to an array
```python
my_base.update({"tags": my_base.util.append("awesome")}, "product-1")
```
### Prepend to an array
```python
my_base.update({"recent_visitors": my_base.util.prepend("Alice")}, "website-stats")
```
### Trim a string
```python
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!
```python
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:
```python
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!
Raw data
{
"_id": null,
"home_page": null,
"name": "contiguity-base",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "python, contiguity, deta, base, database",
"author": null,
"author_email": "Contiguity <help@contiguity.support>",
"download_url": "https://files.pythonhosted.org/packages/35/b8/feae0bb88608dbe93782b0a502dd26ea4d077d45a9974ad7dd0d3660c1d4/contiguity_base-1.1.1.tar.gz",
"platform": null,
"description": "<p align='center'><img src=\"https://contiguity.co/assets/icon-black.png\" height=\"150px\"/></p>\n<h1 align='center'>@contiguity/base</h1>\n\n<p align='center'>\n <img display=\"inline-block\" src=\"https://img.shields.io/pypi/v/contiguity_base?style=for-the-badge\" /> <img display=\"inline-block\" src=\"https://img.shields.io/badge/Made%20with-Python-green?style=for-the-badge\" />\n</p>\n<p align='center'>Contiguity's official Python SDK for Contiguity Base</p>\n\n## Installation \ud83c\udfd7 & Setup \ud83d\udee0\nYou can install the SDK using pip:\n```shell\n$ pip install contiguity_base\n```\n\nThen, import & initialize it like this:\n\n```python\nfrom contiguity_base import connect\n\ndb = connect(\"your-api-key\", \"your-project-id\")\n```\n\nYou can get an API key by fetching it in the [dashboard](https://base.contiguity.co), and a project ID is given to you when creating a project.\n\n## <img src=\"https://avatars.githubusercontent.com/u/47275976?s=280&v=4\" alt=\"Deta Logo\" style=\"vertical-align: middle;\" height=\"30\"> For those moving from Deta Space <img src=\"https://avatars.githubusercontent.com/u/47275976?s=280&v=4\" alt=\"Deta Logo\" style=\"vertical-align: middle;\" height=\"30\">\nContiguity 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. \n\nInstead of `deta = Deta(project_key)`, you'll use `db = connect(api_key, project_id)`\n\nThe 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.\n\nIf you're transitioning from Deta Space to Contiguity, welcome! \n\n## Creating your first \"base\" \ud83d\udcca\n\nTo start working with a base, you can create a Base instance:\n\n```python\nmy_base = db.Base(\"my-awesome-base\")\n```\n\nNow you're ready to perform some cool database operations!\n\n## Putting data into your base \ud83d\udce5\n\nTo add an item to your base, use the `put` method:\n\n```python\nitem = {\n \"name\": \"Contiguity\",\n \"is_awesome\": True,\n \"coolness_level\": 9000\n}\n\nmy_base.put(item)\n```\n\nYou can also specify a key for your item:\n\n```python\nmy_base.put(item, \"unique-key-1\")\n```\n\n## Batch putting \ud83d\udce6\nNeed to add multiple items at once? No problem! Just pass a list of items:\n\n```python\nitems = [\n {\"name\": \"Item 1\", \"value\": 100},\n {\"name\": \"Item 2\", \"value\": 200},\n {\"name\": \"Item 3\", \"value\": 300, \"key\": \"some-unique-key\"}\n]\n\nmy_base.put(items)\n```\n\n## Inserting data into your base \ud83d\ude80\nTo insert an item into your base, use the insert method. This is useful when you want to ensure you're not overwriting existing data:\n```python\nnew_item = {\n \"name\": \"New Product\",\n \"price\": 49.99\n}\n\nmy_base.insert(new_item, \"product-1\")\n```\n\nIf an item with the same key already exists, the insert operation will fail, preventing accidental overwrites.\n\n## Getting data from your base \ud83d\udd0d\n\nTo retrieve an item, use the `get` method:\n\n```python\nmy_item = my_base.get(\"unique-key-1\")\nprint(my_item[\"name\"]) # Outputs: Contiguity\n```\n\n## Updating data in your base \ud83d\udd04\n\nNeed to update an item? Use the `update` method:\n\n```python\nmy_base.update({\"coolness_level\": 9001}, \"unique-key-1\")\n```\n\n## Deleting data from your base \ud83d\uddd1\ufe0f\n\nTo remove an item, use the `delete` method:\n\n```python\nmy_base.delete(\"unique-key-1\")\n```\n\n## Querying (fetching) your base \ud83d\udd75\ufe0f\u200d\u2640\ufe0f\n\nYou can perform complex queries using the `fetch` method like so:\n\n```python\nresults = my_base.fetch({\n \"is_awesome\": True,\n \"profile.name?contains\": \"John\"\n})\n```\n\n### Query Operators\n\n#### Equal\n\n```python\n{\n \"age\": 22, \n \"name\": \"Sarah\"\n}\n```\n\n- **Hierarchical** \n```python\n{\n \"user.profile.age\": 22, \n \"user.profile.name\": \"Sarah\"\n}\n```\n\n- **Array** \n```python\n{\n \"fav_numbers\": [2, 4, 8]\n}\n```\n\n- **Nested Object** \n```python\n{\n \"time\": { \n \"day\": \"Tuesday\", \n \"hour\": \"08:00\"\n }\n}\n```\n\n#### Not Equal\n\n```python\n{\n \"user.profile.age?ne\": 22\n}\n```\n\n#### Less Than\n\n```python\n{\n \"user.profile.age?lt\": 22\n}\n```\n\n#### Greater Than\n\n```python\n{\n \"user.profile.age?gt\": 22\n}\n```\n\n#### Less Than or Equal\n\n```python\n{\n \"user.profile.age?lte\": 22\n}\n```\n\n#### Greater Than or Equal\n\n```python\n{\n \"user.profile.age?gte\": 22\n}\n```\n\n#### Prefix (String starts with)\n\n```python\n{\n \"user.id?pfx\": \"afdk\"\n}\n```\n\n#### Range\n\n```python\n{\n \"user.age?r\": [22, 30]\n}\n```\n\n#### Contains\n\n- **String contains a substring** \n```python\n{\n \"user.email?contains\": \"@contiguity.co\"\n}\n```\n\n- **List contains an item** \n```python\n{\n \"user.places_lived_list?contains\": \"Miami\"\n}\n```\n\n#### Not Contains\n\n- **String does not contain a substring** \n```python\n{\n \"user.email?not_contains\": \"@contiguity.co\"\n}\n```\n\n- **List does not contain an item** \n```python\n{\n \"user.places_lived_list?not_contains\": \"Miami\"\n}\n```\n\n## Utility operations \ud83d\udee0\ufe0f\n\nContiguity provides some cool utility operations for updating your data:\n\n### Increment a value\n```python\nmy_base.update({\"views\": my_base.util.increment(1)}, \"blog-post-1\")\n```\n\n### Decrement a value\n```python\nmy_base.update({\"days\": my_base.util.increment(-1)}, \"countdown\")\n```\n\n### Append to an array\n```python\nmy_base.update({\"tags\": my_base.util.append(\"awesome\")}, \"product-1\")\n```\n\n### Prepend to an array\n```python\nmy_base.update({\"recent_visitors\": my_base.util.prepend(\"Alice\")}, \"website-stats\")\n```\n\n### Trim a string\n```python\nmy_base.update({\"description\": my_base.util.trim()}, \"user-bio\")\n```\n\n## Debug mode \ud83d\udc1b\n\nIf you enable debug mode during initialization, the SDK will log detailed information about your requests. This can be super helpful for troubleshooting!\n```python\ndb = connect(\"your-api-key\", \"your-project-id\", debug=True)\n```\n\n## Error handling \ud83d\udea8\n\nThe 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:\n\n```python\ntry:\n my_base.get(\"non-existent-key\")\nexcept Exception as error:\n print(\"Oops!\", str(error))\n```\n\n## Roadmap \ud83d\udea6\n- Support for more complex query operations\n- Batch operations for deleting multiple items\n- \"Deta Drive\" support (file storage)\n- And many more exciting features!\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Contiguity Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "The official Python SDK for Contiguity Base",
"version": "1.1.1",
"project_urls": {
"Repository": "https://github.com/contiguity/base-python"
},
"split_keywords": [
"python",
" contiguity",
" deta",
" base",
" database"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9c509b975fc67b1c0d95145b75e27e70aff66421be1a988985fb034dc25a158e",
"md5": "697c01e1c1c42875544b38915da7475c",
"sha256": "fe1d55c067590ee7426b2c09192eed3fe3c5ac79351e88add2c3078fa4bc23b4"
},
"downloads": -1,
"filename": "contiguity_base-1.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "697c01e1c1c42875544b38915da7475c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 7598,
"upload_time": "2024-10-01T15:19:59",
"upload_time_iso_8601": "2024-10-01T15:19:59.338424Z",
"url": "https://files.pythonhosted.org/packages/9c/50/9b975fc67b1c0d95145b75e27e70aff66421be1a988985fb034dc25a158e/contiguity_base-1.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "35b8feae0bb88608dbe93782b0a502dd26ea4d077d45a9974ad7dd0d3660c1d4",
"md5": "1d4339febb5579ab61d355d8fea72fc8",
"sha256": "48729680e593c56e89a3946c73454ef81152e7cf7c0796da1e7cbe523f76313c"
},
"downloads": -1,
"filename": "contiguity_base-1.1.1.tar.gz",
"has_sig": false,
"md5_digest": "1d4339febb5579ab61d355d8fea72fc8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 7752,
"upload_time": "2024-10-01T15:20:00",
"upload_time_iso_8601": "2024-10-01T15:20:00.373783Z",
"url": "https://files.pythonhosted.org/packages/35/b8/feae0bb88608dbe93782b0a502dd26ea4d077d45a9974ad7dd0d3660c1d4/contiguity_base-1.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-01 15:20:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "contiguity",
"github_project": "base-python",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "contiguity-base"
}