TinyMongo can use remote transactional SQL databases for storage while keeping the Mongo-like collection API. These backends use one server-side SQL table per TinyMongo database and collection, plus a small metadata table for listing databases and collections.
Supported backend names:
postgresorpostgresqlmysqlormariadb
Install the optional driver dependencies for the backend you use:
pip install "tinymongo[postgres]"
pip install "tinymongo[mysql]"
pip install "tinymongo[mariadb]"
pip install "tinymongo[remote-sql]"If a required driver is missing, TinyMongo raises an ImportError that includes
the exact pip install ... command to run.
from tinymongo import TinyMongoClient
client = TinyMongoClient(
backend="postgres",
dsn="postgresql://user:password@localhost:5432/tinymongo",
)
client.app.users.insert_one({"_id": "ada", "name": "Ada"})The DSN can also come from an environment variable:
export TINYMONGO_POSTGRES_DSN=postgresql://user:password@localhost:5432/tinymongoFallback env vars:
TINYMONGO_POSTGRESQL_DSNDATABASE_URL
PostgreSQL stores document payloads in a JSONB column.
from tinymongo import TinyMongoClient
client = TinyMongoClient(
backend="mariadb",
dsn="mysql://user:password@localhost:3306/tinymongo",
)
client.app.users.insert_one({"_id": "ada", "name": "Ada"})The DSN can also come from an environment variable:
export TINYMONGO_MYSQL_DSN=mysql://user:password@localhost:3306/tinymongoFallback env vars:
TINYMONGO_MARIADB_DSNMYSQL_URLMARIADB_URL
MariaDB/MySQL stores document payloads in a JSON column.
tinymongo inspect ./unused --backend postgres --dsn "$TINYMONGO_POSTGRES_DSN"
tinymongo export ./unused app users \
--backend postgres \
--dsn "$TINYMONGO_POSTGRES_DSN" \
-o users.json
tinymongo migrate ./tinydb ./unused \
--to-backend postgres \
--target-dsn "$TINYMONGO_POSTGRES_DSN"The path argument is ignored for remote SQL backends, but it is still present
to keep CLI commands consistent across all backends.
Remote SQL backends create tables named with this pattern:
<tinydb_database>__<collection>
For example:
app__users
app__events
Each table has:
_id: string primary keydata: JSON/JSONB document payload
TinyMongo also creates __tinymongo_collections to track database and
collection names.
The first remote SQL implementation prioritizes correct TinyMongo behavior and
transactional remote storage. _id lookups use the SQL primary key. Other
Mongo-style filters currently read collection documents and apply TinyMongo's
Python matcher, matching the behavior used as a fallback by the local table
backends.
Future improvements can push more JSON predicates into PostgreSQL JSONB and MariaDB/MySQL JSON SQL.
Remote SQL tests are opt-in:
TINYMONGO_POSTGRES_DSN=postgresql://user:password@localhost:5432/tinymongo \
pytest -m integration tests/integration/test_remote_sql.py
TINYMONGO_MYSQL_DSN=mysql://user:password@localhost:3306/tinymongo \
pytest -m integration tests/integration/test_remote_sql.py