> ## Documentation Index
> Fetch the complete documentation index at: https://oxy.tech/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect from code

> Use standard Postgres drivers for Python, Node.js, Go, and Java to query Airhouse.

Airhouse speaks the Postgres wire protocol, so you use the Postgres driver you already know. There's no Airhouse-specific client library to install.

Every example below connects to the database `demo` as user `alice` on `localhost:5445`. Replace these with your own connection parameters from [Connect with psql](./psql).

<Note>
  Airhouse fully supports the simple query protocol. Its support for the extended query protocol (prepared statements with bound parameters) covers common use, but complex prepared-statement flows can fail. The per-driver tips below keep you on the well-supported path.
</Note>

<Tabs>
  <Tab title="Python">
    Use `psycopg2` (or `psycopg2-binary`) and enable autocommit:

    ```python theme={null}
    import psycopg2

    conn = psycopg2.connect(
        host="localhost",
        port=5445,
        dbname="demo",
        user="alice",
        password="alice-password",
    )
    conn.set_session(autocommit=True)

    with conn.cursor() as cur:
        cur.execute("SELECT kind, count(*) FROM lake.main.events GROUP BY kind")
        for kind, n in cur.fetchall():
            print(kind, n)
    ```

    <Tip>
      `conn.set_session(autocommit=True)` stops psycopg2 from wrapping every statement in an implicit transaction. Without it, a connection can appear to hang.
    </Tip>
  </Tab>

  <Tab title="Node.js">
    Use the `pg` package:

    ```javascript theme={null}
    import { Client } from "pg";

    const client = new Client({
      host: "localhost",
      port: 5445,
      database: "demo",
      user: "alice",
      password: "alice-password",
    });
    await client.connect();

    const { rows } = await client.query(
      "SELECT kind, count(*) AS n FROM lake.main.events GROUP BY kind",
    );
    console.log(rows);

    await client.end();
    ```
  </Tab>

  <Tab title="Go">
    Use `pgx`:

    ```go theme={null}
    package main

    import (
    	"context"
    	"fmt"

    	"github.com/jackc/pgx/v5"
    )

    func main() {
    	ctx := context.Background()
    	conn, err := pgx.Connect(ctx, "postgres://alice:alice-password@localhost:5445/demo")
    	if err != nil {
    		panic(err)
    	}
    	defer conn.Close(ctx)

    	var n int64
    	err = conn.QueryRow(ctx, "SELECT count(*) FROM lake.main.events").Scan(&n)
    	if err != nil {
    		panic(err)
    	}
    	fmt.Println(n)
    }
    ```
  </Tab>

  <Tab title="Java (JDBC)">
    Use the standard PostgreSQL JDBC driver:

    ```java theme={null}
    import java.sql.*;

    public class Example {
        public static void main(String[] args) throws Exception {
            String url = "jdbc:postgresql://localhost:5445/demo";
            try (Connection conn = DriverManager.getConnection(url, "alice", "alice-password");
                 Statement stmt = conn.createStatement();
                 ResultSet rs = stmt.executeQuery("SELECT count(*) FROM lake.main.events")) {
                while (rs.next()) {
                    System.out.println(rs.getLong(1));
                }
            }
        }
    }
    ```

    <Tip>
      If you run into errors with prepared statements, add `preferQueryMode=simple` to the JDBC URL so the driver uses the simple query protocol: `jdbc:postgresql://localhost:5445/demo?preferQueryMode=simple`.
    </Tip>
  </Tab>
</Tabs>

## Connection strings

Most tools accept a Postgres URL:

```text theme={null}
postgresql://<user>:<password>@<host>:5445/<database>
```

Add `?sslmode=require` when the server has TLS enabled. URL-encode special characters in the password.

## Next steps

* [BI and SQL tools](./bi-tools)
* [Service accounts](../guides/service-accounts): mint short-lived credentials for your application's users


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.