Metadata-Version: 2.5
Name: pgsqlite-failover
Version: 0.2.0
Summary: SQLAlchemy failover middleware: PostgreSQL primary with a durable SQLite fallback, journal and replay.
Project-URL: Homepage, https://github.com/svnviet/pgsqlite-failover
Project-URL: Issues, https://github.com/svnviet/pgsqlite-failover/issues
Author: svnviet
License: MIT License
        
        Copyright (c) 2026 svnviet
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: failover,fallback,postgresql,sqlalchemy,sqlite
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: sqlalchemy>=2.0
Provides-Extra: postgres
Requires-Dist: psycopg[binary]>=3.1; extra == 'postgres'
Provides-Extra: test
Requires-Dist: pytest>=8; extra == 'test'
Requires-Dist: testcontainers[postgres]>=4; extra == 'test'
Description-Content-Type: text/markdown

# pgsqlite-failover

SQLAlchemy middleware: PostgreSQL primary, durable SQLite fallback, transaction journal and replay.

```python
from sqlalchemy import text
from pgsqlite_failover import create_failover_engine

engine = create_failover_engine("postgresql+psycopg://user:pass@localhost/app", project_root=".")
with engine.begin() as conn:
    conn.execute(text("INSERT INTO events (name) VALUES (:name)"), {"name": "Tin360"})
```

Storage defaults to `<project_root>/.pgsqlite-failover/` (`fallback.db`, `backup.db`, `journal.db`, `logs/`);
override with `storage_dir=` or `PGSQLITE_FAILOVER_DIR`. Add the directory to `.gitignore`.

## Status (0.2.0)
SQLAlchemy Core only. Routing is per transaction; writes on the fallback are journaled and replayed in order
when the primary recovers. Known limits: the fallback schema must be provisioned separately, SQL must be
portable between PostgreSQL and SQLite, replay is at-least-once (make writes idempotent), ORM Session,
multi-process coordination and PG→SQLite bootstrap are on the roadmap (0.3–0.5).

## Testing
```bash
pip install -e ".[postgres,test]"
pytest            # integration tests start PostgreSQL with testcontainers (needs Docker)
```
Without Docker, point the suite at an existing server: `PGSQLITE_TEST_POSTGRES_URL=postgresql+psycopg://user:pw@host:5432/db pytest`
(the tests create and drop an `events` table). Outages are simulated with a local TCP proxy.
