Lightweight Python Web Framework (WSGI)
Project description
NEXOM
Lightweight Python Web Framework (WSGI)
Nexom はシンプルなコードで構築できることを最優先にしつつ、必要なら低レベル API に降りられる “脱出口” を用意することで、高度な要件でも設計上詰まらないことを目指す。
## 特徴
- WSGI ベース(ブラックボックスなし)
- シンプルなルーティング(Path / Static)
- Request / Response 抽象
- Middleware 対応
- 軽量テンプレートエンジン
- 静的ファイル配信
- CLI によるサーバー雛形生成
- src 構成・assets 同梱対応
インストール
pip install nexom
## クイックスタート
### サーバープロジェクト生成
python -m nexom build-server myapp --out ./myapp
### 生成される構成
myapp/
├─ pages/
│ ├─ default.py
│ ├─ document.py
│ └─ _templates.py
├─ templates/
│ ├─ base.html
│ ├─ default.html
│ └─ document.html
├─ static/
│ └─ dog.jpeg
├─ router.py
├─ wsgi.py
├─ config.py
└─ gunicorn.conf.py
### 起動
cd myapp
gunicorn wsgi:app
基本的な使い方
ルーティング定義(router.py)
from nexom.web.path import Path, Static, Pathlib
from pages import default, document
routing = Pathlib(
Path("", default.main, "Home"),
Path("doc/", document.main, "Docs"),
Static("static/", "./static", "StaticFiles"),
)
ページハンドラ
from nexom.web.request import Request
from nexom.web.response import Response
def main(request: Request, args: dict):
return Response("Hello Nexom")
Request
from nexom.web.request import Request
主な属性:
- request.method
- request.path
- request.headers
- request.cookie
body の取得:
body = request.read_body()
Response
通常レスポンス
from nexom.web.response import Response
return Response("Hello World")
JSON レスポンス
return {"status": "ok"}
Redirect
from nexom.web.response import Redirect
return Redirect("/login")
エラーレスポンス
from nexom.web.response import ErrorResponse
return ErrorResponse(404, "Not Found")
Middleware
Middleware 定義
def logger(request, args, next_):
print(request.method, request.path)
return next_(request, args)
登録
routing.add_middleware(logger)
テンプレート
from nexom.web.template import Templates
templates = Templates("templates", "default")
html = templates.default(title="Hello Nexom")
ライセンス
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nexom-0.1.1.tar.gz
(29.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
nexom-0.1.1-py3-none-any.whl
(30.2 kB
view details)
File details
Details for the file nexom-0.1.1.tar.gz.
File metadata
- Download URL: nexom-0.1.1.tar.gz
- Upload date:
- Size: 29.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a02c65b1d968a40e9f89aed7c2068e70ec55de6ed14c2cb90fb9a4273c5a2de
|
|
| MD5 |
e0fbccaa82246114c874c398ef299981
|
|
| BLAKE2b-256 |
8e681935dcb70ce80754e48c93c88b75e3260bcbe807017f48e809e683de3a13
|
File details
Details for the file nexom-0.1.1-py3-none-any.whl.
File metadata
- Download URL: nexom-0.1.1-py3-none-any.whl
- Upload date:
- Size: 30.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca2fc9a0d72f279d82eaa91329da774a72d648498f4bede659469ce413d45f9a
|
|
| MD5 |
9356bcb7ad6ca5c13a3d7fa2093eb8fe
|
|
| BLAKE2b-256 |
bc1ac34d8c39e173330919558ccdb63fedd221ffddb3a05b208456d38bec5620
|