nova-fastapi-tool
A Hutool-style FastAPI utility toolkit.
Fast + Tool = nova-fastapi-tool. A curated, modular, batteries-included Python library that brings the elegance of Hutool (Java's beloved util library) to the FastAPI world.
Keep FastAPI sweet — one helper at a time.
✨ Features
| Module | What it gives you | Hutool analog |
|---|---|---|
| core | StrUtil, DateUtil, IdUtil, HashUtil, MapUtil, ValidUtil, CryptoUtil |
hutool-core |
| logging | Unified LogUtil facade (std logging + optional loguru), JSON formatter, request-ID middleware |
hutool-log |
| config | Multi-profile YAML / .env loader, Pydantic-settings base, environment-variable expansion |
hutool-setting |
| nacos | Nacos service registry & discovery + config center with FastAPI lifespan auto-wiring |
(unique) |
| auth | JWT JwtUtil, password hashing (argon2/bcrypt), RBAC deps, rate-limiter |
hutool-jwt |
| web | create_app factory, global exception handler, unified R.ok() / R.fail() response, CORS helper |
(unique) |
| db | SQLAlchemy 2 async/sync helpers — DbUtil / AsyncDbUtil, typed Page pagination, transactions, engine registry |
hutool-db |
| cache | CacheUtil / AsyncCacheUtil facade — memory (LRU+TTL) or Redis backend, pluggable serializer |
hutool-cache |
| http | httpx-based client wrapper — HttpUtil / AsyncHttpUtil one-shots, reusable HttpClient / AsyncHttpClient, retry with backoff |
hutool-http |
🚀 Install
The package follows the "core + optional extras" pattern — exactly like Hutool's modular dependencies. Pick just what you need:
# Only core utilities (StrUtil / DateUtil / unified response / common middleware)
pip install nova-fastapi-tool
# + Nacos service registry & config center
pip install nova-fastapi-tool[nacos]
# + JWT auth / RBAC / password hashing / rate limiting
pip install nova-fastapi-tool[auth]
# + rich loguru-backed logging
pip install nova-fastapi-tool[logging]
# + httpx-based HTTP client wrapper (HttpUtil / HttpClient)
pip install nova-fastapi-tool[http]
# = Everything (≈ hutool-all)
pip install nova-fastapi-tool[all]
# = Dev / test / build tooling
pip install nova-fastapi-tool[dev]
Python ≥ 3.11 is required.
🧩 5-second tour
from fastapi import FastAPI
from nova_fastapi_tool import create_app, LogUtil, R, StrUtil, DateUtil
# 1) Assemble a production-ready FastAPI app in 1 line
app: FastAPI = create_app(title="demo-service", debug=False, cors_origins=["*"])
# 2) Simple logging facade that behaves everywhere
LogUtil.info("Starting demo at {}", DateUtil.now_iso())
# 3) String helpers — Hutool-ish ergonomics
if StrUtil.is_blank(" "):
LogUtil.warning("Empty input detected; masked={}", StrUtil.mask_email("user@example.com"))
# 4) Unified response envelope — your front-end will love you
@app.get("/hello")
def hello(name: str | None = None) -> R:
return R.ok({"greeting": f"Hello, {StrUtil.or_default(name, 'World')}!"})
With Nacos + JWT
See examples/ for:
minimal_app.py— Logging + unified response skeletonnacos_demo.py— Service register/discovery + config-center watcherauth_demo.py— JWT login + role-protected endpoints
📁 Project layout
pypi-fastapi/
├── pyproject.toml # PEP 621 packaging + extras (nacos/auth/logging/…)
├── src/
│ └── nova_fastapi_tool/ # Importable package (same name as PyPI artifact)
│ ├── __init__.py # Re-exports everything (≈ hutool-all)
│ ├── version.py # Single source of truth for version
│ ├── core/ # StrUtil, DateUtil, IdUtil, HashUtil, …
│ ├── logging/ # LogUtil facade + JSON formatter + request-ID MW
│ ├── config/ # Multi-profile YAML/.env + Settings base class
│ ├── nacos/ # NacosClient, Registry, ConfigCenter, Discovery, lifespan
│ ├── auth/ # JwtUtil, passwords, RBAC, rate-limit, Depends
│ ├── web/ # create_app, exceptions, R response, CORS, access-log MW
│ ├── db/ # DbUtil / AsyncDbUtil, Page, transactions, engine registry
│ ├── cache/ # CacheUtil / AsyncCacheUtil, memory/Redis backends
│ └── http/ # HttpUtil / HttpClient, retry config, HttpError
├── tests/ # Pytest suite, module-scoped
└── examples/ # Runnable demos
🛡️ License
Apache License 2.0 — see LICENSE.
📦 Publish to PyPI
PyPI credentials are kept out of this repo. Export a project-scoped API token as environment variables before uploading:
export TWINE_USERNAME=__token__ export TWINE_PASSWORD=pypi-xxxxxxxxxxxxxxxxxxxx hatch build # → dist/nova_fastapi_tool-X.Y.Z{.tar.gz,.whl} twine upload dist/*
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file nova_fastapi_tool-0.2.0.tar.gz.
File metadata
- Download URL: nova_fastapi_tool-0.2.0.tar.gz
- Upload date:
- Size: 26.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dfd271e388b04e1a2c2d9a1175bad6a920453581a3d698110ef0f3db0fc5099
|
|
| MD5 |
f30c921ca064899257b6202148e33435
|
|
| BLAKE2b-256 |
84a2fb04144f59020ce3b46b7ea20a803812719c94d1db948fae229621a33c94
|
File details
Details for the file nova_fastapi_tool-0.2.0-py3-none-any.whl.
File metadata
- Download URL: nova_fastapi_tool-0.2.0-py3-none-any.whl
- Upload date:
- Size: 122.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74d48dd5390cffced4be2121d898d6c2237ced4c23048c721cd9c88cc054dd59
|
|
| MD5 |
1a36d54da501115c654af3190e023ffe
|
|
| BLAKE2b-256 |
daa9ff05531882528cddb42e3e3ba255bba876bf19449e78228fb38239e2cca7
|