wmongo
wmongo is a library for python control of MongoDB databases.
Description
wmongo simplifies the use of MongoDB databases in Python. It provides a simple interface to the MongoDB database, allowing you to easily insert, update, and delete data.
Installation
To install the library, use pip:
pip install wmongo
Description
The wmongo library offers a number of general-purpose modules.
License
MIT
This project is licensed under the MIT License. See the LICENSE file for details.
Examples
This directory contains a collection of examples that demonstrate the usage of various modules and functionalities in this project. Each subfolder corresponds to a specific module and includes example scripts to help you understand how to use that module.
Directory Structure
The examples are organized as follows:
examples/
wmongo_async/
crud.py
notification_receiver.py
wmongo/
crud.py
delete_and_notify.py
insert_and_notify.py
notifaction_receiver.py
update_and_notify.py
How to Use
- Navigate to the module folder of interest, e.g.,
examples/module1/. - Open the
README.mdin that folder to get detailed information about the examples. - Run the scripts directly using:
python example1.py
Modules and Examples
wmongo
Description
This module demonstrates specific functionalities.
- crud.py: Example demonstrating functionality.
from typing import List
from wmongo import WMongo
from pydantic import BaseModel
# Credentials stored in a dictionary for easy reuse
mongo_credentials = {
"uri": "mongodb://localhost:27017",
"username": "root",
"password": "example",
}
redis_credentials = {
"redis_host": "localhost",
"redis_port": 6379,
"redis_db": 0,
}
credentials = {
**mongo_credentials,
**redis_credentials,
}
# Pydantic model for user data validation
class UserModel(BaseModel):
name: str
age: int
# Insert a user synchronously
user_data = UserModel(name="Bob", age=25).dict()
with WMongo(database="mydb", verbose=False, **credentials) as wm:
if wm.has_permission(user_id="123", collection="users"):
wm.insert("users", {"name": "Alice", "age": 30})
else:
print("Access Denied")
# Insert a user synchronously with Redis caching
with WMongo(database="mydb", verbose=False, **credentials) as wm:
wm.update("users", {"name": "Bob"}, {"age": 26})
# Read, update, and delete operations within the context manager
with WMongo(database="mydb", verbose=False, **credentials) as wm:
# Delete user
wm.delete("users", {"name": "Bob"})
# Pydantic model for user data validation
class UserRole(BaseModel):
user_id: str
role: int
collections: List[str]
- delete_and_notify.py: Example demonstrating functionality.
from wmongo import WMongo
from pydantic import BaseModel
# Credentials stored in a dictionary for easy reuse
mongo_credentials = {
"username": "root",
"password": "example",
}
redis_credentials = {
"redis_host": "localhost",
"redis_port": 6379,
"redis_db": 0,
}
notifications = {
"enable_notifications": True,
}
credentials = {
**mongo_credentials,
**redis_credentials,
**notifications,
}
# Pydantic model for user data validation
class UserModel(BaseModel):
name: str
age: int
# Insert a user synchronously
user_data = UserModel(name="Bob", age=25).dict()
with WMongo(database="mydb", verbose=True, **credentials) as wm:
if wm.has_permission(user_id="123", collection="users"):
wm.delete("users", {"name": "Alice"})
else:
print("Access Denied")
- insert_and_notify.py: Example demonstrating functionality.
from wmongo import WMongo
from pydantic import BaseModel
# Credentials stored in a dictionary for easy reuse
mongo_credentials = {
"username": "root",
"password": "example",
}
redis_credentials = {
"redis_host": "localhost",
"redis_port": 6379,
"redis_db": 0,
}
notifications = {
"enable_notifications": True,
}
credentials = {
**mongo_credentials,
**redis_credentials,
**notifications,
}
# Pydantic model for user data validation
class UserModel(BaseModel):
name: str
age: int
# Insert a user synchronously
user_data = UserModel(name="Bob", age=25).dict()
with WMongo(database="mydb", verbose=False, **credentials) as wm:
if wm.has_permission(user_id="123", collection="users"):
wm.insert("users", {"name": "Alice", "age": 30})
else:
print("Access Denied")
- notifaction_receiver.py: Example demonstrating functionality.
from wmongo import WMongo
# Credentials stored in a dictionary for easy reuse
mongo_credentials = {
"username": "root",
"password": "example",
}
redis_credentials = {
"redis_host": "localhost",
"redis_port": 6379,
"redis_db": 0,
}
def my_notification_callback(message: str):
print(f"📩 Notification Received: {message}")
notifications = {
"enable_notification_receiver": True,
"notification_callback": my_notification_callback,
}
credentials = {
**mongo_credentials,
**redis_credentials,
**notifications,
}
# Este script solo escuchará notificaciones
with WMongo(
database="mydb",
verbose=False,
**credentials,
) as wm:
print("Listening for notifications...")
wm.listen_notifications()
- update_and_notify.py: Example demonstrating functionality.
from wmongo import WMongo
from pydantic import BaseModel
# Credentials stored in a dictionary for easy reuse
mongo_credentials = {
"username": "root",
"password": "example",
}
redis_credentials = {
"redis_host": "localhost",
"redis_port": 6379,
"redis_db": 0,
}
notifications = {
"enable_notifications": True,
}
credentials = {
**mongo_credentials,
**redis_credentials,
**notifications,
}
# Pydantic model for user data validation
class UserModel(BaseModel):
name: str
age: int
# Insert a user synchronously
user_data = UserModel(name="Bob", age=25).dict()
with WMongo(database="mydb", verbose=True, **credentials) as wm:
if wm.has_permission(user_id="123", collection="users"):
wm.update("users", {"name": "Alice"}, {"age": 31})
else:
print("Access Denied")
wmongo_async
Description
This module demonstrates specific functionalities.
- crud.py: Example demonstrating functionality.
from wmongo import WMongoAsync
import asyncio
# Credentials stored in a dictionary for easy reuse
mongo_credentials = {
"username": "root",
"password": "example",
}
redis_credentials = {
"redis_host": "localhost",
"redis_port": 6379,
"redis_db": 0,
}
notifications = {
"enable_notifications": True,
}
credentials = {
**mongo_credentials,
**redis_credentials,
**notifications,
}
async def insert_example():
async with WMongoAsync(database="mydb", verbose=False, **credentials) as wm:
doc_id = await wm.insert("users", {"name": "Alice", "age": 30})
print(f"Inserted document with ID: {doc_id}")
asyncio.run(insert_example())
async def find_example():
async with WMongoAsync(database="mydb", verbose=False, **credentials) as wm:
users = await wm.find("users", {"age": {"$gte": 20}}) # Usuarios con edad >= 20
print(f"Users found: {users}")
asyncio.run(find_example())
async def update_example():
async with WMongoAsync(database="mydb", verbose=False, **credentials) as wm:
updated_count = await wm.update("users", {"name": "Alice"}, {"age": 35})
print(f"Updated {updated_count} documents.")
asyncio.run(update_example())
async def delete_example():
async with WMongoAsync(database="mydb", verbose=False, **credentials) as wm:
deleted_count = await wm.delete("users", {"name": "Alice"})
print(f"Deleted {deleted_count} documents.")
asyncio.run(delete_example())
- notification_receiver.py: Example demonstrating functionality.
from wmongo import WMongoAsync
import asyncio
# Credentials stored in a dictionary for easy reuse
mongo_credentials = {
"username": "root",
"password": "example",
}
redis_credentials = {
"redis_host": "localhost",
"redis_port": 6379,
"redis_db": 0,
}
def my_notification_callback(message: str):
print(f"📩 Notification Received: {message}")
notifications = {
"enable_notification_receiver": True,
"notification_callback": my_notification_callback,
}
credentials = {
**mongo_credentials,
**redis_credentials,
**notifications,
}
async def listen_for_notifications():
async with WMongoAsync(database="mydb", verbose=False, **credentials) as wm:
print("Listening for notifications...")
wm.listen_notifications()
asyncio.run(listen_for_notifications())
Metadata
Release files for wmongo 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| wmongo-0.1.1.tar.gz | 16.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wmongo-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.7 kB
Release files / wmongo-0.1.1.tar.gz
| Download URL | wmongo-0.1.1.tar.gz |
|---|---|
| Size | 16.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3377ba431314422e95cd1f8dcbfb80fae39cfd36e6d04071efa5363ffa904c43
|
|
BLAKE2b-256 checksum How to use checksums |
a3760f55b18c47dc6f1baf37c25b64254694486f914d0535652d52edb9e9e146
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / wmongo-0.1.1-py3-none-any.whl
| Download URL | wmongo-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
13dfc665aeb53a327c69760fa4c11154f643c1bb725b9427e0e1a830200670d6
|
|
BLAKE2b-256 checksum How to use checksums |
187396e24dbe5db9d481502581a5973c180566ad5797013a6ee3632f499e610d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for wmongo 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.