omni_python

omni_python

omnigres : First-class Python support

Overview

ID Extension Package Version Category License Language
2960
omni_python
omnigres
0.1.1
FEAT
Apache-2.0
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d--
No
Yes
No
Yes
no
no
Relationships
Schemas omni_python
Requires
plpython3u
Siblings
omni
omni_auth
omni_aws
omni_cloudevents
omni_containers
omni_credentials
omni_email
omni_http
omni_httpc
omni_httpd
omni_id
omni_json
omni_kube
omni_ledger
omni_manifest
omni_mimetypes
omni_os
omni_polyfill
omni_regex
omni_rest
omni_schema
omni_seq
omni_service
omni_session
omni_sql
omni_sqlite
omni_test
omni_txn
omni_types
omni_var
omni_vfs
omni_vfs_types_v1
omni_web
omni_worker
omni_xml
omni_yaml

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
0.1.1
18
17
16
15
14
omnigres plpython3u
RPM
PIGSTY
0.1.1
18
17
16
15
14
omnigres_$v -
DEB
PIGSTY
0.1.1
18
17
16
15
14
postgresql-$v-omnigres -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
MISS
PIGSTY 20250120
PIGSTY 20250120
PIGSTY 20250120
PIGSTY 20250120
el8.aarch64
MISS
PIGSTY 20250120
PIGSTY 20250120
PIGSTY 20250120
PIGSTY 20250120
el9.x86_64
MISS
PIGSTY 20250507
PIGSTY 20250507
PIGSTY 20250507
PIGSTY 20250507
el9.aarch64
MISS
PIGSTY 20250507
PIGSTY 20250507
PIGSTY 20250507
PIGSTY 20250507
el10.x86_64
MISS
MISS
MISS
MISS
MISS
el10.aarch64
MISS
MISS
MISS
MISS
MISS
d12.x86_64
MISS
PIGSTY 20250120
PIGSTY 20250120
PIGSTY 20250120
PIGSTY 20250120
d12.aarch64
MISS
PIGSTY 20250120
PIGSTY 20250120
PIGSTY 20250120
PIGSTY 20250120
d13.x86_64
PIGSTY 20251108
PIGSTY 20251108
PIGSTY 20251108
PIGSTY 20251108
PIGSTY 20251108
d13.aarch64
PIGSTY 20251108
PIGSTY 20251108
PIGSTY 20251108
PIGSTY 20251108
PIGSTY 20251108
u22.x86_64
MISS
PIGSTY 20250120
PIGSTY 20250120
PIGSTY 20250120
PIGSTY 20250120
u22.aarch64
MISS
PIGSTY 20250120
PIGSTY 20250120
PIGSTY 20250120
PIGSTY 20250120
u24.x86_64
PIGSTY 20251108
PIGSTY 20251108
PIGSTY 20251108
PIGSTY 20251108
PIGSTY 20251108
u24.aarch64
PIGSTY 20251108
PIGSTY 20251108
PIGSTY 20251108
PIGSTY 20251108
PIGSTY 20251108

Source

pig build pkg omnigres;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install omnigres;		# install via package name, for the active PG version
pig install omni_python;		# install by extension name, for the current active PG version

pig install omni_python -v 18;   # install for PG 18
pig install omni_python -v 17;   # install for PG 17
pig install omni_python -v 16;   # install for PG 16
pig install omni_python -v 15;   # install for PG 15
pig install omni_python -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION omni_python CASCADE; -- requires plpython3u

Usage

omni_python: First-class Python support

The omni_python extension integrates Python code as stored procedures in PostgreSQL.

Basic Python Function

Create a Python file with the @pg decorator:

# hello.py
from omni_python import pg

@pg
def hello() -> str:
    return "Hey there!"

@pg
def add(a: int, b: int) -> int:
    return a + b

Loading Python Files

CREATE EXTENSION omni_python CASCADE;
CREATE EXTENSION omni_schema CASCADE;
CREATE EXTENSION omni_vfs CASCADE;

CREATE OR REPLACE FUNCTION demo_fs() RETURNS omni_vfs.local_fs
    LANGUAGE sql AS $$ SELECT omni_vfs.local_fs('/python-files') $$;

SELECT omni_schema.load_from_fs(demo_fs());

Flask Integration

from omni_python import pg
from omni_http import omni_httpd
from omni_http.omni_httpd import flask
from flask import Flask, jsonify, request

app = Flask('myapp')

@app.route('/employees', methods=['GET'])
def get_employees():
    employees = plpy.execute(plpy.prepare("select * from employees"))
    return json.dumps([dict(e) for e in employees])

handle = pg(flask.Adapter(app))

Configure the HTTP handler:

UPDATE omni_httpd.handlers SET query = $$select handle(request.*) from request$$;
Last updated on