dacktool Library
dacktool is a collection of miscellaneous Python utilities designed to simplify common tasks related to file operations, data conversion (specifically JSON to dictionary), regular expression matching, and basic security functions like password hashing. Currently at version 0.0.7, it appears to be in early development with an infrequent release cadence.
Common errors
-
ModuleNotFoundError: No module named 'dacktool'
cause The dacktool library is not installed in the current Python environment.fixInstall the library using pip: `pip install dacktool` -
AttributeError: module 'dacktool' has no attribute 'read_file'
cause Attempting to import a function (like `read_file`) directly from the top-level `dacktool` package when it resides in a submodule (e.g., `dacktool.files`).fixImport the function from its specific submodule: `from dacktool.files import read_file`. -
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
cause The input string provided to `convert_json_to_dict` is not valid JSON.fixEnsure the input string is a correctly formatted JSON string, e.g., `'{"key": "value"}'`. -
FileNotFoundError: [Errno 2] No such file or directory: 'non_existent_file.txt'
cause The file path specified for `read_file` or `write_file` does not exist or is incorrect, and the operation requires the file to be present (e.g., `read_file`) or the directory to exist.fixVerify the file path is correct and accessible. If reading, ensure the file exists. If writing, ensure the parent directory exists or create it first.
Warnings
- gotcha The library is in early development (v0.0.7); APIs are subject to change without prior notice, potentially leading to breaking changes between minor versions as the project matures.
- gotcha The `security` module provides basic password hashing and verification. For production environments, ensure you understand and follow cryptographic best practices, including proper salting, iteration counts, and key stretching, as this module provides fundamental components rather than a complete security framework.
- gotcha Error handling in some utility functions might be basic. For instance, file operations may raise standard Python exceptions (`FileNotFoundError`, `PermissionError`) which should be handled explicitly by the caller in robust applications.
Install
-
pip install dacktool
Imports
- read_file
from dacktool import read_file
from dacktool.files import read_file
- convert_json_to_dict
from dacktool import convert_json_to_dict
from dacktool.convert import convert_json_to_dict
- hash_password
import dacktool.security; dacktool.security.hash_password()
from dacktool.security import hash_password
Quickstart
from dacktool.convert import convert_json_to_dict
json_data_string = '{"name": "Alice", "age": 30, "city": "New York"}'
python_dict = convert_json_to_dict(json_data_string)
print(f"JSON String: {json_data_string}")
print(f"Python Dictionary: {python_dict}")
print(f"Type of result: {type(python_dict)}")
# Example using files module (requires creating a dummy file)
from dacktool.files import write_file, read_file
import os
file_path = 'my_temp_file.txt'
content = 'Hello from dacktool!'
write_file(file_path, content)
read_content = read_file(file_path)
print(f"\nContent written to '{file_path}': {content}")
print(f"Content read from '{file_path}': {read_content}")
os.remove(file_path) # Clean up the dummy file