Linkis Python SDK
Linkis Python SDK是与Apache Linkis服务交互的Python客户端库。该SDK提供了简便的接口,用于执行代码并获取结果,支持同步和异步操作。
Linkis Python SDK is the Python client library for interacting with Apache Linkis services. This SDK provides convenient interfaces for executing code and retrieving results, supporting both synchronous and asynchronous operations.
安装
Installation
pip install linkis-python-sdk
功能特点
Features
-
支持同步和异步客户端
-
支持结果缓存
-
提供数据过滤、排序和分页功能
-
轻松将结果转换为Pandas DataFrame
-
Support for synchronous and asynchronous clients
-
Result caching capabilities
-
Data filtering, sorting, and pagination
-
Easy conversion of results to Pandas DataFrame
使用示例
Usage Examples
同步客户端
Synchronous Client
from linkis_python_sdk.client import LinkisClient
from linkis_python_sdk.config.config import LinkisConfig
# 创建配置
# Create configuration
config = LinkisConfig(
base_url="http://your-linkis-server/api/rest_j/v1",
username="your_username",
password="your_password"
)
# 创建客户端
# Create client
client = LinkisClient(config)
# 执行代码
# Execute code
code = "SELECT * FROM my_table LIMIT 10"
query_req = {
"columns": [{"column": "id"}, {"column": "name"}],
"filters": [{"column": "age", "operator": "gt", "value": 18}],
"orderbys": [{"column": "id", "ascending": True}],
"page": 1,
"page_size": 10
}
data, total, error = client.execute_code(
code=code,
query_req=query_req,
engine_type="spark",
run_type="sql"
)
print(f"Total records: {total}")
print(f"Data: {data}")
异步客户端
Asynchronous Client
import asyncio
from linkis_python_sdk.asyncio.client import LinkisClient
from linkis_python_sdk.config.config import LinkisConfig
async def main():
# 创建配置
# Create configuration
config = LinkisConfig(
base_url="http://your-linkis-server/api/rest_j/v1",
username="your_username",
password="your_password"
)
# 创建异步客户端
# Create asynchronous client
client = LinkisClient(config)
# 执行代码
# Execute code
code = "SELECT * FROM my_table LIMIT 10"
query_req = {
"columns": [{"column": "id"}, {"column": "name"}],
"filters": [{"column": "age", "operator": "gt", "value": 18}],
"orderbys": [{"column": "id", "ascending": True}],
"page": 1,
"page_size": 10
}
data, total, error = await client.execute_code(
code=code,
query_req=query_req,
engine_type="spark",
run_type="sql"
)
print(f"Total records: {total}")
print(f"Data: {data}")
if __name__ == "__main__":
asyncio.run(main())
带缓存的执行
Execution with Caching
SDK还支持使用Redis缓存执行结果,以提高性能:
The SDK also supports caching execution results with Redis to improve performance:
from redis import ConnectionPool
from linkis_python_sdk.client import LinkisClient
from linkis_python_sdk.config.config import LinkisConfig
# 创建Redis连接池
# Create Redis connection pool
redis_pool = ConnectionPool(host="localhost", port=6379, db=0)
# 创建配置
# Create configuration
config = LinkisConfig(
base_url="http://your-linkis-server/api/rest_j/v1",
username="your_username",
password="your_password"
)
# 创建带缓存的客户端
# Create client with caching
client = LinkisClient(
linkis_conf=config,
r_pool=redis_pool,
cache_expire=1800, # 缓存过期时间(秒)/ Cache expiration time (seconds)
cache_code_prefix="linkis:codecache" # 缓存键前缀 / Cache key prefix
)
# 执行带缓存的代码
# Execute code with caching
data, total, error = client.execute_code_with_cache(
code="SELECT * FROM my_table LIMIT 10",
query_req={"columns": [{"column": "id"}, {"column": "name"}]},
engine_type="spark",
run_type="sql"
)
依赖项
Dependencies
- Python >= 3.9
- requests
- pandas
- redis
- aiohttp
开发贡献
Development and Contribution
欢迎为Linkis Python SDK做出贡献!请参阅PUBLISH.md了解如何构建和发布该包。 Contributions to the Linkis Python SDK are welcome! Please refer to PUBLISH.md for information on how to build and publish the package.
许可证
License
该项目采用Apache License 2.0许可证。
This project is licensed under the Apache License 2.0.
Metadata
Release files for linkis-python-sdk 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| linkis_python_sdk-0.2.0.tar.gz | 14.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| linkis_python_sdk-0.2.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 29.0 kB
Release files / linkis_python_sdk-0.2.0.tar.gz
| Download URL | linkis_python_sdk-0.2.0.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
722f8104b745b09b31d2db1d8bce3030b33303a739d9a05711af116cf9abddc6
|
|
BLAKE2b-256 checksum How to use checksums |
874e870d0da6b34dc14b1dbd3f00f7932f33d3fff5b5b9e5db5b31487cf66434
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Release files / linkis_python_sdk-0.2.0-py2.py3-none-any.whl
| Download URL | linkis_python_sdk-0.2.0-py2.py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
f9ee5d679634c082e03265b7af13395de8cf2ce7d190da480b81e955f3fa52e5
|
|
BLAKE2b-256 checksum How to use checksums |
ba581dc6f524bff4ce502598e1f394a50a7a04a91da39949b78c8dc50693bc26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Security for linkis-python-sdk 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.