Skip to main content

一个轻量级的 wsgi web 框架

项目描述

构建状态 构建状态 覆盖状态 PyPI - 许可证 Python 版本 开源之爱 文件状态

Eynnyd Web 框架徽标

Eynnyd 网络框架

Eynnyd(发音为 [Ey-nahyd])是Everything You Need,Nothing You Don't的首字母缩写词。它是一个轻量级的 WSGI 兼容 python 3 web 框架。Eynnyd 的主要目标是不将错误的工程决策强加给用户。它还旨在不超越或假设用户的需求。

简单和自由是设计

如果以下听起来不错,这就是您的框架:

  • 您被允许但不会被迫遵循 REST。
  • Arequest handler接受 arequest并返回 a response
  • Arequest interceptor接受 arequest并返回 a request
  • Aresponse interceptor接受 arequest和 aresponse并返回 a response
  • 您可以有任意数量的request interceptorsrequest handlersresponse interceptors
  • 您可以随意命名您的处理程序方法。
  • 您可以限制任何拦截器的范围(它适用的路径)。
  • 我们不提供无关的依赖或意见(如数据库连接库或模板引擎)
  • 没有Eynnyd 做事的方法。
  • 没有什么聪明魔法。(如全局单例或特殊装饰器)
  • 您可以在主目录中简洁地查看整个路由布局。

如果这听起来不错,我们建议您继续阅读,看看 Eynnyd 还能为您提供什么。

文件

阅读eynnyd.readthedocs.io上的文档

如何安装它

Eynnyd 已发布到 pypi,可以使用以下命令安装:

pip install eynnyd

如何使用它

Eynnyd 没有内置 WSGI HTTP 服务器。我们推荐 gunicorn来运行您的应用程序。

一个简单的 hello world 示例如下所示:

# hello_world_app.py
from eynnyd import RoutesBuilder
from eynnyd import EynnydWebappBuilder
from eynnyd import ResponseBuilder
from http import HTTPStatus

def hello_world(request):
    return ResponseBuilder()\
        .set_status(HTTPStatus.OK)\
        .set_utf8_body("Hello World")\
        .build()


def build_application():
    routes = \
        RoutesBuilder()\
            .add_handler("GET", "/hello", hello_world)\
            .build()

    return EynnydWebappBuilder()\
            .set_routes(routes)\
            .build()

application = build_application()

使用 gunicorn 现在可以运行它gunicorn hello_world_app

拦截器示例

# hello_world_app.py
import logging

from eynnyd import RoutesBuilder
from eynnyd import EynnydWebappBuilder
from eynnyd import ResponseBuilder
from http import HTTPStatus

LOG = logging.getLogger("hello_world_app")

def hello_world(request):
    return ResponseBuilder()\
        .set_status(HTTPStatus.OK)\
        .set_utf8_body("Hello World")\
        .build()

def log_request(request):
    LOG.info("Got Request: {r}".format(r=request))
    return request

def log_response(request, response):
    LOG.info("Built Response: {s} for Request: {r}".format(s=response, r=request))
    return response

def build_application():
    routes = \
        RoutesBuilder()\
            .add_request_interceptor("/hello", log_request)\
            .add_handler("GET", "/hello", hello_world)\
            .add_response_interceptor("/hello", log_response)\
            .build()

    return EynnydWebappBuilder()\
            .set_routes(routes)\
            .build()

application = build_application()

对于开发者/贡献者

安装要求

跑:

pip install -r test_requirements.txt

运行测试

安装要求后运行:

python -m unittest discover tests

检查覆盖率

安装要求后运行:

coverage run --source eynnyd/ -m unittest discover tests/
coverage report

项目详情


下载文件

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

源分布

eynnyd-0.4.1.tar.gz (38.8 kB 查看哈希

已上传 source

内置分布

eynnyd-0.4.1-py3-none-any.whl (62.8 kB 查看哈希

已上传 py3