Zeraora lightweight collection of utilities that save your dev time.
Project description
一个 Python 工具包,包含一堆杂七杂八的工具,大部分都是从个人与公司项目提取、封装、抽象的,希望能帮你少写几行代码。
zeraora.conf,配置辅助工具。zeraora.django,对经典 Web 框架 Django 的扩展和增强。zeraora.drf,对 RESTful API 框架 Django REST Framework 的扩展和增强。zeraora.math,数学计算与常量。zeraora.requests,对 Requests 的扩展和增强。zeraora.string,字符集常量,与字符串生成。zeraora.time,时间与计时。zeraora.uuid,UUID 生成函数。
优点:除了 typing_extensions
用来兼容类型提示外,它不强制依赖任何第三方库。
缺点:优点太少。
速览/Features
SnakeModel
Django 默认会为以下模型生成一个名为 wms_goodsskuinfo 的表
# ./apps/wms/models.py
from django.db import models
class GoodsSKUInfo(models.Model):
pass
而借助
SnakeModel
可以自动生成为 wms_goods_sku_info,你只需要
# ./apps/wms/models.py
from django.db import models
from zeraora.django import SnakeModel
class GoodsSKUInfo(models.Model, metaclass=SnakeModel):
pass
Configuration
在找一个具有类型提示的、能被 IDE 自动补全字段的、不依赖文件的、超轻量的 ORM?来试试 Configuration 吧。
# ./apps/wms/models.py
from django.db import models
from zeraora.conf import Configuration
class Store(models.Model):
...
configuration = models.JSONField(default=dict)
class StoreConfiguration(Configuration):
VERSION = 1
def __init__(self, __store: Store):
self.enableStorehouse = False
"""启用仓库管理服务?"""
self.minSaleableStock = 1
"""最低可售库存量。"""
super().__init__(store.configuration or dict())
self._store_ = __store
def fill(self, save=True, *args, **kwargs):
__store = self._store_
__store.configuration = self.dump()
if save:
__store.save()
return self
store = Store.objects.get(id=1)
store.configuration = {
"enableStorehouse": True,
}
configs = StoreConfiguration(store)
print(configs.enableStorehouse) # True
print(configs.minSaleableStock) # 1
BearStopwatch
想要一个代码计时器?这里有与 Python 日志系统相适配的 BearStopwatch 。
from zeraora.time import BearStopwatch
with BearStopwatch.configit() as fox:
# 业务逻辑
pass
要是是 Django 项目,可以直接在 settings.py 中配置:
# ./my_project/settings.py
from zeraora.time import BearStopwatch
LOGGING = {
'version': 1,
'formatters': {...},
'filters': {...},
'handlers': {
'Console': { # 确保有一个控制台输出
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
# ...
},
'loggers': {
BearStopwatch.LOGGER: { # 添加相应的日志记录器
'level': BearStopwatch.LEVEL,
'handlers': ['Console'],
},
},
}
想要直接通过命令行打印?有的兄弟,有的! FoxStopwatch 用法更简单:
from zeraora.time import FoxStopwatch
with FoxStopwatch() as fox:
# 业务逻辑
pass
安装/Install
uv 用户将
pip install替换成uv pip install即可。
可以这样,直接安装本体:
pip install Zeraora
也可以这样,网络不好的时候用镜像源:
pip install Zeraora -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
还可以这样,一条命令同时安装一些可选的依赖:
pip install |
可选的依赖包 | 备注 |
|---|---|---|
Zeraora[client] |
Requests | 面向 HTTP 客户端。 |
Zeraora[backend] |
Django | 面向后端开发。 |
Zeraora[restful] |
Django、Django REST Framework | 面向后端 RESTful API 开发。 |
如果全都要!那就这样:
pip install "Zeraora[client,restful]"
兼容性/Compatibility
| 依赖程度 | 兼容范围 | |
|---|---|---|
| 必需 | 3.10.0+ | Python · 一门编程语言。 |
| 必需 | 4.14.0+ | typing_extensions · 用于兼容标准库 typing 模块,提供运行时类型提示。Zeraora 0.4.0 之前不需要这个依赖。 |
| 非必需 | 2.27.0+ | Requests · 简洁优雅的 HTTP 库。 |
| 非必需 | 3.2.0+ | Django · Web 服务开发框架。 |
| 非必需 | 3.13.0+ | Django REST Framework · 基于 Django 的 RESTful Web 服务开发框架。 |
| 非必需 | 3.14.0+ | djangorestframework-stubs · Django REST Framework 的类型提示。 |
文档/Documentations
许可证/License
MIT。源代码会保持简洁、优雅,方便随时分叉出去。
交流/Community
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
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 zeraora-0.4.0rc1.tar.gz.
File metadata
- Download URL: zeraora-0.4.0rc1.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57dae6ad702c97d4e4cab597851a849b2e3308fd60ae47c5924dc340e4f34147
|
|
| MD5 |
e953c924668a5c8cff6e87b56762356a
|
|
| BLAKE2b-256 |
c2c83687b9bdbcb460ebefd41eac99f1f0d1dda9bba26709260d995d69bf6616
|
File details
Details for the file zeraora-0.4.0rc1-py3-none-any.whl.
File metadata
- Download URL: zeraora-0.4.0rc1-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9833b966bc80ee6b1a0d3861b8cd30e26adaf9173a0313c644cf12c6b268534a
|
|
| MD5 |
8f678be0d078ded1e1578393ef257be0
|
|
| BLAKE2b-256 |
f5dc999571ece299320ca6d9e0600371c64914e8d28921801959fd30627410fd
|