Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/florents-tselai/babar
πβ€οΈπ Turn any Python object into a Postgres extension
https://github.com/florents-tselai/babar
postgres postgres-extension postgresql python
Last synced: 5 days ago
JSON representation
πβ€οΈπ Turn any Python object into a Postgres extension
- Host: GitHub
- URL: https://github.com/florents-tselai/babar
- Owner: Florents-Tselai
- License: apache-2.0
- Created: 2023-11-14T18:55:59.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-08-06T16:55:58.000Z (3 months ago)
- Last Synced: 2024-09-19T13:21:30.292Z (about 2 months ago)
- Topics: postgres, postgres-extension, postgresql, python
- Language: Python
- Homepage: https://babar.tselai.com
- Size: 1.94 MB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Babarπβ€οΈπ
Turn any Python object into a Postgres extension
Status |
Why |
How |
Installation |
Usage |
Roadmap
## Status
WARNING: This is a work in progress and is far from doing what it promises.
But not that far... π## Why
Postgres has supported Python as a procedural language for years
via [PL/Python](https://www.postgresql.org/docs/current/plpython.html).Embedding non-trivial Python code in Postgres can get cumbersome and usually
involves copy-pasting from existing code bases and/or creating thin wrappers around existing functions.**babar** automates this process by allowing you to seamlessly package existing Python components (functions, classes etc.)
int a postgres extension.## How
**babar** dynamically inspects the definition of Python objects
and generates semantically equivalent Postgres definitions
along with the necessary extension files (`.control`, `Makefile`, `.sql`)## Installation
## Usage
```bash
pip install pybabar
```Let's create a Postgres extension called [`pystring`](babar/examples/pystring.py)
which adds a few Python functions.```python
from babar import Extensiondef pyconcat(x: str, y: str) -> str:
return x + ydef pyupper(x: str) -> str:
return x.upper()if __name__ == "__main__":
Extension(
"pystring",
pyconcat, pyupper,
comment="this is the pystring extension",
default_version="0.1.0",
)
```Then, from the command line, you can run:
```bash
python pystring.py
```That will create the appropriate extension files,
which you can then install in the usual Postgres way:
```bash
make
make install
```Then you can `CREATE` the extension and use it
```bash
psql -d postgres <