Skip to main content

lexigram-nosql

NoSQL document store support for the Lexigram Framework (MongoDB, DynamoDB, Firestore).


Overview

lexigram-nosql provides async document-store backends behind a clean protocol interface. It ships with a MongoDB driver (Motor-based), a fluent query builder, aggregation pipelines, the repository pattern with specifications, a migration manager, and Named DI multi-backend support. The MongoDB driver is registered through the container; DynamoDB and Firestore backends are available as direct-use classes (lexigram.nosql.backends.dynamodb, lexigram.nosql.backends.firestore).


Full documentation: docs.lexigram.dev

Install

uv add lexigram lexigram-nosql

# With MongoDB support
uv add "lexigram-nosql[mongodb]"
# With DynamoDB support
uv add "lexigram-nosql[dynamodb]"
# With Firestore support
uv add "lexigram-nosql[firestore]"

Quick Start

from lexigram import Application
from lexigram.di.module import Module, module
from lexigram.nosql import NoSQLModule
from lexigram.nosql.config import MongoDBConfig, NoSQLConfig
from lexigram.contracts.data.nosql.nosql import DocumentStoreProtocol


@module(
    imports=[
        NoSQLModule.configure(
            NoSQLConfig(
                driver="mongodb",
                mongodb=MongoDBConfig(
                    uri="mongodb://localhost:27017",
                    database="myapp",
                ),
            )
        )
    ]
)
class AppModule(Module):
    pass


async def main() -> None:
    async with Application.boot(modules=[AppModule]) as app:
        store = await app.container.resolve(DocumentStoreProtocol)
        collection = store.collection("users")

        await collection.insert_one({"name": "Alice", "age": 30})
        async for user in collection.find({"age": {"$gte": 25}}):
            print(user)


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Configuration

Zero-config usage: Call NoSQLModule.configure() with no arguments to use all defaults.

Option 1 — YAML file

# application.yaml
nosql:
  driver: "mongodb"
  mongodb:
    uri: "mongodb://localhost:27017"
    database: "myapp"
    max_pool_size: 100

Option 2 — Profiles + Environment Variables (recommended)

export LEX_NOSQL__DRIVER=mongodb
export LEX_NOSQL__MONGODB__URI=mongodb://localhost:27017
export LEX_NOSQL__MONGODB__DATABASE=myapp

Option 3 — Python

from lexigram.nosql import NoSQLModule
from lexigram.nosql.config import NoSQLConfig, MongoDBConfig

NoSQLModule.configure(
    NoSQLConfig(
        driver="mongodb",
        mongodb=MongoDBConfig(uri="mongodb://localhost:27017", database="myapp"),
    )
)

Config reference

NoSQLConfig

Field Default Env var Description
enabled true LEX_NOSQL__ENABLED Enable NoSQL support
driver "mongodb" LEX_NOSQL__DRIVER NoSQL driver ("mongodb"; only MongoDB is module-wired today — DynamoDB/Firestore backends are direct-use classes)
mongodb MongoDBConfig() MongoDB-specific connection configuration
backends [] Named backend entries for multi-backend DI registration

MongoDBConfig

Field Default Env var Description
uri "mongodb://localhost:27017" LEX_NOSQL__MONGODB__URI MongoDB connection URI
database "lexigram" LEX_NOSQL__MONGODB__DATABASE Database name
max_pool_size 100 LEX_NOSQL__MONGODB__MAX_POOL_SIZE Maximum connection pool size
min_pool_size 10 LEX_NOSQL__MONGODB__MIN_POOL_SIZE Minimum connection pool size
retry_writes true LEX_NOSQL__MONGODB__RETRY_WRITES Enable write retries
retry_reads true LEX_NOSQL__MONGODB__RETRY_READS Enable read retries
read_preference "primaryPreferred" LEX_NOSQL__MONGODB__READ_PREFERENCE Read preference mode
write_concern_w "majority" LEX_NOSQL__MONGODB__WRITE_CONCERN_W Write concern level
auth_source "admin" LEX_NOSQL__MONGODB__AUTH_SOURCE Authentication database

