Skip to main content

一个功能丰富的工具包

Project description

pip_darren

Python HTTP Crypto

一个面向爬虫与自动化场景的 Python 工具库,提供:

  • 常见加密能力(AES / DES / 3DES / RC4 / RSA / SM2 / SM3 / SM4)
  • 哈希与签名(HASH / HMAC)
  • HTTP 请求封装(httpx,支持 Session 与非 Session)
  • 代理池工具(自动拉取、验证、获取代理)
  • 字符串与时间工具
  • 设备信息采集(OS/CPU/GPU/BIOS/主板/磁盘/MAC/UUID)

目录


安装

方式 A:requirements

pip install -r requirements.txt

方式 B:本地开发安装

pip install -e .

快速开始

import darren

AES 示例

cipher = darren.aes.encry("cbc", "hello", "1234567890abcdef", "abcdef1234567890", "pkcs7")
plain = darren.aes.decry("cbc", cipher, "1234567890abcdef", "abcdef1234567890", "pkcs7")
print(cipher, plain)

HASH / HMAC

print(darren.hash.sha256("hello"))
sign = darren.hmac.sha256("hello", "my-key")
print(darren.hmac.verify("sha256", "hello", "my-key", sign, "hex"))

HTTP(httpx-only)

非 Session(一次性请求)

r = darren.http.get("https://example.com", timeout=10, max_retries=1)
print(None if r is None else r.status_code)
if r:
    print(r.text_trunc(120))
    print(r.ok_json(default={}))

Session(Client)模式

session = darren.http.Session(enable_detailed_logging=True, http2=False)
try:
    r = session.get("https://example.com", cookies="a=1; b=2", task_id="demo")
    print(None if r is None else r.status_code)
finally:
    session.close()

下载文件

ok = darren.http.download(
    url="https://example.com",
    save_path="http_logs/example_download.html",
    timeout=10,
    max_retries=0,
    task_id="download_demo",
)
print(ok)

代理工具

# 手动塞入一个代理(测试用)
darren.proxy.add_proxy("127.0.0.1:8080")

# 获取 requests/httpx 可直接使用的代理字典
proxy_dict = darren.proxy.get_one_proxy(timeout=0)
print(proxy_dict)

设备信息

info = darren.device.get_device_info()
print(info["os"])
print(info["cpu"])
print(info["bios"])
print(info["uuid"])

主要模块

  • darren.aes:AES 加解密(支持模式/填充/多输出格式)
  • darren.des / darren.triple_des:DES / 3DES
  • darren.rc4:RC4
  • darren.rsa:RSA 密钥生成、加解密、签名验签
  • darren.sm2 / darren.sm3 / darren.sm4:国密算法
  • darren.hash / darren.hmac:摘要与 HMAC
  • darren.http:httpx 封装(Session/非 Session、下载、安全 JSON、文本截断)
  • darren.proxy:代理管理(添加、获取、动态切换配置)
  • darren.string:字符串工具
  • darren.time:时间工具
  • darren.device:设备信息采集

测试

项目内置了一个非 pytest 的冒烟脚本:

python Test.py

会打印各模块调用结果与基础断言状态。


版本更新

v0.1.x(当前)

  • 统一加密模块能力(AES / DES / 3DES / RC4 / RSA / SMx)
  • HTTP 封装迁移到 httpx(移除 requests 运行时依赖)
  • 代理模块内部请求改为 httpx
  • 新增 DeviceUtils(含 BIOS / 主板 / UUID / 硬盘等原始字段)
  • 完善 Test.py,支持一键冒烟验证

FAQ

1)为什么有些设备字段为空?

不同系统、权限和硬件厂商对序列号暴露程度不同,字段为空是正常现象。建议你组合多个字段做机器指纹。

2)HTTPX download ok = False 是 bug 吗?

不一定。通常是目标 URL 不支持下载、被重定向策略限制、网络环境受限等导致。返回 False 代表下载失败但流程安全退出。

3)代理必须用 Redis 吗?

不是。默认是内存模式。需要 Redis 时可在 ProxyConfig 中显式启用。


注意事项

  • 部分设备字段(如磁盘序列号、BIOS 序列号)在不同系统/权限下可能为空,这是正常现象。
  • 国密相关需要 gmssl
  • 如需 socks5:// 代理,请确保环境包含 socksio(httpx 对应依赖)。

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

darren_utils-0.2.1.303.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

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

darren_utils-0.2.1.303-py3-none-any.whl (40.1 kB view details)

Uploaded Python 3

File details

Details for the file darren_utils-0.2.1.303.tar.gz.

File metadata

  • Download URL: darren_utils-0.2.1.303.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for darren_utils-0.2.1.303.tar.gz
Algorithm Hash digest
SHA256 1104112a457bee22455cbd36f6a20f88dfba5047c06760f2c3c0cde489a4cc5a
MD5 1fa17472b17f87fcdacdc176170d1e94
BLAKE2b-256 56a41a6673d350db5575b6928bbd8b33f551a82f6c39a32335fd5605f67528fd

See more details on using hashes here.

File details

Details for the file darren_utils-0.2.1.303-py3-none-any.whl.

File metadata

File hashes

Hashes for darren_utils-0.2.1.303-py3-none-any.whl
Algorithm Hash digest
SHA256 15debaadae87d1d81378e8618ce6feca681d8c5ea005174e991ee80471a4520a
MD5 a82d1a2ff7f7804b7b2ab18dae6b09bb
BLAKE2b-256 d25b745d22e2790ad99f5dd82a4c67c17150dba8329742dd77778aaa6a2d2a40

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