Skip to main content

一个轻量级的 Python Web 框架

Project description

WFrame

一个轻量级的 Python Web 框架,专注于简单性和可扩展性。

特性

  • 轻量级路由系统
  • 中间件支持
  • 会话管理
  • JWT 认证
  • CSRF 保护
  • 数据库集成(SQLAlchemy)
  • OpenAPI 文档
  • 请求速率限制
  • 错误处理

安装

pip install wframe

快速开始

  1. 创建新项目:
wframe new myapp
cd myapp
  1. 运行应用:
wframe run

示例代码

from wframe import WebFramework, Response
from wframe.security import token_required

app = WebFramework()

@app.route('/')
def index(request):
    return Response('Hello, WFrame!')

@app.route('/api/profile')
@token_required
def profile(request):
    return Response({
        'username': request.user.username
    })

if __name__ == '__main__':
    app.run()

主要功能

路由

@app.route('/users/<id>', methods=['GET', 'POST'])
def user(request, id):
    return Response(f'User {id}')

中间件

def logger_middleware(request):
    print(f'Request: {request.method} {request.path}')
    return request

app.use(logger_middleware)

数据库

from wframe.models import User

@app.route('/users')
def users(request):
    db = next(get_db())
    users = db.query(User).all()
    return Response([user.username for user in users])

认证

@app.route('/login', methods=['POST'])
def login(request):
    data = json.loads(request.get_data())
    token = create_access_token({'username': data['username']})
    return Response({'token': token})

文档

访问 http://localhost:5000/docs 查看 API 文档。

许可证

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wframe-0.1.10.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wframe-0.1.10-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file wframe-0.1.10.tar.gz.

File metadata

  • Download URL: wframe-0.1.10.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for wframe-0.1.10.tar.gz
Algorithm Hash digest
SHA256 2d75c76cef9c496ca5b7928fd9bce5fee6411e5eb9da628514d9950a22127c61
MD5 e575c50ee8bdb7948cbe7a79871f9800
BLAKE2b-256 408603b6deee8ddf6a0b49dd27a6e1ba5f13ce2fa336bb92f737bbc71231b2b9

See more details on using hashes here.

File details

Details for the file wframe-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: wframe-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for wframe-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 8eb59617c64eb86b358fbe80dfe28ff6df04d6fa2e61448848d46a06da948d60
MD5 1e01b2693a6ffac7fb1452c7152635f5
BLAKE2b-256 dfa42b28883ed73756c485c68c08c695ca157ce36c19de414d685a1edf2d1695

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page