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.7.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.7-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wframe-0.1.7.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.7.tar.gz
Algorithm Hash digest
SHA256 46449e7f83acc3143f5cc65da2354753a310d19067e39d2e5aecb38c9f3a866f
MD5 c392f637f0ceceeef00a37751d91fe9d
BLAKE2b-256 1a9edae17f1d85c8fa5086dd76f454e3f679c4fd38cd7f9a01f2862c62183a71

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wframe-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 11.0 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 727976e085f5da29c680b36812e4d4363f261da6ffeb71dac6d17ef6c694215d
MD5 cce5924ea09592a1c3ad1cc9f8f9f621
BLAKE2b-256 924712d19211e2280644385d0f1312b27d5626a88da03c0d1b5769ee58a0563b

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