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

Uploaded Python 3

File details

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

File metadata

  • Download URL: wframe-0.1.8.tar.gz
  • Upload date:
  • Size: 9.8 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.8.tar.gz
Algorithm Hash digest
SHA256 f399d9fa3ddc3577e0dc90dd1d84d9c63b91dfa73e110c116858bb92f1474f1a
MD5 165aa22b23d4551b384d8a9c36ff5134
BLAKE2b-256 cceffbc77a90f46aea4e14a68b31ffdca362819361ec0d553b00cb7fda606551

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wframe-0.1.8-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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 9be0bce4c01c36ab00aca025bab488f03079c605ad39927876ad50332d6b5b5c
MD5 7c4d74760e8049f2aea6b09d2ed1c0a6
BLAKE2b-256 7167a9b0868519157453bacc3fa68fab86a67e550809af0703aff3fd6589f0d0

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