Giter Site home page Giter Site logo

abersheeran / kui Goto Github PK

View Code? Open in Web Editor NEW
281.0 7.0 25.0 4.83 MB

An easy-to-use web framework. Supports both WSGI and ASGI modes. Gevent or asyncio, this is the question.

Home Page: https://kui.aber.sh

License: Apache License 2.0

Python 99.04% HTML 0.96%
asgi http websocket web-framework openapi3 asynchronous radix-tree wsgi

kui's Introduction

Kuí

Codecov PyPI - Python Version

An easy-to-use web framework. Based on baize and pydantic.

Install

pip install kui

kui's People

Contributors

abersheeran avatar dependabot[bot] avatar gjj121785021 avatar kkw1201 avatar leng-yue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

kui's Issues

更改默认路由机制

#12 在这里我实现了基于 Radix Tree 的路由。

为了这口醋,我再去包一锅饺子不太好,并且 index.py 有许多地方与 IndexFile 不是强耦合的。考虑更改默认的路由机制为列表申明式与装饰器式。IndexFile 作为 Application 存在,通过 mount 组合进行请求处理。这样既可以保持 php 风格的文件映射,又可以让路由更加灵活的应对不同需求。

Use `name: Annotated[type, Query(**options)]` replace `name: type = Query(**options)`

Checklist

  • There are no similar issues or pull requests for this yet.
  • I discussed this idea on the community chat and feedback is positive.

Is your feature related to a problem? Please describe.

使用默认值为类型增加描述是妥协的做法。

Describe the solution you would like.

async def function(name: name: Annotated[type, Query(**options)]) -> Annotated[Any, PlainTextResponse[200]]:
     return name

Describe alternatives you considered

Query[type, options]

使用这种方式,编辑器支持不会很好。因为不能传关键词,所以 options 要么是一个充满 None 的序列,要么是一个字典。写起来都不会太舒服。

新手教程

使用 index.py 编写一个网站,用作新手教程。

特例化 `""` 路由

在某些情况下需要如下例代码来同时注册 "/user""/user/login" 两个路由。故而仅允许 "" 不以 "/" 开头。

"/user" // Routes(
    HttpRoute("", ......),
    HttpRoute("/login", ......),
)

在根上的 "" 跟随浏览器行为,自动转换为 "/" 路由。即 app.router << HttpRoute("", ......) 等价于 app.router << HttpRoute("/", ......)

参数路由与准确路由同时添加,准确路由有可能被覆盖

from indexpy.routing.tree import RadixTree
t = RadixTree()

def donothing():
    pass

def donothing2():
    pass

# 交换下面两个路由的顺序,断言可以通过
t.append("/app/{hello}/", donothing)
t.append("/app/hello/", donothing2)

ret = t.search("/app/world/")
print(ret)   # ({'hello': 'world'}, <function donothing at 0x7f12c94931f0>)
assert ret[1] == donothing

ret = t.search("/app/hello/")
print(ret)  # ({'hello': 'hello'}, <function donothing at 0x7f12c94931f0>)
assert ret[1] == donothing2

期望的行为应该类似于 flask 如下:

curl xxxx/a1/hello/ ==> hello2
curl xxxx/a1/world/ ==> hello1
from flask import Flask

app = Flask(__name__)


@app.route("/a1/<hello>/")
def hello1(hello):
    return "hello1"

@app.route("/a1/hello/")
def hello2():
    return "hello2"

app.run()

另外这里

https://github.com/abersheeran/index.py/blob/e895d06ec26bdb4196f919229417b424f5e066a2/indexpy/routing/tree.py#L57-L66

检查路由冲突的地方

第 60 行的 if (node.re_pattern == re_pattern) != (node.characters == param_name): 会不会有 re_pattern 不同, 而 characters == param_name 相同的情况?(这一块没太看懂)

缩小 Config 的影响范围

indexpy.config.Configindexpy.application.Index 等程序中抽离,改用普通参数进行配置。去除中间件配置,需要主动导入中间件并自行配置。

保留 Config,但仅用于 index-cli

使用 BaíZé 重构

由于 Starlette 本身现在更像是一个框架而不是一个工具箱,并且 encode 团队似乎没有太多的时间维护这个框架,更多的精力都在 httpx 上。所以直接放弃使用 Starlette,转而使用 BaíZé 进行重构。除部分响应类外,大部分接口仍然可以保持一致。并且相较于 Starlette,BaíZé 有更丰富的功能支持,比如文件响应允许分片、更加完善的响应类泛型。

官网文档当中有错误

自定义异常处理——>示例代码当中需要from indexpy.types import Request, Response
但是最新版当中indexpy.types没有Request和Response

使 FileRoutes 支持函数

使用类固然使局部代码更加紧凑,但是也牺牲了使用的便捷性。遂决定增加使用的函数的注册方式,原有注册方式保持不变。

*.py 文件中未寻找到 HTTP 对象,则寻找如下名称的函数作为对应 HTTP 请求方法的处理函数:"get", "post", "put", "patch", "delete", "head", "options", "trace"。这意味着使用时不需要继承 indexpy.HttpView,直接定义一个名为 get 的异步函数即可处理请求。

在内部代码里,使用 MultimethodRoutes 同等方式,合并多个函数到一个类中。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.