hutool-python 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hutool_python-1.0.0/LICENSE +127 -0
- hutool_python-1.0.0/MANIFEST.in +10 -0
- hutool_python-1.0.0/PKG-INFO +438 -0
- hutool_python-1.0.0/README-EN.md +393 -0
- hutool_python-1.0.0/README.md +395 -0
- hutool_python-1.0.0/hutool/__init__.py +174 -0
- hutool_python-1.0.0/hutool/cache/__init__.py +7 -0
- hutool_python-1.0.0/hutool/cache/cache_util.py +47 -0
- hutool_python-1.0.0/hutool/cache/fifo_cache.py +87 -0
- hutool_python-1.0.0/hutool/cache/lfu_cache.py +129 -0
- hutool_python-1.0.0/hutool/cache/lru_cache.py +93 -0
- hutool_python-1.0.0/hutool/cache/timed_cache.py +115 -0
- hutool_python-1.0.0/hutool/captcha/__init__.py +3 -0
- hutool_python-1.0.0/hutool/captcha/captcha_util.py +215 -0
- hutool_python-1.0.0/hutool/core/__init__.py +23 -0
- hutool_python-1.0.0/hutool/core/_base.py +61 -0
- hutool_python-1.0.0/hutool/core/bean.py +214 -0
- hutool_python-1.0.0/hutool/core/codec.py +111 -0
- hutool_python-1.0.0/hutool/core/coll.py +635 -0
- hutool_python-1.0.0/hutool/core/date.py +1024 -0
- hutool_python-1.0.0/hutool/core/exceptions.py +66 -0
- hutool_python-1.0.0/hutool/core/io/__init__.py +0 -0
- hutool_python-1.0.0/hutool/core/io/data_size_util.py +79 -0
- hutool_python-1.0.0/hutool/core/io/file_name_util.py +111 -0
- hutool_python-1.0.0/hutool/core/io/file_util.py +650 -0
- hutool_python-1.0.0/hutool/core/io/io_util.py +133 -0
- hutool_python-1.0.0/hutool/core/io/path_util.py +247 -0
- hutool_python-1.0.0/hutool/core/io/resource_util.py +137 -0
- hutool_python-1.0.0/hutool/core/map.py +933 -0
- hutool_python-1.0.0/hutool/core/math_util.py +105 -0
- hutool_python-1.0.0/hutool/core/net.py +288 -0
- hutool_python-1.0.0/hutool/core/text/__init__.py +0 -0
- hutool_python-1.0.0/hutool/core/text/csv_util.py +54 -0
- hutool_python-1.0.0/hutool/core/text/str_builder.py +224 -0
- hutool_python-1.0.0/hutool/core/text/unicode_util.py +58 -0
- hutool_python-1.0.0/hutool/core/tree.py +242 -0
- hutool_python-1.0.0/hutool/core/util/__init__.py +63 -0
- hutool_python-1.0.0/hutool/core/util/array_util.py +503 -0
- hutool_python-1.0.0/hutool/core/util/boolean_util.py +124 -0
- hutool_python-1.0.0/hutool/core/util/charset_util.py +60 -0
- hutool_python-1.0.0/hutool/core/util/class_util.py +136 -0
- hutool_python-1.0.0/hutool/core/util/coordinate_util.py +186 -0
- hutool_python-1.0.0/hutool/core/util/credit_code_util.py +110 -0
- hutool_python-1.0.0/hutool/core/util/desensitized_util.py +194 -0
- hutool_python-1.0.0/hutool/core/util/enum_util.py +94 -0
- hutool_python-1.0.0/hutool/core/util/escape_util.py +97 -0
- hutool_python-1.0.0/hutool/core/util/hash_util.py +243 -0
- hutool_python-1.0.0/hutool/core/util/hex_util.py +140 -0
- hutool_python-1.0.0/hutool/core/util/id_util.py +147 -0
- hutool_python-1.0.0/hutool/core/util/idcard_util.py +300 -0
- hutool_python-1.0.0/hutool/core/util/number_util.py +720 -0
- hutool_python-1.0.0/hutool/core/util/object_util.py +294 -0
- hutool_python-1.0.0/hutool/core/util/page_util.py +61 -0
- hutool_python-1.0.0/hutool/core/util/phone_util.py +140 -0
- hutool_python-1.0.0/hutool/core/util/random_util.py +112 -0
- hutool_python-1.0.0/hutool/core/util/re_util.py +231 -0
- hutool_python-1.0.0/hutool/core/util/reflect_util.py +135 -0
- hutool_python-1.0.0/hutool/core/util/runtime_util.py +89 -0
- hutool_python-1.0.0/hutool/core/util/str_util.py +2320 -0
- hutool_python-1.0.0/hutool/core/util/system_util.py +62 -0
- hutool_python-1.0.0/hutool/core/util/url_util.py +232 -0
- hutool_python-1.0.0/hutool/core/util/version_util.py +41 -0
- hutool_python-1.0.0/hutool/core/util/xml_util.py +158 -0
- hutool_python-1.0.0/hutool/core/util/zip_util.py +126 -0
- hutool_python-1.0.0/hutool/cron/__init__.py +4 -0
- hutool_python-1.0.0/hutool/cron/cron_pattern.py +123 -0
- hutool_python-1.0.0/hutool/cron/cron_util.py +115 -0
- hutool_python-1.0.0/hutool/crypto/__init__.py +5 -0
- hutool_python-1.0.0/hutool/crypto/digest_util.py +167 -0
- hutool_python-1.0.0/hutool/crypto/secure_util.py +311 -0
- hutool_python-1.0.0/hutool/crypto/sign_util.py +74 -0
- hutool_python-1.0.0/hutool/dfa/__init__.py +3 -0
- hutool_python-1.0.0/hutool/dfa/sensitive_util.py +114 -0
- hutool_python-1.0.0/hutool/extra/__init__.py +6 -0
- hutool_python-1.0.0/hutool/extra/emoji_util.py +90 -0
- hutool_python-1.0.0/hutool/extra/pinyin_util.py +44 -0
- hutool_python-1.0.0/hutool/extra/qr_code_util.py +58 -0
- hutool_python-1.0.0/hutool/extra/template_util.py +41 -0
- hutool_python-1.0.0/hutool/http/__init__.py +6 -0
- hutool_python-1.0.0/hutool/http/html_util.py +88 -0
- hutool_python-1.0.0/hutool/http/http_request.py +188 -0
- hutool_python-1.0.0/hutool/http/http_response.py +139 -0
- hutool_python-1.0.0/hutool/http/http_util.py +237 -0
- hutool_python-1.0.0/hutool/json_util.py +251 -0
- hutool_python-1.0.0/hutool/jwt_util.py +57 -0
- hutool_python-1.0.0/hutool/setting/__init__.py +5 -0
- hutool_python-1.0.0/hutool/setting/props_util.py +79 -0
- hutool_python-1.0.0/hutool/setting/setting_util.py +80 -0
- hutool_python-1.0.0/hutool/setting/yaml_util.py +45 -0
- hutool_python-1.0.0/hutool_python.egg-info/PKG-INFO +438 -0
- hutool_python-1.0.0/hutool_python.egg-info/SOURCES.txt +96 -0
- hutool_python-1.0.0/hutool_python.egg-info/dependency_links.txt +1 -0
- hutool_python-1.0.0/hutool_python.egg-info/requires.txt +16 -0
- hutool_python-1.0.0/hutool_python.egg-info/top_level.txt +1 -0
- hutool_python-1.0.0/pyproject.toml +62 -0
- hutool_python-1.0.0/requirements.txt +12 -0
- hutool_python-1.0.0/setup.cfg +4 -0
- hutool_python-1.0.0/setup.py +51 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
木兰宽松许可证, 第2版
|
|
2
|
+
|
|
3
|
+
木兰宽松许可证, 第2版
|
|
4
|
+
2020年1月 http://license.coscl.org.cn/MulanPSL2
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束:
|
|
8
|
+
|
|
9
|
+
0. 定义
|
|
10
|
+
|
|
11
|
+
“软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
|
|
12
|
+
|
|
13
|
+
“贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
|
|
14
|
+
|
|
15
|
+
“贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
|
|
16
|
+
|
|
17
|
+
“法人实体”是指提交贡献的机构及其“关联实体”。
|
|
18
|
+
|
|
19
|
+
“关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
|
|
20
|
+
|
|
21
|
+
1. 授予版权许可
|
|
22
|
+
|
|
23
|
+
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。
|
|
24
|
+
|
|
25
|
+
2. 授予专利许可
|
|
26
|
+
|
|
27
|
+
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
|
|
28
|
+
|
|
29
|
+
3. 无商标许可
|
|
30
|
+
|
|
31
|
+
“本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。
|
|
32
|
+
|
|
33
|
+
4. 分发限制
|
|
34
|
+
|
|
35
|
+
您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。
|
|
36
|
+
|
|
37
|
+
5. 免责声明与责任限制
|
|
38
|
+
|
|
39
|
+
“软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。
|
|
40
|
+
|
|
41
|
+
6. 语言
|
|
42
|
+
“本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。
|
|
43
|
+
|
|
44
|
+
条款结束
|
|
45
|
+
|
|
46
|
+
如何将木兰宽松许可证,第2版,应用到您的软件
|
|
47
|
+
|
|
48
|
+
如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步:
|
|
49
|
+
|
|
50
|
+
1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
|
|
51
|
+
|
|
52
|
+
2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中;
|
|
53
|
+
|
|
54
|
+
3, 请将如下声明文本放入每个源文件的头部注释中。
|
|
55
|
+
|
|
56
|
+
Copyright (c) [Year] [name of copyright holder]
|
|
57
|
+
[Software Name] is licensed under Mulan PSL v2.
|
|
58
|
+
You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
59
|
+
You may obtain a copy of Mulan PSL v2 at:
|
|
60
|
+
http://license.coscl.org.cn/MulanPSL2
|
|
61
|
+
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
62
|
+
See the Mulan PSL v2 for more details.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
Mulan Permissive Software License,Version 2
|
|
66
|
+
|
|
67
|
+
Mulan Permissive Software License,Version 2 (Mulan PSL v2)
|
|
68
|
+
January 2020 http://license.coscl.org.cn/MulanPSL2
|
|
69
|
+
|
|
70
|
+
Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions:
|
|
71
|
+
|
|
72
|
+
0. Definition
|
|
73
|
+
|
|
74
|
+
Software means the program and related documents which are licensed under this License and comprise all Contribution(s).
|
|
75
|
+
|
|
76
|
+
Contribution means the copyrightable work licensed by a particular Contributor under this License.
|
|
77
|
+
|
|
78
|
+
Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
|
|
79
|
+
|
|
80
|
+
Legal Entity means the entity making a Contribution and all its Affiliates.
|
|
81
|
+
|
|
82
|
+
Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
|
|
83
|
+
|
|
84
|
+
1. Grant of Copyright License
|
|
85
|
+
|
|
86
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
|
|
87
|
+
|
|
88
|
+
2. Grant of Patent License
|
|
89
|
+
|
|
90
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
|
|
91
|
+
|
|
92
|
+
3. No Trademark License
|
|
93
|
+
|
|
94
|
+
No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4.
|
|
95
|
+
|
|
96
|
+
4. Distribution Restriction
|
|
97
|
+
|
|
98
|
+
You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software.
|
|
99
|
+
|
|
100
|
+
5. Disclaimer of Warranty and Limitation of Liability
|
|
101
|
+
|
|
102
|
+
THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
103
|
+
|
|
104
|
+
6. Language
|
|
105
|
+
|
|
106
|
+
THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL.
|
|
107
|
+
|
|
108
|
+
END OF THE TERMS AND CONDITIONS
|
|
109
|
+
|
|
110
|
+
How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software
|
|
111
|
+
|
|
112
|
+
To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps:
|
|
113
|
+
|
|
114
|
+
i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner;
|
|
115
|
+
|
|
116
|
+
ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package;
|
|
117
|
+
|
|
118
|
+
iii Attach the statement to the appropriate annotated syntax at the beginning of each source file.
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
Copyright (c) [Year] [name of copyright holder]
|
|
122
|
+
[Software Name] is licensed under Mulan PSL v2.
|
|
123
|
+
You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
124
|
+
You may obtain a copy of Mulan PSL v2 at:
|
|
125
|
+
http://license.coscl.org.cn/MulanPSL2
|
|
126
|
+
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
127
|
+
See the Mulan PSL v2 for more details.
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: hutool-python
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python port of Java Hutool utility library
|
|
5
|
+
Home-page: https://github.com/wgp520/hutool-python
|
|
6
|
+
Author: Hutool-Python
|
|
7
|
+
License: MulanPSL-2.0
|
|
8
|
+
Project-URL: Homepage, https://github.com/wgp520/hutool-python
|
|
9
|
+
Project-URL: Documentation, https://wgp520.github.io/hutool-python
|
|
10
|
+
Project-URL: Repository, https://github.com/wgp520/hutool-python
|
|
11
|
+
Project-URL: Issues, https://github.com/wgp520/hutool-python/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/wgp520/hutool-python/blob/master/docs/changelog.md
|
|
13
|
+
Keywords: hutool,util,utility,toolkit,java-hutool
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Requires-Python: >=3.8
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: pendulum>=3.0
|
|
29
|
+
Requires-Dist: httpx>=0.27
|
|
30
|
+
Requires-Dist: cryptography>=42.0
|
|
31
|
+
Requires-Dist: qrcode[pil]>=7.0
|
|
32
|
+
Requires-Dist: Pillow>=10.0
|
|
33
|
+
Requires-Dist: pypinyin>=0.50
|
|
34
|
+
Requires-Dist: emoji>=2.0
|
|
35
|
+
Requires-Dist: jinja2>=3.0
|
|
36
|
+
Requires-Dist: pyjwt>=2.8
|
|
37
|
+
Requires-Dist: pyyaml>=6.0
|
|
38
|
+
Requires-Dist: watchdog>=4.0
|
|
39
|
+
Requires-Dist: sortedcontainers>=2.0
|
|
40
|
+
Provides-Extra: dev
|
|
41
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
42
|
+
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
43
|
+
|
|
44
|
+
<p align="center">
|
|
45
|
+
<h1 align="center">Hutool-Python</h1>
|
|
46
|
+
</p>
|
|
47
|
+
<p align="center">
|
|
48
|
+
<strong>🐍 让 Python 和 Java 一样"甜蜜"的工具库</strong>
|
|
49
|
+
</p>
|
|
50
|
+
|
|
51
|
+
<p align="center">
|
|
52
|
+
<img src="https://img.shields.io/badge/Python-3.8+-blue.svg" />
|
|
53
|
+
<img src="https://img.shields.io/badge/version-1.0.0-green.svg" />
|
|
54
|
+
<img src="https://img.shields.io/badge/license-MulanPSL2-blue.svg" />
|
|
55
|
+
<img src="https://img.shields.io/badge/tests-613 passed-brightgreen.svg" />
|
|
56
|
+
<a href="https://wgp520.github.io/hutool-python/"><img src="https://img.shields.io/badge/docs-online-blueviolet.svg" /></a>
|
|
57
|
+
</p>
|
|
58
|
+
|
|
59
|
+
-------------------------------------------------------------------------------
|
|
60
|
+
|
|
61
|
+
[**🌎English Version**](README-EN.md)
|
|
62
|
+
|
|
63
|
+
-------------------------------------------------------------------------------
|
|
64
|
+
|
|
65
|
+
## 📚 简介
|
|
66
|
+
|
|
67
|
+
`Hutool-Python` 是 [Java Hutool](https://github.com/dromara/hutool) 的 Python 移植版本,旨在将 Hutool 丰富且易用的工具类生态带到 Python 世界。
|
|
68
|
+
|
|
69
|
+
**Hutool** 是一个功能丰富且易用的 Java 工具库,涵盖了字符串、数字、集合、编码、日期、文件、IO、加密、JSON、HTTP 客户端等一系列操作。`Hutool-Python` 将这些能力忠实移植到 Python,保留 Hutool 的命名风格和设计理念,让 Java 开发者无缝切换,也让 Python 开发者享受 Hutool 式的便捷体验。
|
|
70
|
+
|
|
71
|
+
### 🍺 设计理念
|
|
72
|
+
|
|
73
|
+
- **忠实移植**:类名保持 Hutool 的 PascalCase 风格(如 `StrUtil`、`DateUtil`),方法名转为 Python 的 snake_case(如 `is_blank`、`offset_day`)
|
|
74
|
+
- **Python 化实现**:底层实现使用 Python 生态最佳实践(`pendulum`、`httpx`、`cryptography` 等),而非机械翻译 Java 代码
|
|
75
|
+
- **中文注释**:所有文档注释均使用中文,采用 Sphinx 风格(`:param:` / `:return:` / `:raises:`),便于源码阅读
|
|
76
|
+
- **零配置开箱即用**:无需额外配置,`pip install` 后即可使用
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 🛠️ 包含模块
|
|
81
|
+
|
|
82
|
+
| 模块 | 介绍 | 对应 Java Hutool |
|
|
83
|
+
|------|------|-----------------|
|
|
84
|
+
| `core/util/` | 核心工具类:字符串、数字、数组、对象、布尔、随机、ID、正则、哈希、转义、URL、版本、分页等 25 个工具类 | `cn.hutool.core.util` |
|
|
85
|
+
| `core/coll.py` | 集合工具:`CollUtil`、`ListUtil` | `cn.hutool.core.collection` |
|
|
86
|
+
| `core/map.py` | Map 工具:`MapUtil`、`BiMap`、`DictUtil` | `cn.hutool.core.map` |
|
|
87
|
+
| `core/io/` | IO 工具:文件、IO 流、路径、文件名、数据大小、资源 | `cn.hutool.core.io` |
|
|
88
|
+
| `core/date.py` | 日期工具:`DateUtil`、`DateTime`(基于 pendulum) | `cn.hutool.core.date` |
|
|
89
|
+
| `core/bean.py` | Bean 工具:属性拷贝、Map 互转 | `cn.hutool.core.bean` |
|
|
90
|
+
| `core/codec.py` | 编解码:`Base64`、`Base32` | `cn.hutool.core.codec` |
|
|
91
|
+
| `core/text/` | 文本工具:`UnicodeUtil`、`CsvUtil`、`StrBuilder` | `cn.hutool.core.text` |
|
|
92
|
+
| `core/net.py` | 网络工具:`NetUtil`、`Ipv4Util` | `cn.hutool.core.net` |
|
|
93
|
+
| `core/math_util.py` | 数学工具:`MathUtil`、`BitStatusUtil` | `cn.hutool.core.math` |
|
|
94
|
+
| `core/tree.py` | 树工具:`TreeUtil` | `cn.hutool.core.lang.tree` |
|
|
95
|
+
| `http/` | HTTP 客户端:`HttpUtil`、`HttpRequest`、`HttpResponse`、`HtmlUtil`(基于 httpx) | `cn.hutool.http` |
|
|
96
|
+
| `json_util.py` | JSON 工具:`JSONUtil`(基于内置 json 扩展) | `cn.hutool.json` |
|
|
97
|
+
| `crypto/` | 加密工具:`DigestUtil`、`SecureUtil`、`SignUtil`(基于 cryptography) | `cn.hutool.crypto` |
|
|
98
|
+
| `cache/` | 缓存工具:`FIFOCache`、`LFUCache`、`LRUCache`、`TimedCache` | `cn.hutool.cache` |
|
|
99
|
+
| `captcha/` | 验证码:`CaptchaUtil`(基于 Pillow) | `cn.hutool.captcha` |
|
|
100
|
+
| `dfa/` | 敏感词过滤:`SensitiveUtil`(基于 DFA 算法) | `cn.hutool.dfa` |
|
|
101
|
+
| `extra/` | 扩展工具:`EmojiUtil`、`PinyinUtil`、`TemplateUtil`、`QrCodeUtil` | `cn.hutool.extra` |
|
|
102
|
+
| `cron/` | 定时任务:`CronUtil`、`CronPattern` | `cn.hutool.cron` |
|
|
103
|
+
| `jwt_util.py` | JWT 工具:`JWTUtil`(基于 PyJWT) | `cn.hutool.jwt` |
|
|
104
|
+
| `setting/` | 配置工具:`SettingUtil`、`YamlUtil`、`PropsUtil` | `cn.hutool.setting` |
|
|
105
|
+
|
|
106
|
+
> 注:Java Hutool 中的 AOP、JDBC/Swing、POI、JNDI、ClassLoader、BloomFilter、Log、Script、Socket 等 Java 专属模块不包含在 Hutool-Python 中。
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 📦 安装
|
|
111
|
+
|
|
112
|
+
### 🍊 pip 安装(推荐)
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
pip install hutool-python
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 🍐 从源码安装
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
git clone https://github.com/wgp520/hutool-python.git
|
|
122
|
+
cd hutool-python
|
|
123
|
+
pip install -e .
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 🧪 安装开发依赖
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
pip install -e ".[dev]"
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
> **要求**:Python 3.8+
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 🚀 快速开始
|
|
137
|
+
|
|
138
|
+
### 字符串工具
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from hutool import StrUtil
|
|
142
|
+
|
|
143
|
+
# 判断是否为空白
|
|
144
|
+
StrUtil.is_blank("") # True
|
|
145
|
+
StrUtil.is_blank(" ") # True
|
|
146
|
+
StrUtil.is_blank("hello") # False
|
|
147
|
+
|
|
148
|
+
# 子串操作
|
|
149
|
+
StrUtil.sub_before("abc.jpg", ".") # "abc"
|
|
150
|
+
StrUtil.sub_after("abc.jpg", ".") # "jpg"
|
|
151
|
+
StrUtil.sub_between("a(b)c", "(", ")") # "b"
|
|
152
|
+
|
|
153
|
+
# 命名转换
|
|
154
|
+
StrUtil.to_camel_case("hello_world") # "helloWorld"
|
|
155
|
+
StrUtil.to_snake_case("helloWorld") # "hello_world"
|
|
156
|
+
|
|
157
|
+
# 字符串相似度
|
|
158
|
+
StrUtil.similar("我爱学习", "我爱学") # 0.75
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### 日期工具
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
from hutool import DateUtil
|
|
165
|
+
|
|
166
|
+
# 获取当前时间
|
|
167
|
+
DateUtil.now() # "2024-01-15 14:30:00"
|
|
168
|
+
DateUtil.today() # "2024-01-15"
|
|
169
|
+
|
|
170
|
+
# 解析日期
|
|
171
|
+
dt = DateUtil.parse("2024-01-15")
|
|
172
|
+
|
|
173
|
+
# 日期偏移
|
|
174
|
+
DateUtil.offset_day(dt, 7) # 7天后
|
|
175
|
+
DateUtil.offset_month(dt, -1) # 1个月前
|
|
176
|
+
|
|
177
|
+
# 日期差
|
|
178
|
+
start = DateUtil.parse("2024-01-01")
|
|
179
|
+
end = DateUtil.parse("2024-12-31")
|
|
180
|
+
DateUtil.between_day(start, end) # 365
|
|
181
|
+
|
|
182
|
+
# 判断闰年
|
|
183
|
+
DateUtil.is_leap_year(2024) # True
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### 集合工具
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
from hutool import CollUtil, MapUtil
|
|
190
|
+
|
|
191
|
+
# 分组
|
|
192
|
+
data = [{"type": "a", "val": 1}, {"type": "b", "val": 2}, {"type": "a", "val": 3}]
|
|
193
|
+
CollUtil.group_by(data, key_func=lambda x: x["type"])
|
|
194
|
+
# {"a": [{"type": "a", "val": 1}, {"type": "a", "val": 3}], "b": [...]}
|
|
195
|
+
|
|
196
|
+
# 分页
|
|
197
|
+
CollUtil.page([1, 2, 3, 4, 5], page_num=1, page_size=2) # [1, 2]
|
|
198
|
+
|
|
199
|
+
# Map 操作
|
|
200
|
+
MapUtil.sort({"c": 3, "a": 1, "b": 2}) # {"a": 1, "b": 2, "c": 3}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### ID 生成
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
from hutool import IdUtil
|
|
207
|
+
|
|
208
|
+
IdUtil.random_uuid() # "550e8400-e29b-41d4-a716-446655440000"
|
|
209
|
+
IdUtil.simple_uuid() # "550e8400e29b41d4a716446655440000"
|
|
210
|
+
IdUtil.nano_id() # "V1StGXR8_Z5jdHi6B-myT"
|
|
211
|
+
IdUtil.snowflake_id() # 1480946864314982400
|
|
212
|
+
IdUtil.object_id() # "5f8b2c3d4e5f6a7b8c9d0e1f"
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### HTTP 客户端
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
from hutool.http import HttpUtil
|
|
219
|
+
|
|
220
|
+
# GET 请求
|
|
221
|
+
html = HttpUtil.get("https://example.com")
|
|
222
|
+
|
|
223
|
+
# POST 请求
|
|
224
|
+
result = HttpUtil.post("https://api.example.com/data", json_data={"key": "value"})
|
|
225
|
+
|
|
226
|
+
# 链式调用
|
|
227
|
+
from hutool.http import HttpRequest, HttpResponse
|
|
228
|
+
|
|
229
|
+
resp = (HttpRequest.post("https://api.example.com/data")
|
|
230
|
+
.header("Authorization", "Bearer token")
|
|
231
|
+
.json({"key": "value"})
|
|
232
|
+
.timeout(30)
|
|
233
|
+
.execute())
|
|
234
|
+
|
|
235
|
+
print(resp.is_ok()) # True
|
|
236
|
+
print(resp.to_json()) # {...}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### 加密工具
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
from hutool.crypto import DigestUtil, SecureUtil
|
|
243
|
+
|
|
244
|
+
# 摘要算法
|
|
245
|
+
DigestUtil.md5_hex("hello") # "5d41402abc4b2a76b9719d911017c592"
|
|
246
|
+
DigestUtil.sha256_hex("hello") # "2cf24dba5fb0a30e..."
|
|
247
|
+
|
|
248
|
+
# AES 对称加密
|
|
249
|
+
key = SecureUtil.generate_aes_key()
|
|
250
|
+
encrypted = SecureUtil.encrypt_aes(b"secret data", key, "ECB")
|
|
251
|
+
decrypted = SecureUtil.decrypt_aes(encrypted, key, "ECB")
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### 敏感词过滤
|
|
255
|
+
|
|
256
|
+
```python
|
|
257
|
+
from hutool.dfa import SensitiveUtil
|
|
258
|
+
|
|
259
|
+
# 初始化敏感词库
|
|
260
|
+
SensitiveUtil.init(["敏感词", "违禁词", "垃圾信息"])
|
|
261
|
+
|
|
262
|
+
# 检测
|
|
263
|
+
SensitiveUtil.contains("这是一段包含敏感词的文本") # True
|
|
264
|
+
|
|
265
|
+
# 查找
|
|
266
|
+
SensitiveUtil.find_all("这是一段包含敏感词和违禁词的文本") # ["敏感词", "违禁词"]
|
|
267
|
+
|
|
268
|
+
# 替换
|
|
269
|
+
SensitiveUtil.replace("这是一段包含敏感词的文本") # "这是一段包含**的文本"
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### 验证码
|
|
273
|
+
|
|
274
|
+
```python
|
|
275
|
+
from hutool.captcha import CaptchaUtil
|
|
276
|
+
|
|
277
|
+
# 线干扰验证码
|
|
278
|
+
captcha = CaptchaUtil.create_line_captcha(width=200, height=80, code_count=5)
|
|
279
|
+
code = captcha.create_code()
|
|
280
|
+
img_bytes = captcha.get_image_bytes()
|
|
281
|
+
|
|
282
|
+
# 算术验证码
|
|
283
|
+
arith = CaptchaUtil.create_arithmetic_captcha(width=200, height=80)
|
|
284
|
+
arith.create_code() # "3+5=?"
|
|
285
|
+
arith.get_result() # "8"
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### 更多工具
|
|
289
|
+
|
|
290
|
+
```python
|
|
291
|
+
from hutool.core.util import (
|
|
292
|
+
NumberUtil, ArrayUtil, RandomUtil, HexUtil, HashUtil,
|
|
293
|
+
ReUtil, EscapeUtil, PhoneUtil, IdcardUtil, DesensitizedUtil,
|
|
294
|
+
CoordinateUtil, ZipUtil, XmlUtil, UrlUtil, VersionUtil,
|
|
295
|
+
)
|
|
296
|
+
from hutool.core.codec import Base64
|
|
297
|
+
from hutool.core.io import FileUtil, IoUtil, PathUtil
|
|
298
|
+
from hutool.json_util import JSONUtil
|
|
299
|
+
from hutool.cache import CacheUtil
|
|
300
|
+
from hutool.extra import PinyinUtil, EmojiUtil, TemplateUtil
|
|
301
|
+
from hutool.jwt_util import JWTUtil
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## 📁 项目结构
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
hutool-python/
|
|
310
|
+
├── hutool/ # Python 包
|
|
311
|
+
│ ├── __init__.py
|
|
312
|
+
│ ├── core/ # 核心模块(对应 hutool-core)
|
|
313
|
+
│ │ ├── util/ # 核心工具类(25 个)
|
|
314
|
+
│ │ ├── io/ # IO 工具类(6 个)
|
|
315
|
+
│ │ ├── text/ # 文本工具类(3 个)
|
|
316
|
+
│ │ ├── date.py # 日期工具
|
|
317
|
+
│ │ ├── coll.py # 集合工具
|
|
318
|
+
│ │ ├── map.py # Map 工具
|
|
319
|
+
│ │ ├── bean.py # Bean 工具
|
|
320
|
+
│ │ ├── codec.py # 编解码工具
|
|
321
|
+
│ │ ├── net.py # 网络工具
|
|
322
|
+
│ │ ├── math_util.py # 数学工具
|
|
323
|
+
│ │ └── tree.py # 树工具
|
|
324
|
+
│ ├── http/ # HTTP 客户端(基于 httpx)
|
|
325
|
+
│ ├── json_util.py # JSON 工具
|
|
326
|
+
│ ├── crypto/ # 加密工具(基于 cryptography)
|
|
327
|
+
│ ├── cache/ # 缓存工具(FIFO/LFU/LRU/Timed)
|
|
328
|
+
│ ├── captcha/ # 验证码(基于 Pillow)
|
|
329
|
+
│ ├── dfa/ # 敏感词过滤(DFA 算法)
|
|
330
|
+
│ ├── extra/ # 扩展工具(拼音/Emoji/模板/二维码)
|
|
331
|
+
│ ├── cron/ # 定时任务
|
|
332
|
+
│ ├── jwt_util.py # JWT 工具
|
|
333
|
+
│ └── setting/ # 配置工具(YAML/Properties)
|
|
334
|
+
├── tests/ # 测试(47 个测试文件,613 个测试用例)
|
|
335
|
+
├── requirements.txt
|
|
336
|
+
└── setup.py
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## 🧪 运行测试
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
# 安装开发依赖
|
|
345
|
+
pip install pytest
|
|
346
|
+
|
|
347
|
+
# 运行全部测试
|
|
348
|
+
pytest tests/ -v
|
|
349
|
+
|
|
350
|
+
# 运行核心模块测试
|
|
351
|
+
pytest tests/test_core/ -v
|
|
352
|
+
|
|
353
|
+
# 运行单个模块测试
|
|
354
|
+
pytest tests/test_core/test_str_util.py -v
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## 🔧 依赖清单
|
|
360
|
+
|
|
361
|
+
| 依赖库 | 用途 | 对应模块 |
|
|
362
|
+
|--------|------|---------|
|
|
363
|
+
| `pendulum>=3.0` | 日期时间处理 | `core/date.py` |
|
|
364
|
+
| `httpx>=0.27` | HTTP 客户端 | `http/` |
|
|
365
|
+
| `cryptography>=42.0` | 加密算法 | `crypto/` |
|
|
366
|
+
| `qrcode[pil]>=7.0` | 二维码生成 | `extra/qr_code_util.py` |
|
|
367
|
+
| `Pillow>=10.0` | 图像处理(验证码) | `captcha/` |
|
|
368
|
+
| `pypinyin>=0.50` | 中文拼音转换 | `extra/pinyin_util.py` |
|
|
369
|
+
| `emoji>=2.0` | Emoji 处理 | `extra/emoji_util.py` |
|
|
370
|
+
| `jinja2>=3.0` | 模板引擎 | `extra/template_util.py` |
|
|
371
|
+
| `pyjwt>=2.8` | JWT 处理 | `jwt_util.py` |
|
|
372
|
+
| `pyyaml>=6.0` | YAML 解析 | `setting/yaml_util.py` |
|
|
373
|
+
| `sortedcontainers>=2.0` | 有序容器 | `cache/` |
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
## 📝 Java Hutool 与 Hutool-Python 对照
|
|
378
|
+
|
|
379
|
+
### 方法名映射规则
|
|
380
|
+
|
|
381
|
+
| Java Hutool | Hutool-Python | 示例 |
|
|
382
|
+
|------------|---------------|------|
|
|
383
|
+
| `StrUtil.isBlank()` | `StrUtil.is_blank()` | 驼峰 → 蛇形 |
|
|
384
|
+
| `DateUtil.offsetDay()` | `DateUtil.offset_day()` | 驼峰 → 蛇形 |
|
|
385
|
+
| `new DateTime()` | `DateTime()` | Python 无 `new` |
|
|
386
|
+
| `CollUtil.newArrayList()` | `CollUtil.new_array_list()` | 驼峰 → 蛇形 |
|
|
387
|
+
|
|
388
|
+
### 使用对比
|
|
389
|
+
|
|
390
|
+
```java
|
|
391
|
+
// Java Hutool
|
|
392
|
+
String uuid = IdUtil.randomUUID();
|
|
393
|
+
boolean blank = StrUtil.isBlank(" ");
|
|
394
|
+
DateTime dt = DateUtil.parse("2024-01-15");
|
|
395
|
+
String md5 = SecureUtil.md5("hello");
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
```python
|
|
399
|
+
# Hutool-Python
|
|
400
|
+
uuid = IdUtil.random_uuid()
|
|
401
|
+
blank = StrUtil.is_blank(" ")
|
|
402
|
+
dt = DateUtil.parse("2024-01-15")
|
|
403
|
+
md5 = DigestUtil.md5_hex("hello")
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
## 🏗️ 贡献指南
|
|
409
|
+
|
|
410
|
+
欢迎为 Hutool-Python 贡献代码!请遵循以下原则:
|
|
411
|
+
|
|
412
|
+
1. **保持 Hutool 风格**:类名使用 PascalCase,方法名使用 snake_case
|
|
413
|
+
2. **中文注释**:所有新增方法须包含中文文档注释,格式为 Sphinx 风格(`:param:` / `:return:` / `:raises:`)
|
|
414
|
+
3. **编写测试**:新增方法须附带 pytest 测试用例
|
|
415
|
+
4. **不引入额外依赖**:尽量使用 Python 标准库,仅在必要时引入第三方依赖
|
|
416
|
+
|
|
417
|
+
### 贡献步骤
|
|
418
|
+
|
|
419
|
+
1. Fork 项目
|
|
420
|
+
2. 创建功能分支 (`git checkout -b feature/xxx`)
|
|
421
|
+
3. 提交代码 (`git commit -m 'Add xxx feature'`)
|
|
422
|
+
4. 推送到分支 (`git push origin feature/xxx`)
|
|
423
|
+
5. 创建 Pull Request
|
|
424
|
+
|
|
425
|
+
---
|
|
426
|
+
|
|
427
|
+
## 📖 相关链接
|
|
428
|
+
|
|
429
|
+
- [Hutool-Python 在线文档](https://wgp520.github.io/hutool-python/)
|
|
430
|
+
- [Java Hutool 官方仓库](https://github.com/dromara/hutool)
|
|
431
|
+
- [Java Hutool 中文文档](https://doc.hutool.cn/pages/index/)
|
|
432
|
+
- [Hutool API 文档](https://plus.hutool.cn/apidocs/)
|
|
433
|
+
|
|
434
|
+
---
|
|
435
|
+
|
|
436
|
+
## 📄 许可证
|
|
437
|
+
|
|
438
|
+
本项目基于 [木兰宽松许可证, 第2版](https://license.coscl.org.cn/MulanPSL2) 开源,与 Java Hutool 保持一致。
|