Python SDK with jdbc connector

I know there is a JDBC driver for the Java SDK

Checking if there is anything similar for the Python SDK?

Any tips?

After reviewing the java SDK.. the first step would be something like the following

ziti edge create config private-postgres-cfg ziti-tunneler-client.v1 '{ "hostname" : "zitified-postgres", "port" : 5432 }'

ziti edge create service private-postgres --configs private-postgres-cfg -a "private-postgres-services"

ziti edge create terminator "private-postgres" "ziti-private-blue" tcp:postgres-db:5432

ziti edge create service-policy postgres-dial-policy Dial --identity-roles '#postgres-clients' --service-roles '#private-postgres-services'

the next step is to use a monkeypatch to make a call.. though I am not really sure how this would be setup for a client

Maybe it could be something like this.. but I need to test it out

it assumes that a tunneler app is running
not 100% sure how to configure it without the tunneler

openziti.monkeypatch()

conn = psycopg2.connect(
host="zitified-postgres",
database="simpledb",
user="postgres",
password="Abcd1234")

  # create a cursor
    cur = conn.cursor()

  print('PostgreSQL database version:')
    cur.execute('SELECT version()')

    # display the PostgreSQL database server version
    db_version = cur.fetchone()
    print(db_version)
   
# close the communication with the PostgreSQL
    cur.close()
except (Exception, psycopg2.DatabaseError) as error:
    print(error)
finally:
    if conn is not None:
        conn.close()
        print('Database connection closed.')

I found this example that uses sockets.. so to avoid the use of the tunneler.. some of this code will need to be used I think

let me know if you have any suggestions

I am quite a newbie re Python.

https://kb.objectrocket.com/postgresql/python-sockets-and-postgres-1227

@markamind Did you get a chance to make it work? I'm looking for the similar solution to connect postgresDB using python SDK.

See also Dns routing inside Kubernetes with Edge tunneler daemonset - #7 by natashell for a note on using python sdk to connect to PostgresSQL DB

1 Like