Skip to main content
Applications connect to and interact with YugabyteDB using API client libraries (also known as drivers). YugabyteDB supports both PostgreSQL-compatible drivers for YSQL and Cassandra-compatible drivers for YCQL.

Driver Types

YugabyteDB supports two types of drivers:

Standard PostgreSQL Drivers

Because YugabyteDB YSQL is PostgreSQL-compatible, you can use standard PostgreSQL drivers to connect and work with YugabyteDB. These drivers provide full compatibility with PostgreSQL applications.

YugabyteDB Smart Drivers

Smart drivers extend the upstream PostgreSQL drivers with cluster-aware capabilities:
  • Load balancing: Distribute connections across cluster nodes
  • Topology awareness: Connect to geographically closest nodes
  • Automatic failover: Handle node failures transparently
  • Connection pooling: Efficient connection management
For production deployments, we recommend using YugabyteDB Smart Drivers for optimal performance and resilience.

Supported Drivers by Language

Java

YugabyteDB provides comprehensive Java driver support:

YugabyteDB JDBC Smart Driver

Recommended for production
  • Cluster-aware load balancing
  • Topology-aware connection routing
  • Built on PostgreSQL JDBC driver
<dependency>
  <groupId>com.yugabyte</groupId>
  <artifactId>jdbc-yugabytedb</artifactId>
  <version>42.3.5-yb-5</version>
</dependency>

PostgreSQL JDBC Driver

Standard PostgreSQL driver
<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <version>42.2.14</version>
</dependency>
Connection Example:
import com.yugabyte.ysql.YBClusterAwareDataSource;

YBClusterAwareDataSource ds = new YBClusterAwareDataSource();
ds.setUrl("jdbc:postgresql://localhost:5433/yugabyte");
ds.setUser("yugabyte");
ds.setPassword("yugabyte");

Connection conn = ds.getConnection();
ORMs:
  • Hibernate: Full JPA support
  • MyBatis: SQL mapping framework
  • Ebean: Simplicity and performance
  • Spring Data JPA: Spring integration

Python

Python developers can use Psycopg2, Psycopg3, or the YugabyteDB smart driver.

Yugabyte Psycopg2

Recommended for production
pip install yugabyte-psycopg2

PostgreSQL Psycopg2

Standard PostgreSQL adapter
pip install psycopg2-binary
Connection Example:
import psycopg2

conn = psycopg2.connect(
    host="localhost",
    port=5433,
    database="yugabyte",
    user="yugabyte",
    password="yugabyte"
)

cursor = conn.cursor()
cursor.execute("SELECT version()")
print(cursor.fetchone())
ORMs:
  • SQLAlchemy: Popular Python ORM
  • Django ORM: Built-in Django support

Node.js

Node.js applications use the node-postgres (pg) driver.
npm install pg
Connection Example:
const { Client } = require('pg');

const client = new Client({
  host: 'localhost',
  port: 5433,
  database: 'yugabyte',
  user: 'yugabyte',
  password: 'yugabyte'
});

await client.connect();

const res = await client.query('SELECT * FROM users WHERE id = $1', [1]);
console.log(res.rows[0]);

await client.end();
ORMs:
  • Prisma: Modern ORM with type safety
  • Sequelize: Feature-rich ORM
  • TypeORM: TypeScript-first ORM

Go

Go applications can use pgx or the standard database/sql interface.
go get github.com/lib/pq
go get github.com/jackc/pgx/v5
Connection Example:
import (
    "database/sql"
    _ "github.com/lib/pq"
)

connStr := "host=localhost port=5433 user=yugabyte password=yugabyte dbname=yugabyte sslmode=disable"
db, err := sql.Open("postgres", connStr)
if err != nil {
    log.Fatal(err)
}
defer db.Close()

rows, err := db.Query("SELECT id, username FROM users")
if err != nil {
    log.Fatal(err)
}
defer rows.Close()
ORMs:
  • GORM: Feature-rich ORM
  • sqlx: Extensions to database/sql

C# / .NET

Use Npgsql driver for .NET applications.
dotnet add package Npgsql
Connection Example:
using Npgsql;

string connString = "Host=localhost;Port=5433;Username=yugabyte;Password=yugabyte;Database=yugabyte";

using (var conn = new NpgsqlConnection(connString))
{
    conn.Open();
    
    using (var cmd = new NpgsqlCommand("SELECT username FROM users WHERE id = @id", conn))
    {
        cmd.Parameters.AddWithValue("id", 1);
        var username = cmd.ExecuteScalar();
        Console.WriteLine(username);
    }
}
ORMs:
  • Entity Framework Core: Microsoft’s ORM
  • Dapper: Micro-ORM for .NET

Ruby

Use the pg gem for Ruby applications.
gem install pg
Connection Example:
require 'pg'

conn = PG.connect(
  host: 'localhost',
  port: 5433,
  dbname: 'yugabyte',
  user: 'yugabyte',
  password: 'yugabyte'
)

result = conn.exec('SELECT * FROM users')
result.each do |row|
  puts row['username']
end

conn.close
ORMs:
  • Active Record: Rails default ORM

YCQL Drivers (Cassandra Compatible)

For applications using YCQL (Cassandra-compatible API):

Java

<dependency>
  <groupId>com.yugabyte</groupId>
  <artifactId>cassandra-driver-core</artifactId>
  <version>3.10.3-yb-2</version>
</dependency>

Python

pip install yb-cassandra-driver

Node.js

npm install cassandra-driver

Connection Pooling

Connection pooling is essential for production applications:
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:postgresql://localhost:5433/yugabyte");
config.setUsername("yugabyte");
config.setPassword("yugabyte");
config.setMaximumPoolSize(10);

HikariDataSource ds = new HikariDataSource(config);
from sqlalchemy import create_engine

engine = create_engine(
    'postgresql://yugabyte:yugabyte@localhost:5433/yugabyte',
    pool_size=10,
    max_overflow=20
)
const { Pool } = require('pg');

const pool = new Pool({
  max: 20,
  idleTimeoutMillis: 30000,
  connectionTimeoutMillis: 2000,
});
YugabyteDB includes a built-in connection pooler that provides connection pooling without external dependencies.Enable it on the server side for automatic connection management.

SSL/TLS Configuration

For secure connections in production:
String url = "jdbc:postgresql://hostname:5433/yugabyte" +
             "?ssl=true&sslmode=verify-full" +
             "&sslrootcert=/path/to/root.crt";
Connection conn = DriverManager.getConnection(url, user, password);

Next Steps

Build Apps

Start building your first application

Best Practices

Follow driver best practices

Smart Drivers

Learn about smart driver features

Connection Manager

Use built-in connection pooling

Build docs developers (and LLMs) love