快代理api SDK
依赖环境
python2.7 到 python3.7
从 快代理 购买相应产品
获取安装:
安装 Python SDK 前,请先获取订单对应的`secret_id`和`secret_key`,请严格保管,避免泄露。
通过pip安装(推荐)
- 您可以通过 pip 将SDK安装到您的项目中:
- pip install kdl
- 如果您的项目环境尚未安装 pip ,可参考:
Ubuntu/Debian安装pip:apt-get install python-setuptools
CentOS安装pip:yum install python-setuptools
MacOS安装pip: curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py; python get-pip.py
您还可以参考 pip官网 进行安装。
通过源码包安装
前往 Github 代码托管地址 下载最新代码,解压后:
$ cd api-sdk
$ python setup.py install
示例
以私密代理订单使用为例:
# -*- coding: utf-8 -*-
"""
私密代理使用示例
接口鉴权说明:
目前支持的鉴权方式有 "token" 和 "hmacsha1" 两种,默认使用 "token"鉴权。
所有方法均可添加关键字参数sign_type修改鉴权方式。
"""
import kdl
auth = kdl.Auth("secret_id", "secret_key")
client = kdl.Client(auth)
# 获取订单到期时间, 返回时间字符串
expire_time = client.get_order_expire_time()
print("expire time", expire_time)
# 获取ip白名单, 返回ip列表
ip_whitelist = client.get_ip_whitelist()
print("ip whitelist", ip_whitelist)
# 设置ip白名单,参数类型为字符串或列表或元组
# 成功则返回True, 否则抛出异常
client.set_ip_whitelist([])
client.set_ip_whitelist("127.0.0.1, 192.168.0.139")
print(client.get_ip_whitelist())
client.set_ip_whitelist(tuple())
# 提取私密代理ip, 第一个参数为提取的数量, 其他参数以关键字参数的形式传入(不需要传入signature和timestamp)
# 具体有哪些参数请参考帮助中心: "https://help.kuaidaili.com/api/getdps/"
# 返回ip列表
# 注意:若您使用的是python2, 且在终端调用,或在文件中调用且没有加 "# -*- coding: utf-8 -*-" 的话
# 传入area参数时,请传入unicode类型,如 area=u'北京,上海'
ips = client.get_dps(2, sign_type='hmacsha1', format='json', pt=2, area='北京,上海,广东')
print("dps proxy: ", ips)
# 检测私密代理有效性: 返回 ip: true/false 组成的dict
ips = client.get_dps(2, sign_type='token', format='json')
valids = client.check_dps_valid(ips)
print("valids: ", valids)
# 获取计数版ip余额(仅私密代理计数版)
balance = client.get_ip_balance(sign_type='hmacsha1')
print("balance: ", balance)
您可以在examples目录下找到更详细的示例
参考资料
Metadata
Release files for kdl 0.2.21
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 | |
|---|---|---|---|---|
| kdl-0.2.21.tar.gz | 9.5 kB | Without provenance | Details |
Release files / kdl-0.2.21.tar.gz
| Download URL | kdl-0.2.21.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
681bc8a18d1d59924e7d875c0b798d824491f3ede797a4df3355634c8ae5019c
|
|
BLAKE2b-256 checksum How to use checksums |
94358a16ba59c2fc1d266a1878519ccd74138a8d14338059d93a617836c39171
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/2.7
|
Security for kdl 0.2.21
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.