Skip to content

Use Python without a product specific database driver ​

Coordinator DB's native protocol is specific to its supplied client. A Python driver intended for another database is not a compatible replacement merely because some SQL syntax overlaps. Use HTTP for a Python integration unless a library explicitly implements the documented Coordinator DB contract.

Start with a fixed query ​

The Python standard library can send a request with Basic authentication:

python
import base64
import os
from urllib.request import Request, urlopen

credentials = f"{os.environ['COORDINATOR_USER']}:{os.environ['COORDINATOR_PASSWORD']}"
request = Request(
    os.environ['COORDINATOR_HTTP_URL'],
    data=b'SELECT 1 AS value FORMAT csv',
    headers={'Authorization': 'Basic ' + base64.b64encode(credentials.encode()).decode()},
    method='POST',
)
with urlopen(request, timeout=10) as response:
    print(response.read().decode(), end='')

Handle data separately ​

The example uses a fixed SELECT. For imported values, encode a supported input format instead of constructing SQL with untrusted strings. Check exceptions and preserve the response query identifier when available. A client timeout does not guarantee that a write was rolled back.

Each HTTP request has a separate session; transactions must begin and commit within one request. Use external TLS termination or a trusted route because the server does not provide TLS.

See HTTP requests, formats and native client.