devkitx 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.
- devkitx-1.0.0/.gitignore +15 -0
- devkitx-1.0.0/LICENSE +0 -0
- devkitx-1.0.0/PKG-INFO +560 -0
- devkitx-1.0.0/README.md +513 -0
- devkitx-1.0.0/examples/README.md +154 -0
- devkitx-1.0.0/pyproject.toml +95 -0
- devkitx-1.0.0/src/devtools_py/__init__.py +62 -0
- devkitx-1.0.0/src/devtools_py/__main__.py +457 -0
- devkitx-1.0.0/src/devtools_py/async_utils.py +436 -0
- devkitx-1.0.0/src/devtools_py/cli_utils.py +320 -0
- devkitx-1.0.0/src/devtools_py/config_utils.py +557 -0
- devkitx-1.0.0/src/devtools_py/data_utils.py +288 -0
- devkitx-1.0.0/src/devtools_py/dev_utils.py +393 -0
- devkitx-1.0.0/src/devtools_py/file_utils.py +211 -0
- devkitx-1.0.0/src/devtools_py/http_utils.py +346 -0
- devkitx-1.0.0/src/devtools_py/json_utils.py +244 -0
- devkitx-1.0.0/src/devtools_py/log_utils.py +158 -0
- devkitx-1.0.0/src/devtools_py/py.typed +0 -0
- devkitx-1.0.0/src/devtools_py/security_utils.py +326 -0
- devkitx-1.0.0/src/devtools_py/string_utils.py +489 -0
- devkitx-1.0.0/src/devtools_py/system_utils.py +262 -0
- devkitx-1.0.0/src/devtools_py/time_utils.py +433 -0
- devkitx-1.0.0/src/devtools_py/validation_utils.py +388 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/PyJWT-2.10.1.dist-info/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/anyio-4.10.0.dist-info/licenses/LICENSE +20 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/attrs-25.3.0.dist-info/licenses/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/bcrypt-4.3.0.dist-info/LICENSE +201 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/black-25.1.0.dist-info/licenses/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/blib2to3/LICENSE +254 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/build-1.3.0.dist-info/licenses/LICENSE +20 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/certifi-2025.8.3.dist-info/licenses/LICENSE +20 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/charset_normalizer-3.4.3.dist-info/licenses/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/dev_qol_toolkit-0.1.0.dist-info/licenses/LICENSE +0 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/devtools_py-1.0.0.dist-info/licenses/LICENSE +0 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/id-1.5.0.dist-info/LICENSE +202 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/iniconfig-2.1.0.dist-info/licenses/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/jaraco.classes-3.4.0.dist-info/LICENSE +17 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/jaraco.context-6.0.1.dist-info/LICENSE +17 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/jaraco_functools-4.3.0.dist-info/licenses/LICENSE +18 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/keyring-25.6.0.dist-info/LICENSE +17 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/markdown_it_py-4.0.0.dist-info/licenses/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/mdurl-0.1.2.dist-info/LICENSE +46 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/more_itertools-10.8.0.dist-info/licenses/LICENSE +19 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/mypy/typeshed/LICENSE +237 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/mypy-1.18.1.dist-info/licenses/LICENSE +229 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/mypy_extensions-1.1.0.dist-info/licenses/LICENSE +27 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/nh3-0.3.0.dist-info/licenses/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/packaging-25.0.dist-info/licenses/LICENSE +3 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pathspec-0.12.1.dist-info/LICENSE +373 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pip-25.2.dist-info/licenses/src/pip/_vendor/certifi/LICENSE +20 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pip-25.2.dist-info/licenses/src/pip/_vendor/distro/LICENSE +202 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pip-25.2.dist-info/licenses/src/pip/_vendor/packaging/LICENSE +3 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pip-25.2.dist-info/licenses/src/pip/_vendor/pkg_resources/LICENSE +17 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pip-25.2.dist-info/licenses/src/pip/_vendor/platformdirs/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pip-25.2.dist-info/licenses/src/pip/_vendor/pygments/LICENSE +25 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pip-25.2.dist-info/licenses/src/pip/_vendor/pyproject_hooks/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pip-25.2.dist-info/licenses/src/pip/_vendor/requests/LICENSE +175 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pip-25.2.dist-info/licenses/src/pip/_vendor/resolvelib/LICENSE +13 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pip-25.2.dist-info/licenses/src/pip/_vendor/rich/LICENSE +19 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pip-25.2.dist-info/licenses/src/pip/_vendor/tomli/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pip-25.2.dist-info/licenses/src/pip/_vendor/tomli_w/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pip-25.2.dist-info/licenses/src/pip/_vendor/truststore/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/platformdirs-4.4.0.dist-info/licenses/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pluggy-1.6.0.dist-info/licenses/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pygments-2.19.2.dist-info/licenses/LICENSE +25 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pyproject_hooks-1.2.0.dist-info/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pytest-8.4.2.dist-info/licenses/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pytest_asyncio-1.2.0.dist-info/licenses/LICENSE +201 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/pytest_cov-7.0.0.dist-info/licenses/LICENSE +21 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/readme_renderer-44.0.dist-info/LICENSE +174 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/requests-2.32.5.dist-info/licenses/LICENSE +175 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/requests_toolbelt-1.0.0.dist-info/LICENSE +13 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/rfc3986-2.0.0.dist-info/LICENSE +13 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/rich-14.1.0.dist-info/LICENSE +19 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/ruff-0.13.0.dist-info/licenses/LICENSE +430 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/sniffio-1.3.1.dist-info/LICENSE +3 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/sortedcontainers-2.4.0.dist-info/LICENSE +13 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/twine-6.2.0.dist-info/licenses/LICENSE +174 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/types_requests-2.32.4.20250809.dist-info/licenses/LICENSE +237 -0
- devkitx-1.0.0/venv/lib/python3.13/site-packages/typing_extensions-4.15.0.dist-info/licenses/LICENSE +279 -0
devkitx-1.0.0/.gitignore
ADDED
devkitx-1.0.0/LICENSE
ADDED
|
File without changes
|
devkitx-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: devkitx
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: DevKitX: Comprehensive quality-of-life utilities for Python developers including JSON, HTTP, async, security, validation, and more.
|
|
5
|
+
Project-URL: Homepage, https://github.com/ladycami/devtools-py
|
|
6
|
+
Project-URL: Issues, https://github.com/ladycami/devtools-py/issues
|
|
7
|
+
Project-URL: Documentation, https://github.com/ladycami/devtools-py#readme
|
|
8
|
+
Project-URL: Repository, https://github.com/ladycami/devtools-py.git
|
|
9
|
+
Author-email: LadyCami <ladycami@serityops.com>
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: async,bcrypt,cli,colored-output,configuration,cross-platform,debugging,developer-tools,devtools,env-files,files,http,json,jwt,logging,profiling,progress-bars,retry-logic,security,string-manipulation,system-utils,time-utils,toml,type-safe,utilities,validation,yaml
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
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 :: Internet :: WWW/HTTP :: HTTP Servers
|
|
25
|
+
Classifier: Topic :: Security :: Cryptography
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Classifier: Topic :: System :: Systems Administration
|
|
28
|
+
Classifier: Topic :: Text Processing :: General
|
|
29
|
+
Classifier: Topic :: Utilities
|
|
30
|
+
Classifier: Typing :: Typed
|
|
31
|
+
Requires-Python: >=3.10
|
|
32
|
+
Requires-Dist: bcrypt>=4.0.0
|
|
33
|
+
Requires-Dist: click>=8.0.0
|
|
34
|
+
Requires-Dist: httpx<0.28,>=0.27
|
|
35
|
+
Requires-Dist: pyjwt>=2.8.0
|
|
36
|
+
Requires-Dist: rich>=13.0.0
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: black>=24.8; extra == 'dev'
|
|
39
|
+
Requires-Dist: build>=1.0.0; extra == 'dev'
|
|
40
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
41
|
+
Requires-Dist: pytest-cov>=5; extra == 'dev'
|
|
42
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
43
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
44
|
+
Requires-Dist: twine>=5.0.0; extra == 'dev'
|
|
45
|
+
Requires-Dist: types-requests; extra == 'dev'
|
|
46
|
+
Description-Content-Type: text/markdown
|
|
47
|
+
|
|
48
|
+
# DevKitX
|
|
49
|
+
|
|
50
|
+
**Comprehensive quality-of-life utilities for Python developers**
|
|
51
|
+
|
|
52
|
+
A modern, type-safe toolkit providing essential utilities for common development tasks including JSON manipulation, file operations, logging, CLI utilities, HTTP clients, data processing, string manipulation, configuration management, system operations, async utilities, development tools, security functions, time utilities, and validation.
|
|
53
|
+
|
|
54
|
+
[](https://www.python.org/downloads/)
|
|
55
|
+
[](LICENSE)
|
|
56
|
+
[](https://mypy-lang.org/)
|
|
57
|
+
|
|
58
|
+
## Features
|
|
59
|
+
|
|
60
|
+
- 🚀 **Modern Python**: Built for Python 3.10+ with full type annotations
|
|
61
|
+
- 📦 **Comprehensive**: 14+ utility modules covering common development needs
|
|
62
|
+
- ⚡ **Async Support**: Async-compatible utilities and bridges between sync/async code
|
|
63
|
+
- 🔒 **Security**: Built-in security utilities for hashing, JWT tokens, and input sanitization
|
|
64
|
+
- 🛠️ **Developer Tools**: Profiling, debugging, and testing utilities
|
|
65
|
+
- 🌐 **HTTP Client**: Robust HTTP utilities with retry logic and async support
|
|
66
|
+
- 📝 **Configuration**: Multi-format config management (JSON, YAML, TOML, .env)
|
|
67
|
+
- 🎨 **CLI Tools**: Rich terminal output with colors, progress bars, and interactive prompts
|
|
68
|
+
- 🔧 **System Utils**: Cross-platform system information and process management
|
|
69
|
+
- ✅ **Validation**: Comprehensive input validation and schema checking
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install devkitx
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Quick Start
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from devtools_py import json_utils, string_utils, http_utils, config_utils
|
|
81
|
+
|
|
82
|
+
# JSON operations with enhanced features
|
|
83
|
+
data = json_utils.load_json("config.json")
|
|
84
|
+
flat_data = json_utils.flatten_json(data)
|
|
85
|
+
pretty_output = json_utils.pretty_json(data, color=True)
|
|
86
|
+
|
|
87
|
+
# String manipulation and validation
|
|
88
|
+
snake_case = string_utils.to_snake_case("CamelCaseString")
|
|
89
|
+
is_valid_email = string_utils.validate_email("user@example.com")
|
|
90
|
+
clean_filename = string_utils.sanitize_filename("file<name>.txt")
|
|
91
|
+
|
|
92
|
+
# HTTP requests with automatic retries
|
|
93
|
+
response = http_utils.api_request("GET", "https://api.example.com/data")
|
|
94
|
+
client = http_utils.BaseAPIClient("https://api.example.com")
|
|
95
|
+
users = client.get("/users")
|
|
96
|
+
|
|
97
|
+
# Configuration management
|
|
98
|
+
config = config_utils.ConfigManager(["config.json", "config.yaml"])
|
|
99
|
+
config.load()
|
|
100
|
+
database_url = config.get("database.url", "sqlite:///default.db")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Module Overview
|
|
104
|
+
|
|
105
|
+
### Core Utilities
|
|
106
|
+
|
|
107
|
+
#### JSON Utils (`json_utils`)
|
|
108
|
+
Enhanced JSON operations with pretty printing and flattening:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from devtools_py import json_utils
|
|
112
|
+
|
|
113
|
+
# Load and save JSON with automatic formatting
|
|
114
|
+
data = json_utils.load_json("config.json")
|
|
115
|
+
json_utils.save_json(data, "backup.json", pretty=True)
|
|
116
|
+
|
|
117
|
+
# Flatten nested JSON for easier processing
|
|
118
|
+
nested = {"user": {"profile": {"name": "John", "age": 30}}}
|
|
119
|
+
flat = json_utils.flatten_json(nested)
|
|
120
|
+
# Result: {"user.profile.name": "John", "user.profile.age": 30}
|
|
121
|
+
|
|
122
|
+
# Pretty print with optional syntax highlighting
|
|
123
|
+
print(json_utils.pretty_json(data, color=True))
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### File Utils (`file_utils`)
|
|
127
|
+
Cross-platform file operations with safety features:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from devtools_py import file_utils
|
|
131
|
+
|
|
132
|
+
# Find files with glob patterns or exact names
|
|
133
|
+
python_files = file_utils.find_file("*.py", "src")
|
|
134
|
+
config_file = file_utils.find_file("config.json", ".")
|
|
135
|
+
|
|
136
|
+
# Safe file operations
|
|
137
|
+
file_utils.ensure_dir("output/data")
|
|
138
|
+
file_utils.atomic_write("important.json", '{"key": "value"}')
|
|
139
|
+
file_utils.copy_file("source.txt", "backup.txt", overwrite=False)
|
|
140
|
+
|
|
141
|
+
# Check permissions
|
|
142
|
+
if file_utils.is_writable("output.txt"):
|
|
143
|
+
# Safe to write
|
|
144
|
+
pass
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### String Utils (`string_utils`)
|
|
148
|
+
Comprehensive string manipulation and validation:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from devtools_py import string_utils
|
|
152
|
+
|
|
153
|
+
# Case conversions
|
|
154
|
+
string_utils.to_snake_case("CamelCase") # "camel_case"
|
|
155
|
+
string_utils.to_camel_case("snake_case") # "snakeCase"
|
|
156
|
+
string_utils.to_pascal_case("kebab-case") # "KebabCase"
|
|
157
|
+
string_utils.to_kebab_case("PascalCase") # "pascal-case"
|
|
158
|
+
|
|
159
|
+
# Validation
|
|
160
|
+
string_utils.validate_email("user@example.com") # True
|
|
161
|
+
string_utils.validate_url("https://example.com") # True
|
|
162
|
+
|
|
163
|
+
# Text processing
|
|
164
|
+
string_utils.sanitize_filename("file<name>.txt") # "file_name_.txt"
|
|
165
|
+
string_utils.truncate_text("Long text here", 10) # "Long te..."
|
|
166
|
+
urls = string_utils.extract_urls("Visit https://example.com for info")
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Advanced Utilities
|
|
170
|
+
|
|
171
|
+
#### HTTP Utils (`http_utils`)
|
|
172
|
+
Robust HTTP client with retry logic and async support:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from devtools_py import http_utils
|
|
176
|
+
import asyncio
|
|
177
|
+
|
|
178
|
+
# Synchronous requests with automatic retries
|
|
179
|
+
response = http_utils.api_request(
|
|
180
|
+
"POST",
|
|
181
|
+
"https://api.example.com/users",
|
|
182
|
+
json_body={"name": "John", "email": "john@example.com"},
|
|
183
|
+
headers={"Authorization": "Bearer token"},
|
|
184
|
+
retries=3
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# API client for consistent base URL and headers
|
|
188
|
+
client = http_utils.BaseAPIClient(
|
|
189
|
+
"https://api.example.com",
|
|
190
|
+
headers={"Authorization": "Bearer token"}
|
|
191
|
+
)
|
|
192
|
+
users = client.get("/users")
|
|
193
|
+
new_user = client.post("/users", json_body={"name": "Jane"})
|
|
194
|
+
|
|
195
|
+
# Async support
|
|
196
|
+
async def fetch_data():
|
|
197
|
+
async_client = http_utils.AsyncAPIClient("https://api.example.com")
|
|
198
|
+
return await async_client.get("/data")
|
|
199
|
+
|
|
200
|
+
# Batch requests with concurrency control
|
|
201
|
+
requests = [
|
|
202
|
+
("GET", "https://api.example.com/users/1", {}),
|
|
203
|
+
("GET", "https://api.example.com/users/2", {}),
|
|
204
|
+
]
|
|
205
|
+
responses = await http_utils.async_batch_requests(requests, concurrency_limit=5)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### Config Utils (`config_utils`)
|
|
209
|
+
Multi-format configuration management:
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
from devtools_py import config_utils
|
|
213
|
+
|
|
214
|
+
# Load from multiple sources with precedence
|
|
215
|
+
config = config_utils.ConfigManager([
|
|
216
|
+
"config.json",
|
|
217
|
+
"config.yaml",
|
|
218
|
+
"local.env"
|
|
219
|
+
])
|
|
220
|
+
config.load()
|
|
221
|
+
|
|
222
|
+
# Type-safe configuration access
|
|
223
|
+
database_url = config.get("database.url", "sqlite:///default.db", str)
|
|
224
|
+
debug_mode = config.get("debug", False, bool)
|
|
225
|
+
max_connections = config.get("database.max_connections", 10, int)
|
|
226
|
+
|
|
227
|
+
# Environment variable integration
|
|
228
|
+
config.merge_env_vars("MYAPP_") # Loads MYAPP_* env vars
|
|
229
|
+
|
|
230
|
+
# Save configuration
|
|
231
|
+
config.set("new.setting", "value")
|
|
232
|
+
config.save("updated_config.json")
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
#### Security Utils (`security_utils`)
|
|
236
|
+
Security and cryptographic utilities:
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
from devtools_py import security_utils
|
|
240
|
+
|
|
241
|
+
# Password hashing with bcrypt
|
|
242
|
+
hashed = security_utils.hash_password("my_secure_password")
|
|
243
|
+
is_valid = security_utils.verify_password("my_secure_password", hashed)
|
|
244
|
+
|
|
245
|
+
# Secure key generation
|
|
246
|
+
secret_key = security_utils.generate_secret_key(32)
|
|
247
|
+
uuid = security_utils.generate_uuid()
|
|
248
|
+
|
|
249
|
+
# Data hashing
|
|
250
|
+
file_hash = security_utils.hash_data(b"file content", "sha256")
|
|
251
|
+
|
|
252
|
+
# JWT tokens
|
|
253
|
+
payload = {"user_id": 123, "role": "admin"}
|
|
254
|
+
token = security_utils.generate_jwt_token(payload, secret_key, expires_in=3600)
|
|
255
|
+
decoded = security_utils.verify_jwt_token(token, secret_key)
|
|
256
|
+
|
|
257
|
+
# Input sanitization
|
|
258
|
+
clean_input = security_utils.sanitize_input("<script>alert('xss')</script>")
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
#### Async Utils (`async_utils`)
|
|
262
|
+
Bridge between sync and async code:
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
from devtools_py import async_utils
|
|
266
|
+
import asyncio
|
|
267
|
+
|
|
268
|
+
# Convert sync functions to async
|
|
269
|
+
def slow_sync_function(x):
|
|
270
|
+
time.sleep(1)
|
|
271
|
+
return x * 2
|
|
272
|
+
|
|
273
|
+
async_func = async_utils.sync_to_async(slow_sync_function)
|
|
274
|
+
result = await async_func(5) # Non-blocking
|
|
275
|
+
|
|
276
|
+
# Convert async functions to sync
|
|
277
|
+
async def async_function(x):
|
|
278
|
+
await asyncio.sleep(0.1)
|
|
279
|
+
return x * 2
|
|
280
|
+
|
|
281
|
+
sync_func = async_utils.async_to_sync(async_function)
|
|
282
|
+
result = sync_func(5) # Blocks until complete
|
|
283
|
+
|
|
284
|
+
# Concurrency control
|
|
285
|
+
tasks = [fetch_data(url) for url in urls]
|
|
286
|
+
results = await async_utils.gather_with_limit(5, *tasks) # Max 5 concurrent
|
|
287
|
+
|
|
288
|
+
# Retry with exponential backoff
|
|
289
|
+
result = await async_utils.retry_async(
|
|
290
|
+
unreliable_api_call,
|
|
291
|
+
retries=3,
|
|
292
|
+
delay=1.0,
|
|
293
|
+
exceptions=(ConnectionError,)
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
# Async file operations
|
|
297
|
+
async_fm = async_utils.AsyncFileManager()
|
|
298
|
+
content = await async_fm.read_text("large_file.txt")
|
|
299
|
+
await async_fm.write_text("output.txt", "Hello, World!")
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
#### Development Utils (`dev_utils`)
|
|
303
|
+
Debugging and development tools:
|
|
304
|
+
|
|
305
|
+
```python
|
|
306
|
+
from devtools_py import dev_utils
|
|
307
|
+
|
|
308
|
+
# Function timing and profiling
|
|
309
|
+
@dev_utils.time_function
|
|
310
|
+
@dev_utils.profile_memory
|
|
311
|
+
def expensive_operation():
|
|
312
|
+
return [i**2 for i in range(10000)]
|
|
313
|
+
|
|
314
|
+
# Pretty printing complex objects
|
|
315
|
+
complex_data = {"users": [{"id": 1, "nested": {"deep": "value"}}]}
|
|
316
|
+
print(dev_utils.pretty_print_object(complex_data, max_depth=3))
|
|
317
|
+
|
|
318
|
+
# Test data generation
|
|
319
|
+
schema = {"name": str, "age": int, "active": bool}
|
|
320
|
+
test_data = dev_utils.generate_test_data(schema, count=10)
|
|
321
|
+
|
|
322
|
+
# Function benchmarking
|
|
323
|
+
def method1(): return sum(range(1000))
|
|
324
|
+
def method2(): return sum([i for i in range(1000)])
|
|
325
|
+
|
|
326
|
+
results = dev_utils.benchmark_functions(method1, method2, iterations=1000)
|
|
327
|
+
print(f"method1: {results['method1']:.4f}s avg")
|
|
328
|
+
|
|
329
|
+
# Mock HTTP server for testing
|
|
330
|
+
responses = {
|
|
331
|
+
"/api/users": {"users": [{"id": 1, "name": "John"}]},
|
|
332
|
+
"/api/status": {"status": "ok"}
|
|
333
|
+
}
|
|
334
|
+
server = dev_utils.MockHTTPServer(responses)
|
|
335
|
+
url = server.start()
|
|
336
|
+
# Make requests to url + "/api/users"
|
|
337
|
+
server.stop()
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### System and Validation
|
|
341
|
+
|
|
342
|
+
#### System Utils (`system_utils`)
|
|
343
|
+
Cross-platform system operations:
|
|
344
|
+
|
|
345
|
+
```python
|
|
346
|
+
from devtools_py import system_utils
|
|
347
|
+
|
|
348
|
+
# System information
|
|
349
|
+
sys_info = system_utils.get_system_info()
|
|
350
|
+
python_info = system_utils.get_python_info()
|
|
351
|
+
|
|
352
|
+
# Command execution with timeout
|
|
353
|
+
result = system_utils.run_command(
|
|
354
|
+
["python", "--version"],
|
|
355
|
+
timeout=5.0,
|
|
356
|
+
cwd="/path/to/directory"
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
# Async command execution
|
|
360
|
+
result = await system_utils.run_command_async(["ls", "-la"])
|
|
361
|
+
|
|
362
|
+
# Utility functions
|
|
363
|
+
executable_path = system_utils.find_executable("python")
|
|
364
|
+
env_vars = system_utils.get_env_vars("PYTHON_")
|
|
365
|
+
is_root = system_utils.is_admin()
|
|
366
|
+
free_port = system_utils.get_free_port(8000)
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
#### Validation Utils (`validation_utils`)
|
|
370
|
+
Comprehensive input validation:
|
|
371
|
+
|
|
372
|
+
```python
|
|
373
|
+
from devtools_py import validation_utils
|
|
374
|
+
|
|
375
|
+
# Schema validation
|
|
376
|
+
schema = {"name": str, "age": int, "active": bool}
|
|
377
|
+
data = {"name": "John", "age": 30, "active": True}
|
|
378
|
+
errors = validation_utils.validate_schema(data, schema)
|
|
379
|
+
|
|
380
|
+
# Range and length validation
|
|
381
|
+
validation_utils.validate_range(25, 18, 65) # True
|
|
382
|
+
validation_utils.validate_length("hello", 3, 10) # True
|
|
383
|
+
validation_utils.validate_regex("test123", r"^\w+\d+$") # True
|
|
384
|
+
|
|
385
|
+
# JSON schema validation
|
|
386
|
+
json_schema = {
|
|
387
|
+
"type": "object",
|
|
388
|
+
"properties": {
|
|
389
|
+
"name": {"type": "string", "minLength": 1},
|
|
390
|
+
"age": {"type": "integer", "minimum": 0}
|
|
391
|
+
},
|
|
392
|
+
"required": ["name"]
|
|
393
|
+
}
|
|
394
|
+
errors = validation_utils.validate_json_schema(data, json_schema)
|
|
395
|
+
|
|
396
|
+
# Rule-based validator
|
|
397
|
+
validator = validation_utils.Validator()
|
|
398
|
+
validator.add_rule("email", lambda x: "@" in str(x), "Invalid email")
|
|
399
|
+
validator.add_rule("age", lambda x: isinstance(x, int) and x >= 0, "Invalid age")
|
|
400
|
+
errors = validator.validate({"email": "test@example.com", "age": 25})
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
#### Time Utils (`time_utils`)
|
|
404
|
+
Date and time utilities:
|
|
405
|
+
|
|
406
|
+
```python
|
|
407
|
+
from devtools_py import time_utils
|
|
408
|
+
from datetime import datetime
|
|
409
|
+
|
|
410
|
+
# Flexible date parsing
|
|
411
|
+
date = time_utils.parse_date("2024-01-15")
|
|
412
|
+
date = time_utils.parse_date("15/01/2024", ["%d/%m/%Y"])
|
|
413
|
+
|
|
414
|
+
# Duration formatting
|
|
415
|
+
duration = time_utils.format_duration(3661) # "1h 1m 1.0s"
|
|
416
|
+
|
|
417
|
+
# Business day calculations
|
|
418
|
+
is_weekday = time_utils.is_business_day(datetime(2024, 1, 15))
|
|
419
|
+
next_workday = time_utils.next_business_day(datetime(2024, 1, 12))
|
|
420
|
+
|
|
421
|
+
# Cron scheduling
|
|
422
|
+
next_run = time_utils.cron_next_run("0 9 * * 1-5") # 9 AM weekdays
|
|
423
|
+
|
|
424
|
+
# Timer utility
|
|
425
|
+
timer = time_utils.Timer()
|
|
426
|
+
timer.start()
|
|
427
|
+
# ... do work ...
|
|
428
|
+
elapsed = timer.stop()
|
|
429
|
+
|
|
430
|
+
# Or as context manager
|
|
431
|
+
with time_utils.Timer() as timer:
|
|
432
|
+
# ... do work ...
|
|
433
|
+
pass
|
|
434
|
+
print(f"Elapsed: {timer.elapsed():.2f}s")
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### CLI and Logging
|
|
438
|
+
|
|
439
|
+
#### CLI Utils (`cli_utils`)
|
|
440
|
+
Rich terminal interfaces:
|
|
441
|
+
|
|
442
|
+
```python
|
|
443
|
+
from devtools_py import cli_utils
|
|
444
|
+
|
|
445
|
+
# Interactive prompts
|
|
446
|
+
password = cli_utils.password_prompt("Enter password:", confirm=True)
|
|
447
|
+
selected = cli_utils.multi_select(["option1", "option2", "option3"])
|
|
448
|
+
|
|
449
|
+
# Progress indicators
|
|
450
|
+
for item in cli_utils.progress_bar(range(100), "Processing"):
|
|
451
|
+
# Do work with item
|
|
452
|
+
pass
|
|
453
|
+
|
|
454
|
+
with cli_utils.spinner("Loading data..."):
|
|
455
|
+
# Long running operation
|
|
456
|
+
time.sleep(2)
|
|
457
|
+
|
|
458
|
+
# Colored output and tables
|
|
459
|
+
print(cli_utils.colored_text("Success!", "green", bold=True))
|
|
460
|
+
print(cli_utils.colored_text("Warning", "yellow"))
|
|
461
|
+
|
|
462
|
+
data = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]
|
|
463
|
+
table = cli_utils.table_format(data, headers=["Name", "Age"])
|
|
464
|
+
print(table)
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
#### Log Utils (`log_utils`)
|
|
468
|
+
Enhanced logging setup:
|
|
469
|
+
|
|
470
|
+
```python
|
|
471
|
+
from devtools_py import log_utils
|
|
472
|
+
import logging
|
|
473
|
+
|
|
474
|
+
# Quick logger setup
|
|
475
|
+
logger = log_utils.setup_logging("INFO", to_file="app.log")
|
|
476
|
+
logger = log_utils.setup_logging("DEBUG", json=True, use_loguru=True)
|
|
477
|
+
|
|
478
|
+
# Time logging context manager
|
|
479
|
+
with log_utils.log_time("database_query"):
|
|
480
|
+
# Database operation
|
|
481
|
+
pass
|
|
482
|
+
# Logs: "database_query took 123.45 ms"
|
|
483
|
+
|
|
484
|
+
# Function call logging
|
|
485
|
+
@log_utils.log_calls
|
|
486
|
+
def process_data(data):
|
|
487
|
+
return {"processed": len(data)}
|
|
488
|
+
|
|
489
|
+
result = process_data([1, 2, 3])
|
|
490
|
+
# Logs function calls and returns at DEBUG level
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
## CLI Interface
|
|
494
|
+
|
|
495
|
+
The toolkit also provides a command-line interface for common operations:
|
|
496
|
+
|
|
497
|
+
```bash
|
|
498
|
+
# String manipulation
|
|
499
|
+
devkitx string convert --to snake "CamelCase"
|
|
500
|
+
devkitx string validate --email "user@example.com"
|
|
501
|
+
|
|
502
|
+
# Configuration management
|
|
503
|
+
devkitx config merge config1.json config2.yaml
|
|
504
|
+
|
|
505
|
+
# Security utilities
|
|
506
|
+
devkitx security hash --algorithm sha256 "my-data"
|
|
507
|
+
devkitx security generate --type uuid
|
|
508
|
+
|
|
509
|
+
# System information
|
|
510
|
+
devkitx system info
|
|
511
|
+
devkitx system find-executable python
|
|
512
|
+
|
|
513
|
+
# Time utilities
|
|
514
|
+
devkitx time parse "2024-01-15 14:30:00"
|
|
515
|
+
devkitx time format-duration 3661
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
## Requirements
|
|
519
|
+
|
|
520
|
+
- Python 3.10 or higher
|
|
521
|
+
- Dependencies: `httpx`, `click`, `rich`, `bcrypt`, `PyJWT`
|
|
522
|
+
|
|
523
|
+
## Development
|
|
524
|
+
|
|
525
|
+
```bash
|
|
526
|
+
# Clone the repository
|
|
527
|
+
git clone https://github.com/ladycami/devkitx.git
|
|
528
|
+
cd devkitx
|
|
529
|
+
|
|
530
|
+
# Install in development mode
|
|
531
|
+
pip install -e ".[dev]"
|
|
532
|
+
|
|
533
|
+
# Run tests
|
|
534
|
+
pytest
|
|
535
|
+
|
|
536
|
+
# Run linting
|
|
537
|
+
ruff check src/
|
|
538
|
+
black --check src/
|
|
539
|
+
mypy src/
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
## Contributing
|
|
543
|
+
|
|
544
|
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
545
|
+
|
|
546
|
+
## License
|
|
547
|
+
|
|
548
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
549
|
+
|
|
550
|
+
## Changelog
|
|
551
|
+
|
|
552
|
+
### v1.0.0 (Upcoming)
|
|
553
|
+
- Initial release with comprehensive utility modules
|
|
554
|
+
- Full type annotations and Python 3.10+ support
|
|
555
|
+
- Async utilities and HTTP client with retry logic
|
|
556
|
+
- Security utilities with JWT and bcrypt support
|
|
557
|
+
- Rich CLI interface with progress bars and colored output
|
|
558
|
+
- Multi-format configuration management
|
|
559
|
+
- Development and debugging tools
|
|
560
|
+
- Comprehensive test suite with 90%+ coverage
|