Skip to main content

A Python SDK for tracking API requests

Project description

ydapi_sdk

这个sdk用于ydapi平台记录api访问数据,方便用户便捷使用和分析接口的访问情况

安装

  1. 这里下载SDK包 .
  2. 使用pip安装软件包:
    pip install ydapi-sdk
    

集成

首先你要从ydapi平台申请一个密钥!

示例代码

# 导入 YdSDKClient 类
from ydapi_sdk.client import YdSDKClient

# 初始化 SDK 客户端
api_key = "your_api_key"
client = YdSDKClient(api_key)


# 1. 发送 GET 请求
def send_get_request():
   url = "https://example.com/api/data"
   params = {
      "param1": "value1",
      "param2": "value2"
   }
   headers = {
      "Custom-Header": "Custom-Value"
   }
   try:
      response = client.get(url, params=params, headers=headers)
      print("GET 请求响应:", response)
   except Exception as e:
      print("GET 请求出错:", e)


# 2. 发送 POST 请求
def send_post_request():
   url = "https://example.com/api/create"
   data = {
      "key1": "value1",
      "key2": "value2"
   }
   headers = {
      "Custom-Header": "Custom-Value"
   }
   try:
      response = client.post(url, data=data, headers=headers)
      print("POST 请求响应:", response)
   except Exception as e:
      print("POST 请求出错:", e)


# 3. 发送 PUT 请求
def send_put_request():
   url = "https://example.com/api/update/1"
   json_data = {
      "field1": "new_value1",
      "field2": "new_value2"
   }
   headers = {
      "Custom-Header": "Custom-Value"
   }
   try:
      response = client.put(url, json=json_data, headers=headers)
      print("PUT 请求响应:", response)
   except Exception as e:
      print("PUT 请求出错:", e)


# 4. 发送 DELETE 请求
def send_delete_request():
   url = "https://example.com/api/delete/1"
   headers = {
      "Custom-Header": "Custom-Value"
   }
   try:
      response = client.delete(url, headers=headers)
      print("DELETE 请求响应:", response)
   except Exception as e:
      print("DELETE 请求出错:", e)


# 5. 发送 PATCH 请求
def send_patch_request():
   url = "https://example.com/api/partial-update/1"
   json_data = {
      "field1": "updated_value1"
   }
   headers = {
      "Custom-Header": "Custom-Value"
   }
   try:
      response = client.patch(url, json=json_data, headers=headers)
      print("PATCH 请求响应:", response)
   except Exception as e:
      print("PATCH 请求出错:", e)


# 执行各个请求示例
send_get_request()
send_post_request()
send_put_request()
send_delete_request()
send_patch_request()

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

ydapi_sdk-0.1.4.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

ydapi_sdk-0.1.4-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file ydapi_sdk-0.1.4.tar.gz.

File metadata

  • Download URL: ydapi_sdk-0.1.4.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for ydapi_sdk-0.1.4.tar.gz
Algorithm Hash digest
SHA256 a0dc3854888fc4c84a9ea12356b15507cd3894290e19958aba768e8c88d9bdd5
MD5 82e24d78f791dd01412226e6ac699ff5
BLAKE2b-256 e2d0e11d456d99c5479551506d4e1d28dd806d02116db0574b93d66b3d14ffae

See more details on using hashes here.

File details

Details for the file ydapi_sdk-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: ydapi_sdk-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for ydapi_sdk-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c540245687da033e0f7f12ed9dcce3cdf795f8c07aeb2f31a377caa942a2f20e
MD5 00f7ce2091c31ea89ee73d5cbb774368
BLAKE2b-256 e32386cc24a73a9a7e5c5f59044770e19f73052a259da78b5f4d652169a6257d

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