8000 GitHub - shakefu/humbledb: HumbleDB - MongoDB Python Object-Document Mapper built on pymongo
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

HumbleDB - MongoDB Python Object-Document Mapper built on pymongo

License

Notifications You must be signed in to change notification settings

shakefu/humbledb

Repository files navigation

HumbleDB - MongoDB Object-Document Mapper

HumbleDB solves the age-old MongoDB dilemma: write readable, maintainable code or optimize for storage efficiency. With HumbleDB, you get both. This lightweight ODM lets you use clear, descriptive attribute names in your Python code while automatically mapping them to ultra-short database keys, dramatically reducing document size and memory usage without sacrificing code clarity.

CI Coverage Status GitHub Sponsors

Warning

Version 7.0.0 Breaking Changes. This release updates to Pymongo 4.x, which introduces breaking changes. While we've maintained all older 3.x and 2.x Pymongo methods with identical signatures where possible, there may be other breaking changes not covered by our test suite. If you encounter any issues during upgrade, please open an issue.

Features

Efficient Storage: Map readable attribute names to ultra-short database keys, reducing document size and memory usage while maintaining code clarity.

Full Pymongo Compatibility: Maintains backwards-compatible methods for Pymongo 4.x including insert, find_and_modify, save, and other familiar operations.

Maximum Flexibility: Documents are also dictionaries - no schema restrictions, maximum adaptability to changing requirements.

Thread & Greenlet Safe: Built for concurrent applications with safe connection handling and resource management.

Context-Managed Connections: Connection paradigm minimizes socket usage from the connection pool through explicit context managers.

Lightweight Design: T 9CF2 hin wrapper around Pymongo that exposes the full power of the underlying driver without performance overhead.

Quick Start

Define Your Document Schema

Create a Document subclass with readable attribute names mapped to short database keys:

from humbledb import Mongo, Document

class TestDoc(Document):
    config_database = 'test'      # Target database
    config_collection = 'testdoc' # Target collection
    test_key = 't'               # Maps 'test_key' attribute to 't' in MongoDB
    other_key = 'o'              # Maps 'other_key' attribute to 'o' in MongoDB

Create and Populate Documents

Documents work like regular Python objects with attribute access, while storing data efficiently:

doc = TestDoc()
doc.test_key = 'Hello'
doc.other_key = 'World'

# View the actual MongoDB document structure
print(doc)
# TestDoc({'t': 'Hello', 'o': 'World'})

Flexible Data Access

Access your data through mapped attributes or direct dictionary keys:

# Via mapped attributes (recommended)
print(doc.test_key)    # 'Hello'

# Via dictionary access
print(doc['t'])        # 'Hello'
print(doc['o'])        # 'World'

Database Operations

Use the Mongo context manager for safe database operations:

# Insert document
with Mongo:
    TestDoc.insert(doc)

# Query documents
with Mongo:
    found = TestDoc.find_one()

print(found)
# TestDoc({'_id': ObjectId('50ad81586112797f89b99606'), 't': 'Hello', 'o': 'World'})

See the documentation for more examples and detailed explanations.

Documentation

The complete documentation can be found on http://humbledb.readthedocs.org.

License

See LICENSE.rst.

Contributors

About

HumbleDB - MongoDB Python Object-Document Mapper built on pymongo

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •  
0