Python API Reference
A complete reference for Infinity's Python APIs.
SCHEMA MANAGEMENT
connect
# Connect to the Infinity server and get an Infinity object
infinity.connect(uri)
Connects to the Infinity server, and gets an Infinity object.
You must have an Infinity object ready to perform database-specific operations.
Parameters
uri: Required
The uri here is a NetworkAddress object:
NetworkAddress: Used in client-server mode, when you have deployed Infinity as a separate server and wish to connect to it remotely. A NetworkAddress object comprises two fields:
"<SERVER_IP_ADDRESS>":str- The IP address of the Infinity server.<PORT>:int- The SDK port number on which the Infinity server listens. Defaults to23817.
When setting uri as NetworkAddress, ensure you:
- Install the Infinity SDK:
pip install infinity==<VERSION> - Import the
infinitymodule:import infinity.
When connecting to Infinity in client-server mode, ensure that the client version exactly matches the server version. For example:
| Client version | Server version |
|---|---|
| v0.1.0 | v0.1.0 |
| v0.1.1 | v0.1.1 |
| v0.2.0 | v0.2.0 |
| v0.2.1 | v0.2.1 |
| v0.3.0 | v0.3.0 |
| v0.4.0 | v0.4.0 |
| v0.5.0-dev2 | v0.5.0-dev2 |
If the versions do not match, please update your client or server to ensure compatibility.
In client-server mode, also ensure that your server version matches the version specified in your configuration file. Here, the matching rule is less strict than an exact match:
- The major and minor versions must be identical.
- The patch version may differ.
This allows for bug fixes without requiring changes to the configuration file.
| Configuration version | Compatible server version |
|---|---|
| v0.1.0 | v0.1.0, v0.1.1 |
| v0.2.0 | v0.2.0, v0.2.1 |
Returns
- Success: An
infinity.remote_thrift.infinity.RemoteThriftInfinityConnectionobject in client-server mode. - Failure:
InfinityExceptionerror_code:int- A non-zero value indicating a specific error condition.error_msg:str- A message providing additional details about the error.
Examples
Connect to Infinity in client-server mode
If you have deployed Infinity as a separate server and installed the Infinity client via pip install infinity==<VERSION>, you can connect to it via its IP address. If your Infinity is running on your local machine, you can also use infinity.common.LOCAL_HOST to replace "<SERVER_IP_ADDRESS>" in the following code snippet.
import infinity
# If Infinity is deployed on the local machine, use infinity.LOCAL_HOST to replace <SERVER_IP_ADDRESS>
infinity_object = infinity.connect(infinity.NetworkAddress("192.168.1.101", 23817))
disconnect
infinity_object.disconnect()
Disconnects the client from the Infinity server in client-server mode, or destructs the Infinity object and releases all associated resources when Infinity is imported as a Python module.
Returns
A structure containing the following attributes:
error_code:int0: The operation succeeds.- A non-zero value indicates a specific error condition.
error_msg:str
Whenerror_codeis non-zero,error_msgprovides additional details about the error.
Examples
infinity_object.disconnect()
create_database
infinity_object.create_database(db_name, conflict_type = ConflictType.Error, comment = None)
Creates a database with a specified name.
Parameters
db_name: str, Required
A non-empty string indicating the name of the database, which must adhere to the following requirements:
- Permitted characters include:
- English letters (a-z, A-Z)
- Digits (0-9)
- "_" (underscore)
- Must begin with an English letter or underscore.
- Maximum 65,535 characters.
- Case-insensitive.
conflict_type: ConflictType, Optional
Error: Raise an error if a database with the same name exists.Ignore: Ignore the database creation request and keep the existing database with the same name.
You may want to import the infinity.common package to set ConflictType:
from infinity.common import ConflictType
If ConflictType is not set, it defaults to Error.
comment: str, Optional
Additional comment for the database to create.
Returns
- Success: An
infinity.remote_thrift.db.RemoteDatabaseobject in client-server mode. - Failure:
InfinityExceptionerror_code:int- A non-zero value indicating a specific error condition.error_msg:str- A message providing additional details about the error.
Examples
# Create a database named 'my_database':
# If the specified database already exists, raise an error.
infinity_object.create_database("my_database")
# Create a database named 'my_database':
# If the specified database already exists, raise an error (same as above).
infinity_object.create_database("my_database", infinity.common.ConflictType.Error, comment="Database One")
from infinity.common import ConflictType
# Create a database named 'my_database':
# If the specified database already exists, silently ignore the operation and proceed.
infinity_object.create_database("my_database", ConflictType.Ignore, comment="Database One")
drop_database
infinity_object.drop_database(db_name, conflict_type = ConflictType.Error)
Deletes a database by its name.
Parameters
db_name: str, Required
A non-empty string indicating the name of the database to delete.
conflict_type: ConflictType, Optional
Error: Raise an error if the specified database does not exist.Ignore: Ignore the operation and proceed regardless, if the specified database does not exist.
You may want to import the infinity.common package to set ConflictType:
from infinity.common import ConflictType
If ConflictType is not set, it defaults to Error.
Returns
A structure containing the following attributes:
error_code:int0: The operation succeeds.- A non-zero value indicates a specific error condition.
error_msg:str
Whenerror_codeis non-zero,error_msgprovides additional details about the error.
Examples
# Delete a database named 'my_database':
# If the specified database does not exist, raise an error.
infinity_object.drop_database("my_database")
# Delete a database named 'my_database':
# If the specified database does not exist, raise an error (same as above).
infinity_object.drop_database("my_database", infinity.common.ConflictType.Error)
from infinity.common import ConflictType
# Delete a database named 'my_database':
# If the specified database does not exist, silently ignore the operation and proceed.
infinity_object.drop_database("my_database", ConflictType.Ignore)
list_databases
infinity_object.list_databases()
Retrieves a list of all available databases within the Infinity system.
Returns
A structure containing the following attributes:
db_names:list[str]A list of strings indicating the names of all available databases.error_code:int0: The operation succeeds.- A non-zero value indicates a specific error condition.
error_msg:str
Whenerror_codeis non-zero,error_msgprovides additional details about the error.
Examples
res = infinity_object.list_databases()
print(res.db_names) # ['my_database', 'database_1']
show_database
infinity_object.show_database(database_name)
Shows detailed information about a database.
Returns
A structure containing the following attributes:
error_code:int0: The operation succeeds.- A non-zero value indicates a specific error condition.
error_msg:str
Whenerror_codeis non-zero,error_msgprovides additional details about the error.
Examples
res = infinity_object.show_database('my_database')
get_database
infinity_object.get_database(database_name)
Retrieves a database object by its name.
Parameters
db_name: str, Required
A non-empty string indicating the name of the database to retrieve.
Returns
- Success: An
infinity.remote_thrift.db.RemoteDatabaseobject in client-server mode. - Failure:
InfinityExceptionerror_code:int- A non-zero value indicating a specific error condition.error_msg:str- A message providing additional details about the error.
Examples
db_object = infinity_object.get_database("my_database")
create_table
db_object.create_table(table_name, columns_definition, conflict_type = ConflictType.Error)
Creates a table with a specified name and defined columns.
Call create_database() or get_database() to get a database object for all table-specific operations.
Parameters
table_name: str, Required
A non-empty string indicating the name of the table, which must adhere to the following requirements:
- Permitted characters include:
- English letters (a-z, A-Z)
- Digits (0-9)
- "_" (underscore)
- Must begin with an English letter or underscore.
- Maximum 65,535 characters.
- Case-insensitive.
columns_definition: dict[str, dict[str, Any]], Required
Definitions for all table columns as a dictionary. Each key in the dictionary is a column name (a str following the same rule as table_name), with a corresponding 'value' dictionary defining the column's data type and default value information in key-value pairs:
- Data type (
"type")
The data type of the column.- Numeric:
"int8""int16""int"/"int32"/"integer""int64""float"/"float32""double"/"float64""float16""bfloat16"
- String:
"varchar" - Dense vector: e.g.,
"vector,128,float"vector: The column is a dense vector column.- The second item in the string: The dimension of dense vector.
- The third item in the string: The element type of dense vector. Can be:
"int8""int16""int"/"int32"/"integer""int64""float"/"float32""double"/"float64""float16""bfloat16"
- Sparse vector: e.g.,
"sparse,128,float,int"sparse: The column is a sparse vector column.- The second item in the string: The dimension of sparse vector.
- The third item in the string: The element type of sparse vector. Can be:
"int8""int16""int"/"int32"/"integer""int64""float"/"float32""double"/"float64""float16""bfloat16"
- The fourth item in the string: The data type of sparse vector indices. Can be:
int8int16int/int32/integerint64
- Tensor vector: e.g.,
"tensor,4,float"tensor: The column is a tensor column.- The second item in the string: The dimension of each vector unit in a tensor.
- The third item in the string: The element type of tensors. Can be:
"int8""int16""int"/"int32"/"integer""int64""float"/"float32""double"/"float64""float16""bfloat16"
- Tensor array: e.g.,
"tensorarray,6,float"tensorarray: The column is a tensor-array column.- The second item in the string: The dimension of each vector unit in a tensor array.
- The third item in the string: The element type of tensor arrays. Can be:
"int8""int16""int"/"int32"/"integer""int64""float"/"float32""double"/"float64""float16""bfloat16"
- Multivector: e.g.,
"multivector,128,float"multivector: The column is a multi-vector column.- The second item in the string: The dimension of each vector unit in a multivector.
- The third item in the string: The element type of multi-vectors. Can be:
"int8""int16""int"/"int32"/"integer""int64""float"/"float32""double"/"float64""float16""bfloat16"
- Array: e.g.,
"array,varchar","array,array,varchar"array: The column is an array column.- followed by the element type of the array. Can be recursive.
- for example,
"array,varchar"is a one-dimensional array of strings, and"array,array,varchar"is a two-dimensional array of strings.
- Numeric:
- Default value (
"default")
The default value for unspecified cells in that column.
conflict_type: ConflictType, Optional
Error: Raise an error if a table with the same name exists.Ignore: Ignore the table creation request and keep the existing table with the same name.
You may want to import the infinity.common package to set ConflictType:
from infinity.common import ConflictType
If ConflictType is not set, it defaults to Error.
Returns
- Success: An
infinity.remote_infinity.table.RemoteTableobject in client-server mode. - Failure:
InfinityException:error_code:int- A non-zero value indicating a specific error condition.error_msg:str- A message providing additional details about the error.
Examples
Create a table with an integer column only
# The `create_table`method supports creating integer columns in the following data types:
# - int8
# - int16
# - int/int32/integer
# - int64
db_object.create_table("my_table", {"c1": {"type": "int", "default": 1}})
Create a table with a float column only
# The `create_table`method supports creating float columns in the following data types:
# - float/float32
# - double/float64
# - float16
# - bfloat16
db_object.create_table("my_table", {"c1": {"type": "float64"}})
Create a table with a string column only
db_object.create_table("my_table", {"c1": {"type": "varchar"}})
Create a table with a bool column only
db_object.create_table("my_table", {"c1": {"type": "bool"}})
Create a table with a vector column only
You can build a HNSW index on the vector column to speed up the match_dense search.
# Create a table with a vector column only:
# - `vector`: The column is a vector column
# - `128`: The vector dimension
# - `float`: The primitive data type of the vectors. Can be `float`/`float32`, `float16`, `bfloat16`, `uint8` or `int8`
db_object.create_table("my_table", {"c1": {"type": "vector,128,float"}})
Create a table with a multi-vector column only
You can build an HNSW index on the multi-vector column to accelerate match_dense search.
# Create a table with a multi-vector column only:
# - `multivector`: The column is a multi-vector column
# - `128`: The basic vector dimension
# - `float`: The primitive data type of the basic vectors. Can be `float`/`float32`, `float16`, `bfloat16`, `uint8` or `int8`
db_object.create_table("my_table", {"c1": {"type": "multivector,128,float"}})
Create a table with a sparse vector column only
You can build a BMP index on the sparse vector column to speed up the match_sparse search.
from infinity.common import ConflictType
# Create a table with a vector column only:
# - `sparse`: The column is a sparse vector column
# - `128`: The sparse vector dimension
# - `float`: The primitive data type of the sparse vectors. Can be `float`/`float32` or `double`/`float64`
# - `int`: The data type of the sparse vector indices. Can be `int8`, `int16`, `int`/`int32`/`integer`, or `int64`
db_object.create_table("my_table", {"c1": {"type": "sparse,128,float,int"}}, ConflictType.Error)
Create a table with a tensor column only
from infinity.common import ConflictType
# Create a table with a tensor column only:
# - `tensor`: The column is a tensor column
# - `4`: Dimension of each vector unit in the tensor
# - `float`: The primitive data type of the tensors. Can be `float`/`float32`, `float16`, `bfloat16` or `bit`
db_object.create_table("my_table", {"c1": {"type": "tensor,4,float"}}, ConflictType.Ignore)
Create a table with a tensor array column only
from infinity.common import ConflictType
# Create a table with a tensor array column only:
# - `tensorarray`: The column is a tensor array column
# - `6`: Dimension of each vector unit in the tensor arrays
# - `float`: The primitive data type of the tensor arrays. Can be `float`/`float32`, `float16`, `bfloat16` or `bit`
db_object.create_table("my_table", {"c1": {"type": "tensorarray,6,float"}}, ConflictType.Ignore)
drop_table
db_object.drop_table(table_name, conflict_type = ConflictType.Error)
Deletes a table from the database by its name.
Parameters
table_name: str, Required
A non-empty string indicating the name of the table to delete.
conflict_type: ConflictType, Optional
Error: Raise an error if the specified table does not exist.Ignore: Ignore the operation and proceed regardless, if the specified table does not exist.
You may want to import the infinity.common package to set ConflictType:
from infinity.common import ConflictType
If ConflictType is not set, it defaults to Error.
Returns
A structure containing the following attributes:
error_code:int0: The operation succeeds.- A non-zero value indicates a specific error condition.
error_msg:str
Whenerror_codeis non-zero,error_msgprovides additional details about the error.
Examples
# Delete a table named 'my_table':
# If the specified table does not exist, raise an error.
db_object.drop_table("my_table")
# Delete a table named 'my_table':
# If the specified table does not exist, raise an error (same as above).
db_object.drop_table("my_table", infinity.common.ConflictType.Error)
from infinity.common import ConflictType
# Delete a table named 'my_table':
# If the specified table does not exist, silently ignore the operation and proceed.
db_object.drop_table("my_table", ConflictType.Ignore)
create_table_snapshot
db_object.create_table_snapshot(snapshot_name, table_name)
Creates a snapshot of the specified table with the given snapshot name.
Parameters
snapshot_name: str, Required
A non-empty string indicating the name of the table snapshot.
table_name: str, Required
A non-empty string indicating the name of the table.
Returns
A structure containing the following attributes:
error_code:int0: The operation succeeds.- A non-zero value indicates a specific error condition.
error_msg:str
Whenerror_codeis non-zero,error_msgprovides additional details about the error.
Examples
# Create a snapshot named 'my_table_snapshot' of the table 'my_table'.
# If the specified snapshot already exists or the specified table does not exist, raise an error.
db_object.create_table_snapshot("my_table_snapshot", "my_table")
create_database_snapshot
infinity_obj.create_database_snapshot(snapshot_name, database_name)
Creates a snapshot of the specified database with the given snapshot name.
Parameters
snapshot_name: str, Required
A non-empty string indicating the name of the database snapshot.
database_name: str, Required
A non-empty string indicating the name of the database.
Returns
A structure containing the following attributes:
error_code:int0: The operation succeeds.- A non-zero value indicates a specific error condition.
error_msg:str
Whenerror_codeis non-zero,error_msgprovides additional details about the error.
Examples
# Create a snapshot named 'my_database_snapshot' of the database 'my_database'.
# If the specified snapshot already exists or the specified database does not exist, raise an error.
infinity_obj.create_database_snapshot("my_database_snapshot", "my_database")
create_system_snapshot
infinity_obj.create_system_snapshot(snapshot_name)
Creates a snapshot of the system with the given snapshot name.
Parameters
snapshot_name: str, Required
A non-empty string indicating the name of the system snapshot.