Skip to main content

gdmongolite: lightweight, auto-maintained all-in-one MongoDB toolkit by Ganeshdatta

Project description

gdmongolite

gdmongolite: lightweight, auto-maintained all-in-one MongoDB toolkit by Ganeshdatta

Installation

pip install gdmongolite

Usage

1. Configure Your Environment

Create a .env file at your project root with your MongoDB URI and settings:

MONGO_URI="mongodb://localhost:27017"
MONGO_DB="myapp"
MONGO_MAX_POOL=50

2. Defining Your First Schema

Open src/gdmongolite/schema/__init__.py and define your schema:

from gdmongolite import DB, Schema, Email, Positive

# Bind to default DB from .env
db = DB()

class User(Schema):
    name: str
    email: Email
    age: Positive
    tags: list[str] = []

# Immediately available on DB instance
assert db.User is User

3. Running Migrations

Whenever you add, remove, or change fields in your schema, run:

poetry run gdmongolite migrate

4. Interactive Shell

Start an interactive shell to inspect and test your models:

poetry run gdmongolite shell

Then, in the REPL:

await db.User.insert({"name":"Alice","email":"a@b.com","age":28})
users = await db.User.find(age__gte=18).to_list()
print(users)

5. Generating Models from Existing Collections

To scaffold a model from a live collection:

poetry run gdmongolite gen-model --collection products --out src/models/product.py

6. Running Tests

Validate core and your extensions:

poetry run pytest --maxfail=1 --disable-warnings -q

7. Adding Telemetry Hooks

In your app top-level (e.g., app.py):

from gdmongolite.core import DBSingleton

@DBSingleton.on("pre_query")
def log_pre(collection, filt, opts):
    print(f"Querying {collection}: {filt}")

@DBSingleton.on("post_query")
def log_post(collection, result):
    print(f"{collection} query completed.")

Cookbook (Advanced Use Cases)

  • Complex Queries
  • Transactions
  • Sharded Clusters
  • Change Streams

(To be expanded)

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

gdmongolite-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gdmongolite-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file gdmongolite-0.1.0.tar.gz.

File metadata

  • Download URL: gdmongolite-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for gdmongolite-0.1.0.tar.gz
Algorithm Hash digest
SHA256 28e82005891c294b5df875178a1d480e3b4dc9fa4d0d82aa1effcc6905a7db12
MD5 ce98eee058abbfdac894cd8389368922
BLAKE2b-256 a67d0b2744512ecea0626c8d05514ba6840b4475463dc9e4b740d768528fb6c2

See more details on using hashes here.

File details

Details for the file gdmongolite-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gdmongolite-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for gdmongolite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2dac4c7f57c8ad576d9f555f1b2a7e6e5539146be70dc36f5a26addfc0617328
MD5 7bfec801cd61545937bccf4f8378f51e
BLAKE2b-256 4ad5c2357fd131baeb78ac4d48dea450fcc36392db0c11f322aa152b080b4d66

See more details on using hashes here.

Supported by

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