FlexDB is a flexible, free-to-use database service that allows for instant and seamless integration through its REST API. This library, python-flexdb
, provides an easy-to-use Python wrapper around the FlexDB REST API.
To start using FlexDB in your project, simply run the following command:
pip install python-flexdb
First, let's import the FlexDB
class from the flexdb
package:
from python-flexdb import FlexDB
Now, create a new instance of the FlexDB
class.
flexdb = FlexDB()
You can pass an optional configuration dictionary containing your API key and the API endpoint:
flexdb = FlexDB({'api_key': 'your_api_key'})
A store is like a container for your data. To create a new store, call the create_store
method with a unique name:
store = await flexdb.create_store('my-store')
To fetch an existing store by its name (when using an API key), use the get_store
method:
store = await flexdb.get_store('my-store')
If you want to make sure a store exists before performing any operations, use the ensure_store_exists
method. It will return the existing store or create a new one if it doesn't exist:
store = await flexdb.ensure_store_exists('my-store')
A collection is a group of related documents within a store. To create a new collection, call the collection
method on a store instance:
collection = store.collection('my-collection')
Note: no collection will be created until you add a document to it.
To add a new document to a collection, use the create
method and pass an object containing the data you want to store:
document = await collection.create({'key': 'value'})
To fetch a document by its ID, use the get
method:
document = await collection.get('document_id')
To update an existing document, call the update
method with the document ID and an object containing the updated data:
updated_document = await collection.update('document_id', {'key': 'new_value'})
To remove a document from a collection, use the delete
method and pass the document ID:
await collection.delete('document_id')
To fetch multiple documents from a collection, use the get_many
method. You can pass an options dictionary to control pagination and the number of documents to fetch:
documents = await collection.get_many({'page': 1, 'limit': 10})
To remove an entire collection and all its documents, call the delete_collection
method:
await collection.delete_collection()
To delete a store and all its collections, use the delete
method on a store instance:
await store.delete()
This project is licensed under the GPL-3.0 License - see the [[[LICENSE.md```(LICENSE.md) file for details.