MongoAPI
MongoAPI is a Python package designed to simplify MongoDB operations. This tool provides an intuitive interface for interacting with MongoDB collections, including features like CRUD operations, TTL (Time-To-Live) indexing, and automatic expiration handling.
Installation
To install MongoAPI, use pip:
pip install mongoapi
or install directly from the GitHub repository:
pip install git+https://github.com/rekcah-pavi/mongoapi
Features
- CRUD Operations: Easily perform Create, Read, Update, and Delete actions on MongoDB documents.
- Expiration Handling: Automatically manage document expiration with the
__expiresfield. - Indexing: Supports unique key indexing and TTL indexing for automatic cleanup of expired documents.
- Lightweight Dependency: Built with
pymongofor efficient database interaction.
Usage
Initialize the API
from mongoapi import mongoapi,mongodb_url
url = mongodb_url("username","pass","dbname","host") #port=27017
# Initialize the MongoAPI
api = mongoapi(url,"mydb")
Insert or Update a Document
# Insert or update a document
import time
ex = time.time()+60 #expires in 60 seconds
api.put({"key": "item1", "value": "data", "__expires": ex}) # __expires is an optional expiry timestamp
#insert many at once
api.put([{"key": https://pypi.org/project/mongoapi/
### Retrieve a Document
```python
# Retrieve by key
item = api.get("item1")
print(item)
Update Specific Fields
# Update specific fields by key
api.patch("item1", {"value": "updated_data"})
Delete a Document
# Delete a document by key
api.delete("item1")
Retrieve All Documents
# Retrieve all non-expired documents
all_items = api.get_all()
print(all_items)
Delete All Documents
# Delete all documents in the collection
api.delete_all()
License
This package is licensed under the MIT License. See the LICENSE file for details.
Author
Developed by Paviththanan (rkpavi06@gmail.com).
GitHub Repository: MongoAPI
Metadata
Release files for mongoapi 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mongoapi-1.0.2.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mongoapi-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.6 kB
Release files / mongoapi-1.0.2.tar.gz
| Download URL | mongoapi-1.0.2.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ca2c7c30ef27f6f06692e7be9116c53fee5f9a06640f1dfff852363b7cac3610
|
|
BLAKE2b-256 checksum How to use checksums |
40a439d35dcd98cab317710915efc7aa144b562ec4d73ef992926dc555096e13
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.10
|
Release files / mongoapi-1.0.2-py3-none-any.whl
| Download URL | mongoapi-1.0.2-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d5eaebeac10b4c82a6c60564b3eed66e361da87e7c3f0bc8735be07fca2a1eb8
|
|
BLAKE2b-256 checksum How to use checksums |
e11aec8171c0a2f39a50775c4bfe03abdede8edf08890ae4b0c5f4217b065d22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.10
|