Skip to main content

Python工具集,包含飞书API、AutoDL API和日志工具

Project description

zdpytools

Python工具集,提供日志、飞书API和AutoDL API集成功能。

功能

  • 日志工具:基于loguru的简单易用的日志模块
  • 飞书API:飞书开放平台API的封装,支持多维表格操作
  • AutoDL API:基于httpx的AutoDL弹性部署API异步封装

安装

pip install zdpytools

使用示例

日志工具

from zdpytools.utils.log import logger

logger.info("这是一条信息日志")
logger.error("这是一条错误日志")

飞书API

import asyncio
from zdpytools.feishu import Feishu

async def example():
    fs = Feishu(app_id="你的飞书应用ID", app_secret="你的飞书应用密钥")
    try:
        # 查询多维表格记录
        result = await fs.bitable_records_search("app_token", "table_id")
        print(result)

        # 列出多维表格中的所有数据表
        tables = await fs.get_all_tables("app_token")
        for table in tables:
            print(f"表格ID: {table.get('id')}, 名称: {table.get('name')}")
    finally:
        await fs.close()

asyncio.run(example())

飞书多维表格API

列出数据表
# 基本用法,获取第一页数据表
result = await fs.list_tables(app_token="YOUR_APP_TOKEN")

# 指定页面大小
result = await fs.list_tables(
    app_token="YOUR_APP_TOKEN",
    page_size=5
)

# 使用分页标记获取下一页
if result.get("has_more") and result.get("page_token"):
    next_page = await fs.list_tables(
        app_token="YOUR_APP_TOKEN",
        page_token=result.get("page_token"),
        page_size=5
    )

# 获取所有数据表(自动处理分页)
all_tables = await fs.get_all_tables(app_token="YOUR_APP_TOKEN")

AutoDL API

import asyncio
from zdpytools.autodl import AutoDLClient
from zdpytools.utils.log import logger

async def example():
    # 可以直接传入token或者设置环境变量 AUTODL_TOKEN
    async with AutoDLClient() as client:
        try:
            # 获取GPU库存
            gpu_stock = await client.get_gpu_stock(
                region_sign="westDC2",
                cuda_v_from=117,
                cuda_v_to=128
            )

            for gpu_info in gpu_stock:
                for gpu_name, stock in gpu_info.items():
                    logger.info(f"GPU型号: {gpu_name}, 空闲数量: {stock.get('idle_gpu_num')}")
        except Exception as e:
            logger.error(f"获取GPU库存失败: {e}")

asyncio.run(example())

命名原则

根据 Python 的最佳实践和代码可读性,建议采用以下命名规范:

  1. 模块文件(.py文件)

    • 使用小写字母加下划线(snake_case)
    • 例如:feishu.py, webhook.py, const.py
    • 原因:这是 Python 社区的标准做法,符合 PEP 8 规范
  2. 类文件

    • 使用驼峰命名法(CamelCase)
    • 例如:BaseModel.py, FeishuBase.py
    • 原因:类名通常使用驼峰法,这样更容易识别类的定义
  3. 目录名

    • 使用小写字母加下划线
    • 例如:feishu/, utils/
    • 原因:保持与模块命名一致
  4. 特殊文件

    • __init__.py 保持原样(这是 Python 包的标准命名)
    • __pycache__ 保持原样(这是 Python 的标准目录)

这样的命名规范有以下优点:

  1. 符合 Python 社区规范
  2. 提高代码可读性
  3. 便于区分模块和类
  4. 保持一致性
  5. 避免命名冲突

封装更新

python build_package.py

许可证

MIT

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

zdpytools-0.1.34.tar.gz (34.3 kB view details)

Uploaded Source

Built Distribution

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

zdpytools-0.1.34-py3-none-any.whl (40.2 kB view details)

Uploaded Python 3

File details

Details for the file zdpytools-0.1.34.tar.gz.

File metadata

  • Download URL: zdpytools-0.1.34.tar.gz
  • Upload date:
  • Size: 34.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for zdpytools-0.1.34.tar.gz
Algorithm Hash digest
SHA256 497007de99b4f4845e4653080c4cb45d3dd5c5cd8598f7c0cf741aff4f245d52
MD5 3402430362f3b92efd6fb8ba6d62e28b
BLAKE2b-256 b7b5d06b54106c2dd1a41799105f93df64cf06b8f6046c381b29901540ff020c

See more details on using hashes here.

File details

Details for the file zdpytools-0.1.34-py3-none-any.whl.

File metadata

  • Download URL: zdpytools-0.1.34-py3-none-any.whl
  • Upload date:
  • Size: 40.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for zdpytools-0.1.34-py3-none-any.whl
Algorithm Hash digest
SHA256 150fd6175bdb1cb8eac08a8495cde72f55c01dec11d789a4e7a6cc5fcb946792
MD5 22fa1c68b0c3320f6ac4265b20f94a35
BLAKE2b-256 0b0e68f38db07c40570a1557f36456d6b5e25c5c001dc14f917f6da4f3c33732

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