{"id":18060509,"url":"https://github.com/florents-tselai/babar","last_synced_at":"2025-04-11T12:13:16.780Z","repository":{"id":207229620,"uuid":"718766182","full_name":"Florents-Tselai/babar","owner":"Florents-Tselai","description":"🐘❤️🐍 Turn any Python object into a Postgres extension","archived":false,"fork":false,"pushed_at":"2024-10-14T16:14:31.000Z","size":2035,"stargazers_count":3,"open_issues_count":22,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T08:38:19.275Z","etag":null,"topics":["postgres","postgres-extension","postgresql","python"],"latest_commit_sha":null,"homepage":"https://babar.tselai.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Florents-Tselai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-14T18:55:59.000Z","updated_at":"2024-06-11T18:41:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"6c992fde-50c8-43c4-b21c-7c6252695154","html_url":"https://github.com/Florents-Tselai/babar","commit_stats":null,"previous_names":["florents-tselai/babar"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2Fbabar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2Fbabar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2Fbabar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2Fbabar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Florents-Tselai","download_url":"https://codeload.github.com/Florents-Tselai/babar/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248398758,"owners_count":21097294,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["postgres","postgres-extension","postgresql","python"],"created_at":"2024-10-31T04:08:44.381Z","updated_at":"2025-04-11T12:13:16.762Z","avatar_url":"https://github.com/Florents-Tselai.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cp align=\"center\"\u003e\n   \u003cimg width=\"50%\" height=\"40%\" src=\"https://tselai.com/data/babar-1.png\" alt=\"Logo\"\u003e\n  \u003c/p\u003e\n  \u003ch1 align=\"center\"\u003eBabar🐘❤️🐍\u003c/h1\u003e\n  \u003cp align=\"center\"\u003e\n  \u003cstrong\u003eTurn any Python object into a Postgres extension\u003c/strong\u003e\n    \u003cbr\u003e \u003cbr /\u003e\n    \u003ca href=\"#status\"\u003e\u003cstrong\u003e Status\u003c/strong\u003e\u003c/a\u003e |\n    \u003ca href=\"#why\"\u003e\u003cstrong\u003e Why\u003c/strong\u003e\u003c/a\u003e |\n    \u003ca href=\"#how\"\u003e\u003cstrong\u003e How \u003c/strong\u003e\u003c/a\u003e |\n    \u003ca href=\"#installation\"\u003e\u003cstrong\u003e Installation \u003c/strong\u003e\u003c/a\u003e |\n    \u003ca href=\"#usage\"\u003e\u003cstrong\u003e Usage \u003c/strong\u003e\u003c/a\u003e |\n    \u003ca href=\"#roadmap\"\u003e\u003cstrong\u003e Roadmap \u003c/strong\u003e\u003c/a\u003e \n\n   \u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://pypi.org/project/pybabar/\"\u003e\u003cimg src=\"https://img.shields.io/pypi/v/pybabar?label=PyPI\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Florents-Tselai/babar/actions/workflows/test.yml?branch=mainline\"\u003e\u003cimg src=\"https://github.com/Florents-Tselai/babar/actions/workflows/test.yml/badge.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/florents-tselai/babar\"\u003e\u003cimg src=\"https://codecov.io/gh/Florents-Tselai/babar/branch/main/graph/badge.svg\"\u003e\u003c/a\u003e  \n\u003ca href=\"https://opensource.org/licenses/Apache-2.0\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-Apache%202.0-blue.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Florents-Tselai/babar/releases\"\u003e\u003cimg src=\"https://img.shields.io/github/v/release/Florents-Tselai/babar?include_prereleases\u0026label=changelog\"\u003e\u003c/a\u003e\n\n## Status\n\nWARNING: This is a work in progress and is far from doing what it promises.\nBut not that far... 😉\n\n## Why\n\nPostgres has supported Python as a procedural language for years\nvia [PL/Python](https://www.postgresql.org/docs/current/plpython.html).\n\nEmbedding non-trivial Python code in Postgres  can get cumbersome and usually\ninvolves copy-pasting from existing code bases and/or creating thin wrappers around existing functions.\n\n**babar** automates this process by allowing you to seamlessly package existing Python components (functions, classes etc.)\nint a postgres extension.\n\n## How\n**babar** dynamically inspects the definition of Python objects\nand generates semantically equivalent Postgres definitions\nalong with the necessary extension files (`.control`, `Makefile`, `.sql`)\n\n## Installation\n\n## Usage\n\n```bash\npip install pybabar\n```\n\nLet's create a Postgres extension called [`pystring`](babar/examples/pystring.py)\nwhich adds a few Python functions.\n\n```python\nfrom babar import Extension\n\ndef pyconcat(x: str, y: str) -\u003e str:\n    return x + y\n\ndef pyupper(x: str) -\u003e str:\n    return x.upper()\n\nif __name__ == \"__main__\":\n    Extension(\n        \"pystring\",\n        pyconcat, pyupper,\n        comment=\"this is the pystring extension\",\n        default_version=\"0.1.0\",\n    )\n```\n\nThen, from the command line, you can run:\n\n```bash\npython pystring.py\n```\n\nThat will create the appropriate extension files,\nwhich you can then install in the usual Postgres way:\n```bash\nmake \nmake install\n```\n\nThen you can `CREATE` the extension and use it\n\n```bash\npsql -d postgres \u003c\u003cSQL\nCREATE EXTENSION pystring\n\nSELECT pyconcat('hello ', 'world');\nSELECT pyupper('hello');\nSQL\n```\n\n## Roadmap\n\n## v0.1.0 (wip)\n\n* simple functions (not classes, methods etc)\n* Functions should be 100% self-contained (outer scope is not inspected)\n* primitive types only: support only str/text as arg and return\n* Probably no cli interface / just python __main__.py\n\n## Future\n* `@pg_function` decorator for individual functions. Much like `click`;\n* maybe subclass `Extension` should make a whole Python class an extension?\n* CLI like `babar -m pack.mod.func1 pack2.mod2.func2`\n* Handle upgrades\n* pgxn integration\n\n---\n\nIt is lightly inspired by [Python-Fire](https://github.com/google/python-fire) \nwhich turns any Python object into a cli interface\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflorents-tselai%2Fbabar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflorents-tselai%2Fbabar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflorents-tselai%2Fbabar/lists"}