Bandit
A lightweight Python library for debugging and logging, providing tools to retrieve script and function names dynamically. Ideal for quick insights into code execution without heavy dependencies.
Installation
Install bandit-log from PyPI:
pip install bandit-log
Features
- Retrieve the current script name and function name with simple static methods.
- Use a decorator to log execution details automatically.
- No external dependencies, pure Python.
Usage
Here’s a quick example to get you started:
from bandit_log.bandit import Bandit
# Decorate a function to log its name
@Bandit.universal_print(show_script=False)
def power_of_five(n):
return 5 ** n
# Call the function
print(power_of_five(3)) # Outputs: "Func: power_of_five" followed by 125
# Get script and function names manually
script, func = Bandit.names()
print(f"Running in {script}, called from {func}")
API Reference
Bandit.universal_print(show_script=True, show_func=True)
A decorator that prints the script name and/or function name before executing the function.
- Arguments:
show_script(bool): IfTrue, prints the script name. Default:True.show_func(bool): IfTrue, prints the function name. Default:True.
- Example:
@Bandit.universal_print(show_script=False) def my_func(): print("Hello!") my_func() # Outputs: "Func: my_func" then "Hello!"
Bandit.names()
Returns a tuple of the current script name and the calling function name.
- Returns:
(script_name, function_name) - Example:
script, func = Bandit.names() print(script, func) # e.g., "example.py some_function"
Bandit.func_name()
Returns the name of the calling function.
- Returns:
str - Example:
def test(): print(Bandit.func_name()) # Outputs: "test" test()
Bandit.script_name()
Returns the name of the current script.
- Returns:
str - Example:
print(Bandit.script_name()) # e.g., "example.py"
Requirements
- Python 3.7 or higher
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Feel free to open issues or submit pull requests on GitHub.
Made with ❤️ by somke
Metadata
Release files for bandit-log 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| bandit_log-0.1.2.tar.gz | 3.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bandit_log-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.9 kB
Release files / bandit_log-0.1.2.tar.gz
| Download URL | bandit_log-0.1.2.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee5e1dea8d4212f9306d202b01f39d7f3825196ff1fc52989e0c52a9b22a5d23
|
|
BLAKE2b-256 checksum How to use checksums |
844b200c173840ad888aa43f6a7a0805f69971168e1350894acd5afb135d9146
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / bandit_log-0.1.2-py3-none-any.whl
| Download URL | bandit_log-0.1.2-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52083356744a5d5268e0e8629d3f02dd6b91838377b6be7c7e4b13e157719c06
|
|
BLAKE2b-256 checksum How to use checksums |
f6b06fe078f054ec79d503923e4c119b0d710caa6e2f0370dcebc58fb32684b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for bandit-log 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.