从命令行调用asgipython应用程序,就像CURL一样

asgi-cli的Python项目详细描述


ASGI命令行

testsCoverage Statuspypi version

呼叫ASGI 命令行中的Python应用程序,就像CURL一样。在

如果您使用这个工具,★Star这个存储库来显示您的兴趣,请!在

安装

pip install -U asgi-cli

使用

^{pr2}$
usage: asgi-cli [-h] [-V] [-X COMMAND] [-H HEADER] [-d DATA | -F MULTIPART]
                [-I] [-b] [-p] [-n NUMBER] [-v]
                app [url]

positional arguments:
  app                   an application module
  url                   a uniform resource locator or path (default /)

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -X COMMAND, --request COMMAND
                        specify request command to use, e.g. POST (default
                        GET)
  -H HEADER, --header HEADER
                        pass custom header line, e.g. -H='Accept:
                        application/json'
  -d DATA, --data DATA  request body data, e.g. '{"msg":"hello"}', 'msg=hello'
  -F MULTIPART, --form MULTIPART
                        specify HTTP multipart POST data, e.g. name=value or
                        name=@file
  -I, --head            show status and headers only
  -b, --benchmark       issue a number of requests through repeated iterations
                        (reports throughtput and average call time)
  -p, --profile         prints out a report of top 10 functions ordered by
                        internal time, saves to 'stats.cprof' file
  -n NUMBER             a number of requests to issue (default 100K)
  -v, --verbose         make the operation more talkative

示例

示例.py

START={"type":"http.response.start","status":200,"headers":[(b"content-length",b"13"),(b"content-type",b"text/html; charset=utf-8"),],}BODY1={"type":"http.response.body","body":b"Hello"}BODY2={"type":"http.response.body","body":b", world!"}asyncdefapp(scope,receive,send)->None:awaitsend(START)awaitsend(BODY1)awaitsend(BODY2)

然后运行示例:

asgi-cli example:app打印响应正文:

Hello, world!

asgi-cli -v example:apppretty打印作用域并发送消息:

{'scope': {'asgi': {'spec_version': '2.1', 'version': '3.0'},
           'client': ('127.0.0.1', 49327),
           'headers': [(b'accept', b'*/*'),
                       (b'user-agent', b'asgi-cli/0.0.1'),
                       (b'host', b'127.0.0.1:8000')],
           'http_version': '1.1',
           'method': 'GET',
           'path': '/',
           'query_string': b'',
           'raw_path': b'/',
           'root_path': '',
           'scheme': 'http',
           'server': ('127.0.0.1', 8000),
           'type': 'http'}}
{'message': {'headers': [(b'content-length', b'13'),
                         (b'content-type', b'text/html; charset=utf-8')],
             'status': 200,
             'type': 'http.response.start'}}
{'message': {'body': b'Hello', 'type': 'http.response.body'}}
{'message': {'body': b', world!', 'type': 'http.response.body'}}

asgi-cli -b example:app显示执行状态(分3次迭代运行,每次迭代显示每秒的请求数和平均调用时间):

 #1 => 477.74K, 2.09μs
 #2 => 438.12K, 2.28μs
 #3 => 446.90K, 2.24μs

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
无法在Netbeans 8.2 JDK8u231中创建java Maven项目(Web应用程序)   java如何以设定的时间间隔生成随机数?   java从socket和inputStream的慢速读取   spring SCORM:Java中基于Web的SCORM播放器   Java将函数传递给方法   java绑定通用服务及其实现和子类型   java如何在运行时从选择列表框中动态选择选项?爪哇硒   java Selenium WebDriver什么是“Selenium客户端和WebDriver语言绑定”   elasticsearch需要elasticsearch高级Java客户端更新ByQueryRequest API帮助   JAVA哈希表查找最大值   WSDL操作中的java soapAction属性为空   java访问封闭类或父类方法的一般方法   eclipse在java中运行带有SeleneTestCase的ANT。lang.NoClassDefFoundError   java Hazelcast不会在节点启动时填充ReplicatedMap   如何在Java中从excel中读取特定行?   html JAVA将本地时间(GMT+8)转换为UTC时间   java将自定义端点添加到Spring数据REST存储库中,并以大摇大摆的方式显示   java计算未来位置