Module Factory Methods

Method Description
NoSQLModule.configure(config) Configure with explicit config
NoSQLModule.scope(*repositories) Scope repository classes into a feature module
NoSQLModule.stub() Minimal config for testing

Key Features

  • MongoDB backend — async Motor-based with connection pooling and retry logic
  • Query builder — type-safe fluent API for MongoDB queries and projections
  • Aggregation pipelines — composable pipeline stages for complex aggregations
  • Repositories — base DocumentRepository pattern with specification support
  • Migration manager — index creation, field operations, and collection management
  • Named DI multi-backend — multiple backends registered via Annotated[DocumentStoreProtocol, Named("analytics")]
  • Session and transaction context managersmongodb_session() and mongodb_transaction() (lexigram.nosql.backends.mongodb.session) for ACID operations

Testing

lexigram-nosql ships no in-memory backend — stub() uses the MongoDB driver, so boot requires a reachable MongoDB. Point it at a test instance:

from lexigram.nosql.config import MongoDBConfig, NoSQLConfig

config = NoSQLConfig(
    driver="mongodb",
    mongodb=MongoDBConfig(uri="mongodb://localhost:27017", database="testdb"),
)

async with Application.boot(modules=[NoSQLModule.stub(config)]) as app:
    store = await app.container.resolve(DocumentStoreProtocol)
    collection = store.collection("users")
    await collection.insert_one({"name": "Alice"})  # requires a live test MongoDB

Key Source Files

File What it contains
src/lexigram/nosql/module.py NoSQLModule.configure(), .scope(), .stub()
src/lexigram/nosql/config.py NoSQLConfig, MongoDBConfig, NamedNoSQLConfig
src/lexigram/nosql/di/provider.py NoSQLProvider boot and registration
src/lexigram/nosql/backends/mongodb/backend.py MongoDBDocumentStore implementation
src/lexigram/nosql/query/builder.py DocumentQueryBuilder
src/lexigram/nosql/query/pipeline.py AggregationPipeline
src/lexigram/nosql/repository/base.py DocumentRepository base class
src/lexigram/nosql/migration/manager.py MigrationManager

Download files

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

Source Distribution

lexigram_nosql-0.1.5001.tar.gz (85.1 kB view details)

Uploaded Source

Built Distribution

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

lexigram_nosql-0.1.5001-py3-none-any.whl (60.5 kB view details)

Uploaded Python 3

File details

Details for the file lexigram_nosql-0.1.5001.tar.gz.

File metadata

  • Download URL: lexigram_nosql-0.1.5001.tar.gz
  • Upload date:
  • Size: 85.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for lexigram_nosql-0.1.5001.tar.gz
Algorithm Hash digest
SHA256 0587e8c33ef7546898079050e7176dac2a01c5b5ea2b5218e147b1dc66d8723b
MD5 4e2fddf72619f6c124dcf35eea3bf1f4
BLAKE2b-256 fb794286f9d306abe712f70bcb7681ed97f0c3beca4305912ad3f79b4b8f9586

See more details on using hashes here.

File details

Details for the file lexigram_nosql-0.1.5001-py3-none-any.whl.

File metadata

File hashes

Hashes for lexigram_nosql-0.1.5001-py3-none-any.whl
Algorithm Hash digest
SHA256 826fcfb785dc83160da345819cfecd9143031a5ab02bb3de0e71d7addc7ed977
MD5 90e5cfc8955055876df7a07e94f23742
BLAKE2b-256 b05c6505b1cbe0e5d3b023fb2f4ca7f966df731f5e96f9abd7861879b67c6849

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.5009

1 file

0.1.5006

2 files

This release

0.1.5001 This release

2 files

0.1.3007

1 file

0.1.3006

1 file

0.1.3005

1 file

0.1.4

2 files

0.1.2

1 file

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page