Files
2025-11-30 08:44:54 +08:00

5.5 KiB

slug
slug
/client

Client

The Client class is used to connect to a database in either embedded mode or server mode. It automatically selects the appropriate connection mode based on the provided parameters.

:::tip OceanBase Database is a fully self-developed, enterprise-level, native distributed database developed by OceanBase. It achieves financial-grade high availability on ordinary hardware and sets a new standard for automatic, lossless disaster recovery across five IDCs in three regions. It also sets a new benchmark in the TPC-C benchmark test, with a single cluster size exceeding 1,500 nodes. OceanBase Database is cloud-native, highly consistent, and highly compatible with Oracle and MySQL. For more information about OceanBase Database, see OceanBase Database. :::

Connect to an embedded seekdb instance

Use the Client class to connect to a local embedded seekdb instance.

import pyseekdb

# Create embedded client
client = pyseekdb.Client(
    #path="./seekdb",      # Path to SeekDB data directory
    #database="test"        # Database name
)

The following table describes the parameters.

Parameter Value type Required Description Example value
path string No The path to the seekdb data directory. seekdb stores database files in this directory and loads them when it starts. ./seekdb
database string No The name of the database. test

Connect to a remote server

Use the Client class to connect to a remote server, which runs seekdb or OceanBase Database.

:::tip

Before you connect to a remote server, make sure that you have deployed a server instance of seekdb or OceanBase Database.
For information about how to deploy a server instance of seekdb, see Overview.
For information about how to deploy OceanBase Database, see Overview.

:::

Example: Connect to a server instance of seekdb

import pyseekdb

# Create remote server client (SeekDB Server)
client = pyseekdb.Client(
    host="127.0.0.1",      # Server host
    port=2881,              # Server port
    database="test",        # Database name
    user="root",            # Username
    password=""             # Password (can be retrieved from SEEKDB_PASSWORD environment variable)
)

The following table describes the parameters.

Parameter Value type Required Description Example value
host string Yes The IP address of the server where the instance is located. 127.0.0.1
prot string Yes The port number of the instance. The default value is 2881. 2881
database string Yes The name of the database. test
user string Yes The username. The default value is root. root
password string Yes The password corresponding to the user. If you do not provide the password parameter or specify an empty string, the system retrieves the password from the SEEKDB_PASSWORD environment variable.

Example: Connect to OceanBase Database

import pyseekdb

# Create remote server client (OceanBase Server)
client = pyseekdb.Client(
    host="127.0.0.1",      # Server host
    port=2881,              # Server port (default: 2881)
    tenant="test",         # Tenant name
    database="test",       # Database name
    user="root",           # Username (default: "root")
    password=""             # Password (can be retrieved from SEEKDB_PASSWORD environment variable)
)

The following table describes the parameters.

Parameter Value type Required Description Example value
host string Yes The IP address of the server where the database is located. 127.0.0.1
prot string Yes The port number of OceanBase Database. The default value is 2881. 2881
tenant string No The name of the tenant. This parameter is not required for seekdb. For OceanBase Database, the default value is sys. test
database string Yes The name of the database. test
user string Yes The username corresponding to the tenant. The default value is root. root
password string Yes The password corresponding to the user. If you do not provide the password parameter or specify an empty string, the system retrieves the password from the SEEKDB_PASSWORD environment variable.

APIs supported when you use the Client class to connect to a database

When you use the Client class to connect to a database, you can call the following APIs.

API Description Document link
create_collection() Creates a new collection. Document
get_collection() Queries a specified collection. Document
delete_collection() Deletes a specified collection. Document
list_collections() Lists all collections in the current database. Document
get_or_create_collection() Queries a specified collection. If the collection does not exist, it is created. Document
count_collection() Queries the number of collections in the current database. Document