一个用于解析cURL命令的Python库
Project description
cURL 命令解析器
一个用于解析cURL命令行并将其转换为结构化数据的Python库。
特性
- 🔄 命令解析: 解析标准的 cURL 命令并提取关键信息
- 📊 结构化输出: 将解析结果转换为结构化的数据格式
- 🌐 多种输入: 支持命令行直接输入、文件读取和管道输入
- 📋 全面支持: 支持 HTTP 方法、请求头、Cookie、请求体等常见选项
- 🔍 参数提取: 自动解析 URL 查询参数和表单数据
- 🛠️ CLI 工具: 提供命令行工具,支持 JSON 和文本格式输出
支持的 cURL 选项
-X, --request: HTTP 请求方法 (GET, POST, PUT, DELETE 等)-H, --header: 请求头设置-d, --data: 请求体数据-b, --cookie: Cookie 设置-F, --form: 表单数据-u, --user: 用户认证-L, --location: 跟随重定向-k, --insecure: 忽略 SSL 证书验证-v, --verbose: 详细输出-o, --output: 输出到文件
安装
pip install easy-curl-parser
使用方法
命令行工具
# 直接解析 cURL 命令
python -m curl_parser.cli 'curl -H "Accept: application/json" https://api.example.com'
# 从文件读取 cURL 命令
python -m curl_parser.cli -f curl_command.txt
# 通过管道输入
echo 'curl https://example.com' | python -m curl_parser.cli
# JSON 格式输出
python -m curl_parser.cli -j 'curl https://example.com'
# 输出到文件
python -m curl_parser.cli -o result.txt 'curl https://example.com'
Python API
from curl_parser import parse_curl
# 解析cURL命令
curl_command = "curl 'http://example.com' -H 'Accept: application/json'"
result = parse_curl(curl_command)
# 获取解析后的数据
print(result.parsed_data.url) # http://example.com
print(result.parsed_data.headers) # {'Accept': 'application/json'}
数据结构
parse_curl 函数返回 CurlParseResult 对象,包含:
parsed_data: 解析后的数据,类型为ParsedCurlDataunresolved_data: 未被解析的数据
ParsedCurlData 包含以下字段:
url: 请求URLparams: URL查询参数headers: 请求头cookies: Cookiedata: 请求体数据request: 请求方法 (默认为 "GET")
示例
from curl_parser import parse_curl
curl_command = '''
curl 'http://localhost:155/common/sso/login?_t=1757126032510_JG9BY' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' \
-b 'locale=und' \
--data-raw 'username=erdcadmin&password=GaSkDZ2dZOmracDMTMoRy9uqMnxa46FK3OHnE1ppGbuz9clTDWb+nZDVdFqoatPL'
'''
result = parse_curl(curl_command)
print(result.parsed_data.url) # http://localhost:155/common/sso/login
print(result.parsed_data.params) # {'_t': '1757126032510_JG9BY'}
print(result.parsed_data.request) # POST
开发
安装开发依赖
git clone https://github.com/RosApr/curl-parser.git
cd curl-parser
pip install -e .
运行测试
python ./test/test_parser.py
许可证
MIT
贡献
欢迎提交问题和Pull Request!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easy_curl_parser-0.1.1.tar.gz.
File metadata
- Download URL: easy_curl_parser-0.1.1.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3eab3726afaa99f00ec62cd643ab6ff24e8a161631b1ae09a1a57ab6072a7d12
|
|
| MD5 |
d819d4aa95d7aed6e034afdd993ec809
|
|
| BLAKE2b-256 |
f82bea58d08e9b57d79a3cae6fc90eded11aff5b9e59d7377c1c0400aa0a595c
|
File details
Details for the file easy_curl_parser-0.1.1-py3-none-any.whl.
File metadata
- Download URL: easy_curl_parser-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ad0ed2cc597c1f7f83cf1cf9c065e0dfb9b6d85932be1038b07da48298cc3a7
|
|
| MD5 |
6b0785ff74c7259633e7359108cfa327
|
|
| BLAKE2b-256 |
4e8610db74dc10b40e3ec9e979cb8a0a3df2b2d4888d22e336c2eafff6eaf31e
|