Skip to main content

DuckDB HTTP客户端,提供简单的方式通过HTTP API与DuckDB服务器交互

Project description

DuckDB Server Python Client

这是一个简单的Python客户端库,用于通过HTTP API与DuckDB服务器进行交互。

安装

pip install duckdb-server-client

使用方法

基本使用

from duckdb_server_client import DuckDBClient

# 创建客户端实例
client = DuckDBClient(
    host="localhost",  # 默认值
    port=9999,        # 默认值
    api_key=None      # 可选的API密钥
)

# 执行简单查询
result = client.execute("SELECT * FROM users")
if result["success"]:
    print(result["data"])
else:
    print(f"错误: {result['error']}")

参数化查询

支持使用命名参数进行参数化查询:

# 使用参数化查询
result = client.execute(
    "SELECT * FROM users WHERE age > :min_age AND city = :city",
    {
        "min_age": 18,
        "city": "北京"
    }
)

# 等同于执行:SELECT * FROM users WHERE age > 18 AND city = '北京'

返回值格式

成功时返回:

{
    "success": True,
    "data": <查询结果>  # JSON数据或文本
}

失败时返回:

{
    "success": False,
    "error": "错误信息",
    "status_code": HTTP状态码
}

特性

  • 简单易用的API
  • 支持参数化查询
  • 支持API密钥认证
  • 自动处理JSON响应
  • 完善的错误处理

注意事项

  • 参数化查询中的参数名需要使用:作为前缀
  • 字符串类型的参数会自动添加单引号
  • 数字类型的参数会直接替换到SQL语句中

API文档

DuckDBClient

初始化

client = DuckDBClient(host="localhost", port=9999, api_key=None)

参数:

  • host: DuckDB服务器主机地址
  • port: DuckDB服务器端口
  • api_key: API密钥(可选)

方法

execute(query: str)

执行SQL查询并返回结果。

query(sql: str)

execute方法的别名,用于执行SQL查询。

许可证

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

duckdb_server_client-0.1.3.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

duckdb_server_client-0.1.3-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file duckdb_server_client-0.1.3.tar.gz.

File metadata

  • Download URL: duckdb_server_client-0.1.3.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for duckdb_server_client-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e0ce6dbeefa7223b39bcbec7300b8301ce1748d79cde58c4f5b3fa3d38d4791a
MD5 941524512281c0fdbec8d0fbc6354292
BLAKE2b-256 0a1c9b8ce4d5ea259698902e52972728931eb716a91f827132821684fe640cf9

See more details on using hashes here.

File details

Details for the file duckdb_server_client-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for duckdb_server_client-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9859b3d5f38a977c6e0ea2cbf5c3e637d60c780a07dff4ee4dafc26ab306782a
MD5 eeb1ed08d3586f820b5dde1b4af4f1d8
BLAKE2b-256 474b538e7d9eafb7e3679e5a6f62bad0f60fc3bef7fe104163ffe14ff1076f10

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page