curl-to-json


Namecurl-to-json JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/KingJem/curl-to-json
SummaryConvert curl command to json data
upload_time2024-12-01 16:49:54
maintainerNone
docs_urlNone
authorKingJem
requires_python<4.0,>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## Trans curl request to  json data

将参数转化为json 的时候尽量使用 -- 之后的值,作为字典的键。
这个库的目的是将curl 发送请求的参数转化为json 格式,方便在python 中使用。

curl 功能很强大,支持的参数也很多,这里只做了部分的解析

重点放在curl HTTP发送请求的方面.

其他一些特性,--ipv4,--ipv6,本地文件读取,指定dns 寻址服务器
DoH,ftp 等协议暂未支持

支持的参数

- `-X`, `  --request` 支持的请求方法,

- `--http2` 是否使用http2 协议 默认为否

- `-d`,`--data` 支持, 支持在一行命令中多次使用`-d` 参数,此时HTTP 请求头中
  `Content-Type : application/x-www-form-urlencoded`

  使用该参数,请求自动转化为POST.

- `-H`,`--header`  添加HTTP请求头,支持多行

- `-I`,`--head` 发送HEAD请求,并打印header,支持

- `-s`,`--silent`, 不输出任何东西,只返回HTTP 头

- `-v`, `--verbose` 输出通信的整个过程,用于调试

- `-b`, `--cookie` cookie 支持多个-b 参数,不支持文件读取

- `-A`, `--user-agent` 设置User-Agent,curl 默认的User-Agent 为 curl/version,本项目默认为空

- `--compressed` 是否压缩请求

- `-k`, `--insecure` 允许不验证服务器的证书

- `-u`, `--user` 用户名:密码

- `-L`, `--location` 允许自动跟随重定向

- `-I`,`--include` 打印头信息

- `-x`,`--proxy` 使用代理 代理 格式为:hostname:port,如果没有scheme 默认使用http

- `-U`, `--proxy-user` 代理用户名密码 ,格式为:username:password 如果有会自动将账号密码添加到代理url 中

- `-u`, `--user` basic 认证,格式为:username:password,输出为headers 中的Authorization

- `--connect-timeout` 连接超时时间

- `--referer` 请求头中的referer

## usage

1. 命令行中使用
```shell
python -m curl_to_json  curl_to_json curl -X GET http://example.com
```
2. 也可以直接使用 
```shell
curl_to_json curl -X GET http://example.com
```

3. 也可以使用 以下格式
```shell
curl_to_json "curl -X GET http://example.com"
```

4. 在python 代码中使用
```python
from curl_to_json import parse

cmd = 'curl -X GET http://example.com'

print(parse(cmd))

```

       
## Reference

