Skip to main content

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.

ParameterValue typeRequiredDescriptionExample value
pathstringNoThe path to the seekdb data directory. seekdb stores database files in this directory and loads them when it starts../seekdb
databasestringNoThe 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.

ParameterValue typeRequiredDescriptionExample value
hoststringYesThe IP address of the server where the instance is located.127.0.0.1
protstringYesThe port number of the instance. The default value is 2881.2881
databasestringYesThe name of the database.test
userstringYesThe username. The default value is root.root
passwordstringYesThe 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.

ParameterValue typeRequiredDescriptionExample value
hoststringYesThe IP address of the server where the database is located.127.0.0.1
protstringYesThe port number of OceanBase Database. The default value is 2881.2881
tenantstringNoThe name of the tenant. This parameter is not required for seekdb. For OceanBase Database, the default value is sys.test
databasestringYesThe name of the database.test
userstringYesThe username corresponding to the tenant. The default value is root.root
passwordstringYesThe 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.

APIDescriptionDocument 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