Python Advanced Features Plus - 提供多种实用的 Python 扩展功能
Project description
PyAFPlus
PyAFPlus 是一个 Python 工具集合,提供了多种实用的扩展功能。
安装
pip install pyafplus
功能模块
progressplus - 高性能进度条模块
提供五种不同性能级别和功能的进度条实现:
- 标准进度条 (ProgressBar)
- 丰富的自定义选项
- 支持前缀、后缀、进度单位等
- 显示速度、预计剩余时间
- 适合需要详细信息的场景
from pyafplus.progressplus import ProgressBar
import time
# 创建标准进度条
bar = ProgressBar(
total=100,
prefix='处理中:',
suffix='完成',
decimals=1,
length=50,
fill='█',
unit='MB',
speed_unit='MB/s',
show_speed=True,
show_time=True,
show_percent=True
)
for i in range(100):
time.sleep(0.1) # 模拟处理
bar.update()
bar.finish()
- 快速进度条 (FastProgressBar)
- 优化的更新性能
- 支持最小更新间隔
- 保留基本的自定义选项
- 适合频繁更新的场景
from pyafplus.progressplus import FastProgressBar
# 创建快速进度条
bar = FastProgressBar(
total=100,
min_update_interval=0.1, # 最小更新间隔(秒)
unit='条',
speed_unit='条/s'
)
for i in range(100):
bar.update()
bar.finish()
- 极速进度条 (VFTProgressBar)
- 极致的性能优化
- 使用更新阈值控制显示频率
- 适合大规模迭代场景
from pyafplus.progressplus import VFTProgressBar
# 创建极速进度条
bar = VFTProgressBar(
total=100,
update_threshold=1000, # 每1000次迭代更新一次显示
unit='it',
speed_unit='it/s'
)
for i in range(100):
bar.update()
bar.finish()
- Rust 进度条 (RustProgressBar)
- Rust 实现的超高速进度条
- 性能提升约 4.7 倍
- 支持全部自定义选项
- 适合对性能要求极高的场景
from pyafplus.progressplus import RustProgressBar
# 创建 Rust 进度条
bar = RustProgressBar(
total=100,
prefix="处理中:",
suffix="完成",
decimals=1,
length=50,
fill="█",
unit="MB",
speed_unit="MB/s",
show_speed=True,
show_time=True,
show_percent=True,
update_threshold=1000
)
for i in range(100):
bar.update()
bar.finish()
- 增强版 Rust 进度条 (RustProgressBarPlus)
- 基于 Rust 实现的高度自定义进度条
- 支持自定义格式字符串
- 提供更多显示控制选项
- 性能与 RustProgressBar 相当
- 支持最小更新间隔和更新阈值
from pyafplus.progressplus import RustProgressBarPlus
# 使用标准格式
bar = RustProgressBarPlus(
total=100,
prefix="处理中:",
suffix="完成",
decimals=1,
length=50,
fill="█",
empty="░", # 自定义空白字符
unit="MB",
speed_unit="MB/s",
show_speed=True,
show_time=True,
show_percent=True,
show_count=True,
show_bar=True,
update_threshold=1000,
min_update_interval=0.1
)
for i in range(100):
bar.update()
bar.finish()
# 使用自定义格式
bar = RustProgressBarPlus(
total=100,
fill="=",
empty=" ",
unit="个",
speed_unit="个/s",
custom_format="自定义 |{bar}| {percent}% ({count}) [{speed}] ETA: {eta}"
)
for i in range(100):
bar.update()
bar.finish()
性能对比
在处理 1 亿次迭代时的性能表现:
- 标准进度条:4.61 秒
- 快速进度条:2.84 秒(提升 1.62x)
- 极速进度条:2.76 秒(提升 1.67x)
- Rust 进度条:0.98 秒(提升 4.70x)
- 增强版 Rust 进度条:0.99 秒(提升 4.66x)
自定义选项
所有进度条都支持基本的自定义选项:
total: 总迭代次数prefix: 前缀字符串suffix: 后缀字符串decimals: 百分比的小数位数length: 进度条的长度fill: 进度条填充字符unit: 进度单位(如:MB, KB, 个)speed_unit: 速度单位(如:it/s, MB/s)show_speed: 是否显示速度show_time: 是否显示预计剩余时间show_percent: 是否显示百分比
增强版 Rust 进度条额外支持:
empty: 进度条空白字符show_count: 是否显示计数show_bar: 是否显示进度条min_update_interval: 最小更新间隔(秒)custom_format: 自定义格式字符串,支持以下占位符:{bar}: 进度条{percent}: 百分比{count}: 计数{speed}: 速度{eta}: 预计剩余时间
其他模块
- dictplus - 字典扩展
- listplus - 列表扩展
- strplus - 字符串扩展
- strmaths - 字符串数学运算
- bccmaths - 大数运算
版本历史
v1.1.6
- 新增 progressplus 模块,提供五种不同性能级别的进度条
- 添加 Rust 实现的超高速进度条
- 添加增强版 Rust 进度条,支持更多自定义功能
- 支持丰富的自定义选项和显示功能
贡献
欢迎提交 Issue 和 Pull Request。
许可证
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
pyafplus-1.1.7.tar.gz
(184.0 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
pyafplus-1.1.7-py3-none-any.whl
(175.0 kB
view details)
File details
Details for the file pyafplus-1.1.7.tar.gz.
File metadata
- Download URL: pyafplus-1.1.7.tar.gz
- Upload date:
- Size: 184.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
028f09f0f1d52e616f0190982067b8188eff1256288697f76913b4f09589050e
|
|
| MD5 |
7980b6d2afe4ec29734049f32df2fcb3
|
|
| BLAKE2b-256 |
99845e58ddf45db44269bb3f8853b7fa50014dcd4c018cbd1fde2938616bb8fd
|
File details
Details for the file pyafplus-1.1.7-py3-none-any.whl.
File metadata
- Download URL: pyafplus-1.1.7-py3-none-any.whl
- Upload date:
- Size: 175.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21c64b159c90b3ef8ecbe85a7c549a7935efa2f5d6db5317ae30346b5fdbcfb9
|
|
| MD5 |
ab01ea134b7187530b9ffacff3d800e1
|
|
| BLAKE2b-256 |
f9cf4b6d8b77936c6f05ec973a1b58e2555c724115abee73d81faa68296e8103
|