*1. [curl 的用法指南](https://www.ruanyifeng.com/blog/2019/09/curl-reference.html)*

*2. [Linux命令大全-curl](https://hezhiqiang.gitbook.io/linux/ming-ling/curl)*

*3. [Uncurl](https://github.com/spulec/uncurl)*

*4. [curl 在线手册](https://man.cx/curl)*


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/KingJem/curl-to-json",
    "name": "curl-to-json",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "KingJem",
    "author_email": "qqqivy@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/df/93/bae9a22b311b067e421a2ee29ce3594de687ec00ca1973fd632c5adee24d/curl_to_json-0.1.0.tar.gz",
    "platform": null,
    "description": "## Trans curl request to  json data\n\n\u5c06\u53c2\u6570\u8f6c\u5316\u4e3ajson \u7684\u65f6\u5019\u5c3d\u91cf\u4f7f\u7528 -- \u4e4b\u540e\u7684\u503c\uff0c\u4f5c\u4e3a\u5b57\u5178\u7684\u952e\u3002\n\u8fd9\u4e2a\u5e93\u7684\u76ee\u7684\u662f\u5c06curl \u53d1\u9001\u8bf7\u6c42\u7684\u53c2\u6570\u8f6c\u5316\u4e3ajson \u683c\u5f0f\uff0c\u65b9\u4fbf\u5728python \u4e2d\u4f7f\u7528\u3002\n\ncurl \u529f\u80fd\u5f88\u5f3a\u5927\uff0c\u652f\u6301\u7684\u53c2\u6570\u4e5f\u5f88\u591a\uff0c\u8fd9\u91cc\u53ea\u505a\u4e86\u90e8\u5206\u7684\u89e3\u6790\n\n\u91cd\u70b9\u653e\u5728curl HTTP\u53d1\u9001\u8bf7\u6c42\u7684\u65b9\u9762.\n\n\u5176\u4ed6\u4e00\u4e9b\u7279\u6027\uff0c--ipv4,--ipv6,\u672c\u5730\u6587\u4ef6\u8bfb\u53d6\uff0c\u6307\u5b9adns \u5bfb\u5740\u670d\u52a1\u5668\nDoH,ftp \u7b49\u534f\u8bae\u6682\u672a\u652f\u6301\n\n\u652f\u6301\u7684\u53c2\u6570\n\n- `-X`, `  --request` \u652f\u6301\u7684\u8bf7\u6c42\u65b9\u6cd5\uff0c\n\n- `--http2` \u662f\u5426\u4f7f\u7528http2 \u534f\u8bae \u9ed8\u8ba4\u4e3a\u5426\n\n- `-d`,`--data` \u652f\u6301, \u652f\u6301\u5728\u4e00\u884c\u547d\u4ee4\u4e2d\u591a\u6b21\u4f7f\u7528`-d` \u53c2\u6570\uff0c\u6b64\u65f6HTTP \u8bf7\u6c42\u5934\u4e2d\n  `Content-Type : application/x-www-form-urlencoded`\n\n  \u4f7f\u7528\u8be5\u53c2\u6570\uff0c\u8bf7\u6c42\u81ea\u52a8\u8f6c\u5316\u4e3aPOST.\n\n- `-H`,`--header`  \u6dfb\u52a0HTTP\u8bf7\u6c42\u5934,\u652f\u6301\u591a\u884c\n\n- `-I`,`--head` \u53d1\u9001HEAD\u8bf7\u6c42\uff0c\u5e76\u6253\u5370header\uff0c\u652f\u6301\n\n- `-s`,`--silent`, \u4e0d\u8f93\u51fa\u4efb\u4f55\u4e1c\u897f\uff0c\u53ea\u8fd4\u56deHTTP \u5934\n\n- `-v`, `--verbose` \u8f93\u51fa\u901a\u4fe1\u7684\u6574\u4e2a\u8fc7\u7a0b\uff0c\u7528\u4e8e\u8c03\u8bd5\n\n- `-b`, `--cookie` cookie \u652f\u6301\u591a\u4e2a-b \u53c2\u6570\uff0c\u4e0d\u652f\u6301\u6587\u4ef6\u8bfb\u53d6\n\n- `-A`, `--user-agent` \u8bbe\u7f6eUser-Agent,curl \u9ed8\u8ba4\u7684User-Agent \u4e3a curl/version,\u672c\u9879\u76ee\u9ed8\u8ba4\u4e3a\u7a7a\n\n- `--compressed` \u662f\u5426\u538b\u7f29\u8bf7\u6c42\n\n- `-k`, `--insecure` \u5141\u8bb8\u4e0d\u9a8c\u8bc1\u670d\u52a1\u5668\u7684\u8bc1\u4e66\n\n- `-u`, `--user` \u7528\u6237\u540d:\u5bc6\u7801\n\n- `-L`, `--location` \u5141\u8bb8\u81ea\u52a8\u8ddf\u968f\u91cd\u5b9a\u5411\n\n- `-I`,`--include` \u6253\u5370\u5934\u4fe1\u606f\n\n- `-x`\uff0c`--proxy` \u4f7f\u7528\u4ee3\u7406 \u4ee3\u7406 \u683c\u5f0f\u4e3a\uff1ahostname:port\uff0c\u5982\u679c\u6ca1\u6709scheme \u9ed8\u8ba4\u4f7f\u7528http\n\n- `-U`, `--proxy-user` \u4ee3\u7406\u7528\u6237\u540d\u5bc6\u7801 ,\u683c\u5f0f\u4e3a\uff1ausername:password \u5982\u679c\u6709\u4f1a\u81ea\u52a8\u5c06\u8d26\u53f7\u5bc6\u7801\u6dfb\u52a0\u5230\u4ee3\u7406url \u4e2d\n\n- `-u`, `--user` basic \u8ba4\u8bc1\uff0c\u683c\u5f0f\u4e3a\uff1ausername:password\uff0c\u8f93\u51fa\u4e3aheaders \u4e2d\u7684Authorization\n\n- `--connect-timeout` \u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\n\n- `--referer` \u8bf7\u6c42\u5934\u4e2d\u7684referer\n\n## usage\n\n1. \u547d\u4ee4\u884c\u4e2d\u4f7f\u7528\n```shell\npython -m curl_to_json  curl_to_json curl -X GET http://example.com\n```\n2. \u4e5f\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 \n```shell\ncurl_to_json curl -X GET http://example.com\n```\n\n3. \u4e5f\u53ef\u4ee5\u4f7f\u7528 \u4ee5\u4e0b\u683c\u5f0f\n```shell\ncurl_to_json \"curl -X GET http://example.com\"\n```\n\n4. \u5728python \u4ee3\u7801\u4e2d\u4f7f\u7528\n```python\nfrom curl_to_json import parse\n\ncmd = 'curl -X GET http://example.com'\n\nprint(parse(cmd))\n\n```\n\n       \n## Reference\n\n*1. [curl \u7684\u7528\u6cd5\u6307\u5357](https://www.ruanyifeng.com/blog/2019/09/curl-reference.html)*\n\n*2. [Linux\u547d\u4ee4\u5927\u5168-curl](https://hezhiqiang.gitbook.io/linux/ming-ling/curl)*\n\n*3. [Uncurl](https://github.com/spulec/uncurl)*\n\n*4. [curl \u5728\u7ebf\u624b\u518c](https://man.cx/curl)*\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Convert curl command to json data",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/KingJem/curl-to-json",
        "Repository": "https://github.com/KingJem/curl-to-json"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8f919ac26fe51e5821d75287657c97c06c0cbb0350faef12b7158a6cc54810ea",
                "md5": "11693abb2899a4959d2c12cf5a79bb9c",
                "sha256": "413ca8999f9dc4d2fe00607bd1d1cd58791ae0f8b10ddb56f38975999a4f9eff"
            },
            "downloads": -1,
            "filename": "curl_to_json-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "11693abb2899a4959d2c12cf5a79bb9c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 5186,
            "upload_time": "2024-12-01T16:49:53",
            "upload_time_iso_8601": "2024-12-01T16:49:53.107698Z",
            "url": "https://files.pythonhosted.org/packages/8f/91/9ac26fe51e5821d75287657c97c06c0cbb0350faef12b7158a6cc54810ea/curl_to_json-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "df93bae9a22b311b067e421a2ee29ce3594de687ec00ca1973fd632c5adee24d",
                "md5": "c17c7cdd9d67c1f2e20c8e24186bded9",
                "sha256": "467270f94e7aab2af71e927fd6e310b1ee0cdabaa380b53bdf7607bc30c37f26"
            },
            "downloads": -1,
            "filename": "curl_to_json-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c17c7cdd9d67c1f2e20c8e24186bded9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 4313,
            "upload_time": "2024-12-01T16:49:54",
            "upload_time_iso_8601": "2024-12-01T16:49:54.340922Z",
            "url": "https://files.pythonhosted.org/packages/df/93/bae9a22b311b067e421a2ee29ce3594de687ec00ca1973fd632c5adee24d/curl_to_json-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-01 16:49:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "KingJem",
    "github_project": "curl-to-json",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "curl-to-json"
}
        
Elapsed time: 1.00218s