跳转到主要内容

使用Python编写的简单模块化API。

项目描述

PyPi TravisCI CodeCov

Smapy

使用Python编写的简单模块化API。

概述

Smapy 是一个基于 Falcongunicorn 的框架,它允许尽可能少地编写Python代码来构建模块化、分布式和异步的面向服务的Web API。

安装

安装 Smapy 最简单和推荐的方式是使用 pip

pip install smapy

或者,克隆存储库并执行 make install 命令从源代码安装。

git clone git@github.com:smapy/smapy.git
cd smapy
make install

对于开发,您可以使用 make install-develop 命令来安装所有测试和代码检查所需依赖。

入门

要开始一个 Smapy 应用程序,您需要执行 smapy 命令行工具。

$ smapy
[2018-12-29 21:53:03 +0100] [25213] [INFO] Starting gunicorn 19.9.0
[2018-12-29 21:53:03 +0100] [25213] [INFO] Listening at: http://127.0.0.1:8001 (25213)
[2018-12-29 21:53:03 +0100] [25213] [INFO] Using worker: gevent
[2018-12-29 21:53:03 +0100] [25216] [INFO] Booting worker with pid: 25216
2018-12-29 21:53:03,304 - 25216 - INFO - None - application - Initializing the API
2018-12-29 21:53:03,307 - 25216 - INFO - None - api - Adding new runnable hello.World
2018-12-29 21:53:03,307 - 25216 - INFO - None - api - Adding new runnable misc.MultiProcess
2018-12-29 21:53:03,307 - 25216 - INFO - None - api - Adding new runnable misc.Report
2018-12-29 21:53:03,308 - 25216 - INFO - None - api - Adding new runnable misc.HelloWorld

之后,您可以通过HTTP请求开始玩。

$ curl localhost:8001/hello
{
    "elapsed": 0.08,
    "host": "hostname",
    "in_ts": "2018-05-06T20:37:48.671867",
    "out_ts": "2018-05-06T20:37:48.671947",
    "pid": 31789,
    "results": null,
    "session": null,
    "status": "404 Not Found"
}

$ curl localhost:8001/hello_world
{
    "elapsed": 12.044,
    "host": "hostname",
    "in_ts": "2018-05-06T20:37:58.759039",
    "out_ts": "2018-05-06T20:37:58.771083",
    "pid": 31789,
    "results": null,
    "session": "5aef67a6ab17857c2d81a6ea",
    "status": "200 OK"
}

$ curl localhost:8001/hello_world?sync=True
{
    "elapsed": 26.668,
    "host": "hostname",
    "in_ts": "2018-05-06T20:38:03.903315",
    "out_ts": "2018-05-06T20:38:03.929983",
    "pid": 31789,
    "results": {
        "hello": "world!",
        "sync": "True"
    },
    "session": "5aef67abab17857c2d81a6ec",
    "status": "200 OK"
}

$ curl localhost:8001/report?session=5aef67a6ab17857c2d81a6ea
{
    "elapsed": 19.758,
    "host": "hostname",
    "in_ts": "2018-05-06T20:39:49.670267",
    "out_ts": "2018-05-06T20:39:49.690025",
    "pid": 31789,
    "results": {
        "actions": {
            "OK": 1
        },
        "last_activity": "2018-05-06T20:37:58.812000",
        "session": {
            "_id": "5aef67a6ab17857c2d81a6ea",
            "alive": false,
            "body": {},
            "elapsed": "0:00:00.058000",
            "env": {
                "HTTP_ACCEPT": "*/*",
                "HTTP_HOST": "localhost:8001",
                "HTTP_USER_AGENT": "curl/7.47.0",
                "PATH_INFO": "/hello_world",
                "QUERY_STRING": "",
                "RAW_URI": "/hello_world",
                "REMOTE_ADDR": "127.0.0.1",
                "REMOTE_PORT": "50636",
                "REQUEST_METHOD": "GET",
                "SCRIPT_NAME": "",
                "SERVER_NAME": "127.0.0.1",
                "SERVER_PORT": "8001",
                "SERVER_PROTOCOL": "HTTP/1.1",
                "SERVER_SOFTWARE": "gunicorn/19.8.1"
            },
            "host": "hostname",
            "in_ts": "2018-05-06T20:37:58.759000",
            "out_ts": "2018-05-06T20:37:58.817000",
            "params": {},
            "pid": 31789,
            "resource": "misc.HelloWorld",
            "response": {
                "hello": "world!"
            },
            "status": "OK",
            "sync": false
        },
        "session_data": {
            "links": 0,
            "occurrences": 0,
            "post": 0
        }
    },
    "session": "5aef6815ab17857c2d81a6ef",
    "status": "200 OK"
}

历史

0.0.3

新发布脚本。

0.0.2

  • 添加 smapy CLI
  • 添加默认操作和资源
  • 动态导入操作
  • 更新项目结构

0.0.1

  • 首次在PyPI上发布。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

smapy-0.0.3.tar.gz (33.3 kB 查看哈希值)

上传时间 源代码

构建分发

smapy-0.0.3-py2.py3-none-any.whl (18.4 kB 查看哈希值)

上传时间 Python 2 Python 3

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页