Skip to main content

A Python package for simplifying MongoDB operations with built-in support for TTL and CRUD functionality.

Project description

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 __expires field.
  • Indexing: Supports unique key indexing and TTL indexing for automatic cleanup of expired documents.
  • Lightweight Dependency: Built with pymongo for 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mongoapi-1.0.2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

mongoapi-1.0.2-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file mongoapi-1.0.2.tar.gz.

File metadata

  • Download URL: mongoapi-1.0.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for mongoapi-1.0.2.tar.gz
Algorithm Hash digest
SHA256 ca2c7c30ef27f6f06692e7be9116c53fee5f9a06640f1dfff852363b7cac3610
MD5 41e45e893b060ed678ce6b21bdb26403
BLAKE2b-256 40a439d35dcd98cab317710915efc7aa144b562ec4d73ef992926dc555096e13

See more details on using hashes here.

File details

Details for the file mongoapi-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: mongoapi-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for mongoapi-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d5eaebeac10b4c82a6c60564b3eed66e361da87e7c3f0bc8735be07fca2a1eb8
MD5 e636bdd0c3637d017c42d192a410a525
BLAKE2b-256 e11aec8171c0a2f39a50775c4bfe03abdede8edf08890ae4b0c5f4217b065d22

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page