松智云 Python SDK
松智云网页截图 API 的 Python 客户端库。支持 Python 3.8+。
环境要求
- Python 3.8 或更高版本
- 松智云 API Key(免费注册获取)
安装
pip install songzhiyun
快速开始
from songzhiyun import SongzhiClient
client = SongzhiClient("sk-xxx")
result = client.screenshot("https://example.com")
print(result["imageUrl"])
# → /screenshots/d55c14ca.png
完整选项
from songzhiyun import SongzhiClient
client = SongzhiClient("sk-xxx")
result = client.screenshot(
"https://example.com",
width=1920,
height=1080,
full_page=True, # 全页长图
mobile=True, # 移动端模拟
wait_ms=2000, # 页面加载后额外等待
format="png", # png / jpeg / webp / pdf
quality=95, # 图片质量 1-100(jpeg/webp)
ad_block=True, # 广告拦截
watermark={
"text": "机密文档",
"position": "bottom-right", # top-left / top-right / center / bottom-left / bottom-right
"opacity": 50, # 0-100
},
)
print(result["imageUrl"])
Python SDK 自动将 snake_case 参数转换为 API 要求的 camelCase。
参数说明
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
width |
int | 1280 | 视口宽度(像素) |
height |
int | 720 | 视口高度(像素) |
full_page |
bool | False | 全页截图(长图) |
mobile |
bool | False | 移动端 User-Agent + 375 宽视口 |
wait_ms |
int | 0 | 页面加载后额外等待(毫秒) |
format |
str | "png" | 输出格式:png / jpeg / webp / pdf |
quality |
int | 90 | 图片质量 1-100(jpeg/webp) |
ad_block |
bool | True | 广告拦截 |
watermark |
dict | None | 水印配置 {"text":"...", "position":"...", "opacity":50} |
异步模式
# 提交任务(立即返回 taskId,不阻塞)
task = client.submit("https://example.com", width=1280, height=720)
print(f"taskId: {task['taskId']}")
# ... 做其他事情 ...
# 轮询直到完成
result = client.poll(task["taskId"], timeout=60, interval=1)
print(f"imageUrl: {result['imageUrl']}")
错误处理
from songzhiyun import SongzhiClient, SongzhiError
try:
result = client.screenshot("https://example.com")
except SongzhiError as e:
print(f"错误码: {e.code}, 消息: {e.message}")
错误码说明:
| 错误码 | 说明 |
|---|---|
| 1001 | 参数错误或资源不存在 |
| 1002 | 缺少认证信息 |
| 1003 | 本月配额已用完 |
| 1004 | 并发请求超限 |
| 1006 | 请求过于频繁 |
| 5000 | 服务器内部错误 |
相关链接
License
MIT
Metadata
Release files for songzhiyun 0.1.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 | Actions |
|---|---|---|---|---|
| songzhiyun-0.1.0.tar.gz | 3.7 kB | Without provenance | Details for songzhiyun-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| songzhiyun-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for songzhiyun-0.1.0-py3-none-any.whl |
Total release size: 7.8 kB
Release files / songzhiyun-0.1.0.tar.gz
| Download URL | songzhiyun-0.1.0.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd8cb1d3f589de5b83a59951fec8ba70b28a8405360c6a1460aa2995a51d28f1
|
|
BLAKE2b-256 checksum How to use checksums |
298a60889d918fd0731740892900b5df3c3502c77acda97282cca1f2854bc342
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Release files / songzhiyun-0.1.0-py3-none-any.whl
| Download URL | songzhiyun-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
14b5006a00185574340d9c70a24cd8f7b5e34ff66c0cee24908ad936f680c701
|
|
BLAKE2b-256 checksum How to use checksums |
6ba8eb1276cf14108067b2daf73497977fd629abe76531e5798e7c40c8fbcd75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Security for songzhiyun 0.1.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.