KenobiDB is a document-based data store abstraction built on Python’s sqlite3
, offering a simple and efficient way to manage JSON-like data. Its API is highly similar to MongoDB’s, providing familiar operations for insertion, updates, and searches—without the need for a server connection. By removing the complexity of SQL, KenobiDB delivers a secure, high-performance environment with built-in thread safety, async execution, and basic indexing while leveraging the simplicity of a document-based database. Perfect for small applications and prototypes, KenobiDB combines SQLite’s lightweight, serverless setup with the flexibility of document-based storage. Check out the website or view the project on PyPI.
- Lightweight and serverless setup using SQLite.
- MongoDB-like API for familiar operations.
- Supports key-value pair searching instead of complex SQL queries.
- Thread safety with
RLock
. - Asynchronous execution with
ThreadPoolExecutor
. - Built-in basic indexing for efficient searches.
- Super easy integration.
- Solid performance
You can install KenobiDB using pip:
pip install kenobi
Alternatively, for the latest version, copy and paste the kenobi.py
file into your working directory.
from kenobi import KenobiDB
db = KenobiDB('example.db')
db.insert({'name': 'Obi-Wan', 'color': 'blue'})
# Output: True
db.search('color', 'blue')
# Output: [{'name': 'Obi-Wan', 'color': 'blue'}]
Initialize the database with a specified file. If the file does not exist, it will be created. SQLite is used for storage, and the database ensures the necessary table and indices are created.
db = KenobiDB('example.db')
Add a single document or multiple documents to the database.
db.insert({'name': 'Obi-Wan', 'color': 'blue'})
db.insert_many([
{'name': 'Anakin', 'color': 'red'},
{'name': 'Yoda', 'color': 'green'}
])
Remove documents matching a specific key-value pair.
db.remove('name', 'Obi-Wan')
Update documents matching a specific key-value pair with new data.
db.update('name', 'Anakin', {'color': 'dark'})
Remove all documents from the database.
db.purge()
Retrieve all documents with optional pagination.
db.all(limit=10, offset=0) # With pagination
db.all() # No pagination
Retrieve documents matching a specific key-value pair with optional pagination.
db.search('color', 'blue')
Retrieve documents using regex.
db.search_pattern('color', 'b*')
Retrieve documents where a key matches any value in a list.
db.find_any('color', ['blue', 'red'])
Retrieve documents where a key matches all values in a list.
db.find_all('color', ['blue', 'red'])
KenobiDB uses RLock
for thread safety and ThreadPoolExecutor
with a maximum of 5 workers for concurrent operations.
Use the execute_async
method to run functions asynchronously.
def insert_document(db, document):
db.insert(document)
future = db.execute_async(insert_document, db, {'name': 'Luke', 'color': 'green'})
Shut down the thread pool executor.
db.close()
Contributions are welcome! To test the library:
- Clone the repository.
- Report issues as you encounter them.
- Run the unittests.
Feel free to open issues or submit pull requests on the GitHub repository.
KenobiDB is designed for small-scale applications and prototypes. While it provides excellent performance for most operations, it is not intended to replace full-fledged databases for high-scale or enterprise-level applications for that you should use MongoDB.