Simple-MongoDB
Warning: This Python package is currently still in development phase
Description
Placeholder
Installation
pip install simple-mongodb
Simple Example
import asyncio
from typing import Any
from bson import ObjectId
from pydantic import BaseModel
from simple_mongodb import BaseCollection, MongoDBClient
class AccountCollection(BaseCollection):
db = 'my-db' # The name of the database or set the enviroment variable MONGODB_DB
collection = 'account-collection' # The name of the collection
class Account(BaseModel):
name: str
async def main() -> None:
# Initialize a client object and pass the url or set enviroment variables
# MONGODB_HOST, MONGODB_PORT,
# MONGODB_USERNAME, MONGODB_PASSWORD
# Is the url param or enviroment variables not set the default values are used
client: MongoDBClient = MongoDBClient(url='mongodb://user:pass@host:27017')
# Initialize the account collection
account_collection: AccountCollection = AccountCollection(client=client)
account: Account = Account(name='example-name')
try:
# Insert the document in the collection
document: dict[str, Any] = account.model_dump()
inserted_id: ObjectId = await account_collection.insert_one(document=document)
# Find the document
where: dict[str, Any] = {'_id': inserted_id}
document: dict[str, Any] = await account_collection.find_one(where=where)
# Update the document
update: dict[str, Any] = {'$set': {'name': 'other-name'}}
# Returns the id of the new document if upsert=True
await account_collection.update_one(where=where, update=update, upsert=False)
except account_collection.InsertError:
pass
except account_collection.FindError:
pass
except account_collection.UpdateError:
pass
except account_collection.ServerTimeoutError:
pass
# Close the db connection
client.close()
if __name__ == '__main__':
asyncio.run(main())
Metadata
Release files for simple-mongodb 0.9.0
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 | |
|---|---|---|---|---|
| simple_mongodb-0.9.0.tar.gz | 11.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| simple_mongodb-0.9.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.5 kB
Release files / simple_mongodb-0.9.0.tar.gz
| Download URL | simple_mongodb-0.9.0.tar.gz |
|---|---|
| Size | 11.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4533e9687583ddbff884a64b4812535fa15017fb76eba73b2dabbc50ec16c90d
|
|
BLAKE2b-256 checksum How to use checksums |
83196772a21a6981590fd012d547caf655c1e42479117a4197fe58a153bfbfbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Release files / simple_mongodb-0.9.0-py3-none-any.whl
| Download URL | simple_mongodb-0.9.0-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
58e97bf728085c3fb69ca5f53b37c88d3e75247c69cf2e9c20523be4a633fd97
|
|
BLAKE2b-256 checksum How to use checksums |
d383d195c65c331b0e51de45ad2928ca915c83026347e536567cf3e0222c3ea4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Security for simple-mongodb 0.9.0
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.