Endless Database with pyyaml and pymongo
Project description
EndlessDB
EndlessDB is a small Python wrapper around MongoDB that lets an application work with databases, collections, and documents as dynamic Python objects.
The goal is to keep the natural MongoDB shape while making day-to-day access feel direct:
from src.endlessdb import EndlessConfiguration, EndlessDatabase
class LocalConfiguration(EndlessConfiguration):
def override(self):
self.CONFIG_YML = "tests/config.yml"
self.MONGO_URI = "mongodb://root:root@localhost:27017/"
self.MONGO_DATABASE = "tests-endlessdb"
LocalConfiguration.apply()
edb = EndlessDatabase()
employees = edb.Employee
employees["john"] = {"Name": "John", "Age": 25}
john = employees["john"]
john.Age = 26
print(john.Name)
print(john().to_dict())
What It Provides
- Dynamic database, collection, and document wrappers:
EndlessDatabase,EndlessCollection, andEndlessDocument. - Attribute and index access for collections and nested document properties.
- Mongo-backed writes for collection items and document fields.
- Lazy/virtual documents for paths that do not exist yet.
- Document references stored as MongoDB DBRef-compatible data.
- JSON and YAML export helpers.
- YAML-based defaults and configuration override hooks.
- Direct access to the underlying PyMongo database and collection objects when the wrapper should not hide MongoDB.
Object Model
EndlessDB has two layers for each public object:
- The public wrapper (
EndlessDatabase,EndlessCollection,EndlessDocument) is what application code touches. - The logic container returned by calling the wrapper (
edb(),collection(),document()) exposes metadata and lower-level operations.
Common examples:
edb = EndlessDatabase()
collection = edb.Employee
collection_logic = collection()
document = collection["john"]
document_logic = document()
print(collection_logic.key())
print(document_logic.path(True))
print(document_logic.mongo())
This split keeps everyday code compact while still making the internal path, parent, Mongo object, serialization, and reload/delete operations available when needed.
Configuration
Configuration is controlled through EndlessConfiguration. A project can override the default MongoDB connection, database name, config collection, and YAML defaults file by subclassing EndlessConfiguration and calling apply() before creating EndlessDatabase.
class AppConfiguration(EndlessConfiguration):
def override(self):
self.CONFIG_YML = "config.yml"
self.CONFIG_COLLECTION = "config"
self.MONGO_URI = "mongodb://root:root@localhost:27017/"
self.MONGO_DATABASE = "app"
AppConfiguration.apply()
edb = EndlessDatabase()
The test suite uses this mechanism to point EndlessDB at the integration database in tests/docker-compose.yml.
Reading And Writing
Collections can be reached through attribute or item access:
employees = edb.Employee
same_collection = edb["Employee"]
Documents are addressed by MongoDB _id:
employees["john"] = {"Name": "John", "Age": 25}
john = employees["john"]
Document fields can be read and written as Python attributes or nested item paths:
john.Age = 26
john["Profile.City"] = "New York"
assert john.Age == 26
assert john.Profile.City == "New York"
When a document is already loaded, external MongoDB changes are visible after reloading the document logic:
john().reload()
References
Assigning an EndlessDocument to another document stores a reference-like value in MongoDB and resolves it back to an EndlessDocument on reload.
departments = edb.Department
departments["it"] = {"Name": "IT"}
john.Department = departments["it"]
assert john.Department == departments["it"]
Serialization
Each logic container can export to dictionaries, JSON, or YAML.
data = john().to_dict()
json_text = john().to_json()
yaml_text = employees().to_yml()
Bytes are base64 encoded for JSON, and date/datetime values are encoded with ISO format.
Debugger Visualization
EndlessDB is intentionally friendly in the VS Code debugger. Public wrappers and logic containers implement __str__ and __repr__ so the debugger watch window shows useful state instead of anonymous Python objects.
The visual representation is compact but information dense:
- Database, collection, and document objects each show their kind.
- Paths are composed from database, collection, document id, and nested property names.
- Length counters show how many collections, documents, or fields are visible at that point.
- Virtual documents are marked so it is clear when a path exists only in Python until it is written.
- Protected/read-only and open/writeable states are shown directly in the representation.
- Debug mode adds an extra marker, making debug-enabled objects easy to spot while stepping through code.
That means expressions such as edb, edb.Employee, edb.Employee["john"], and edb.Employee["john"].Profile reveal their identity, path, size, and state directly in the debugger without extra logging.
Samples
The samples folder contains runnable examples for the main EndlessDB workflows:
- quickstart collection/document writes;
- nested dot-path updates;
- document references;
- JSON, base64 JSON, and YAML serialization;
- YAML defaults loading;
- debugger-friendly representations.
Start MongoDB and run any sample from the repository root:
docker compose -f samples/docker-compose.yml up -d
.\.venv\Scripts\python.exe samples\01_quickstart.py
Development Setup
EndlessDB currently targets Python 3.13+.
Create or refresh the local virtual environment from the repository root:
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install --upgrade pip
.\.venv\Scripts\python.exe -m pip install -r requirements-dev.txt
Start the integration MongoDB instance:
docker compose -f tests/docker-compose.yml up -d
Run the tests:
.\.venv\Scripts\python.exe -m pytest tests
The test suite contains focused pytest tests for configuration overrides, Mongo-backed writes, nested paths, document references, YAML collections, serialization, protected mode, and debugger-friendly representations. See .github/project-plan.md for the active backlog.
To prepare a release interactively, use the release assistant. It asks before each stage, can increment pyproject.toml by major/minor/patch/dev/rc/custom version, checks that the selected version is not already published, builds the package, validates it with Twine, and then asks whether to upload to TestPyPI, public PyPI, both, or neither:
.\scripts\release.ps1
Release Notes
Publishing is intentionally manual. Before uploading to TestPyPI or PyPI, the version in pyproject.toml must change and must not already exist on the target package index. Build and validate the distribution locally, publish to TestPyPI first, verify installation, and only then publish the same built artifacts to public PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file endlessdb-0.4.16.tar.gz.
File metadata
- Download URL: endlessdb-0.4.16.tar.gz
- Upload date:
- Size: 23.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2695915ad329a8da42d68dd2dcc16d81312ea85755f49d5a164aa5fef4e2666
|
|
| MD5 |
a888bede5a5b88eaf43961a9d979928d
|
|
| BLAKE2b-256 |
2a52a2435e7789c42f4950165f19ff57712374c87528bc3bfb8dcc8de6aa8eb8
|
File details
Details for the file endlessdb-0.4.16-py3-none-any.whl.
File metadata
- Download URL: endlessdb-0.4.16-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb29d1ca7511cf1a39aeaffa093d60f53765e7236b08c077601e36784677fc77
|
|
| MD5 |
ddd1ce78dbdcd5a3d1638fb0e94e0042
|
|
| BLAKE2b-256 |
003bc64223c8eca5460dde6ee0c803c97881a2260caf5e885a890d3306de0dff
|