|
1 | 1 | """ |
| 2 | +[](https://freeimage.host/i/Klv1Zcx) |
| 3 | +
|
2 | 4 | TinyPG: Ephemeral PostgreSQL databases for Python development and testing. |
3 | 5 |
|
4 | | -Based on ephemeralpg by Eric Radman, reimplemented in pure Python. |
| 6 | +TinyPG provides a clean Python API for creating temporary PostgreSQL databases for development and testing. It's designed to be self-contained and work without requiring system-wide PostgreSQL installation. |
| 7 | +
|
| 8 | +## Features |
| 9 | +
|
| 10 | +- **Pure Python**: Takes care of downloading portable postgresql binaries for you |
| 11 | +- **Fast startup**: Fast database initialization |
| 12 | +- **Development-focused**: Perfect for writing python integrations tests against postgres without having to configure it in your environment |
| 13 | +- **Good dev UX**: Context managers and pytest fixtures & works seamlessly with your existing code (SQLAlchemy, async ...) |
| 14 | +- **(Optional) Supports compiling postgres from sources**: if you're not comfortable pulling prebuilt binaries from the internet |
| 15 | +
|
| 16 | +## Installation |
| 17 | +
|
| 18 | +You can install TinyPG from PyPI using your preferred Python packaging tool: |
| 19 | +
|
| 20 | +```bash |
| 21 | +# Using pip |
| 22 | +pip install tinypg |
| 23 | +
|
| 24 | +# Using uv |
| 25 | +uv pip install tinypg |
| 26 | +``` |
| 27 | +
|
| 28 | +The package provides optional extras for asynchronous drivers and development |
| 29 | +tooling. For example, to install the async dependencies with uv: |
| 30 | +
|
| 31 | +```bash |
| 32 | +uv pip install "tinypg[async]" |
| 33 | +``` |
| 34 | +
|
| 35 | +## Quick Start |
| 36 | +
|
| 37 | +```python |
| 38 | +import tinypg |
| 39 | +
|
| 40 | +# Simple usage with context manager |
| 41 | +with tinypg.database() as db_uri: |
| 42 | + import psycopg2 |
| 43 | + conn = psycopg2.connect(db_uri) |
| 44 | + # Use database... |
| 45 | +# Database automatically cleaned up |
| 46 | +
|
| 47 | +# Advanced usage |
| 48 | +db = tinypg.EphemeralDB(port=5433, cleanup_timeout=300) |
| 49 | +uri = db.start() |
| 50 | +try: |
| 51 | + # Use database... |
| 52 | + pass |
| 53 | +finally: |
| 54 | + db.stop() |
| 55 | +``` |
| 56 | +
|
| 57 | +## Requirements |
| 58 | +
|
| 59 | +- Python 3.8+ |
| 60 | +- PostgreSQL source compilation tools (if binaries need to be built) |
| 61 | +
|
| 62 | +## Github repository |
| 63 | +
|
| 64 | +TinyPG's github repository is available there: |
| 65 | +[Github repository](https://github.com/kketch/tinypg) |
| 66 | +
|
5 | 67 | """ |
6 | 68 |
|
7 | 69 | from .config import TinyPGConfig |
|
0 commit comments