OWASP Security Bot - Utils
Project description
OSBot-Utils
A comprehensive Python utility toolkit providing Type-Safe primitives, decorators, caching layers, HTML/AST helpers, SQLite tooling, SSH execution, LLM request pipelines, tracing, and more โ all designed to accelerate building robust, maintainable automation and integration code.
โจ Key Features
- ๐ก๏ธ Type-Safe First: Strongly typed primitives (
Safe_Str,Safe_Int,Safe_Float, etc.) with validation and sanitization - โก Multi-layer Caching: In-memory, per-instance, pickle-on-disk, temp-file, and request/response caches
- ๐๏ธ Rich Utilities: Helpers for HTML parsing/rendering, AST inspection, SSH/SCP execution, SQLite schema management, and more
- ๐ง LLM Support: Structured request builders, OpenAI API integration, schema enforcement, and persistent cache
- ๐ Tracing & Debugging: Full function call tracing with configurable depth, locals capture, and pretty output
- ๐งช Testing Utilities: Temp SQLite DBs, mockable caches, and easy test helpers
๐ฆ Installation
pip install osbot-utils
From source:
pip install git+https://github.com/owasp-sbot/OSBot-Utils.git@dev
๐ Quick Start
Using Type-Safe Primitives
from osbot_utils.type_safe.primitives.safe_str.Safe_Str import Safe_Str
class Username(Safe_Str):
max_length = 20
print(Username("alice")) # 'alice'
print(Username("invalid username!")) # 'invalid_username_'
Simple In-Memory Caching
from osbot_utils.decorators.methods.cache_on_self import cache_on_self
class DataFetcher:
@cache_on_self
def fetch(self, x):
print("Fetchingโฆ")
return x * 2
fetcher = DataFetcher()
fetcher.fetch(10) # Calls method
fetcher.fetch(10) # Returns cached result
HTML Parsing
from osbot_utils.helpers.html.transformers.Html__To__Html_Dict import html_to_dict
html_code = "<html><body><h1>Hello</h1></body></html>"
print(html_to_dict(html_code))
SQLite Dynamic Table
from osbot_utils.helpers.sqlite.Temp_Sqlite__Table import Temp_Sqlite__Table
with Temp_Sqlite__Table() as table:
table.row_schema = type("Row", (), {"name": str, "age": int})
table.create()
table.add_row_and_commit(name="Alice", age=30)
print(table.rows())
LLM Request Execution
from osbot_utils.helpers.llms.builders.LLM_Request__Builder__Open_AI import LLM_Request__Builder__Open_AI
from osbot_utils.helpers.llms.actions.LLM_Request__Execute import LLM_Request__Execute
builder = LLM_Request__Builder__Open_AI()
builder.set__model__gpt_4o().add_message__user("Say hi in JSON")
executor = LLM_Request__Execute(request_builder=builder)
response = executor.execute(builder.llm_request())
print(response.response_data)
๐๏ธ Architecture
OSBot-Utils is organized into core Type-Safe foundations with layered utilities for different domains:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Your Code โ
โ โโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโ โ
โ โ Type-Safe โ โ Decorators โ โ Helpers โ โ
โ โ Primitivesโ โ & Caching โ โ (HTML, โ โ
โ โ โ โ โ โ AST, โ โ
โ โ โ โ โ โ SQLite)โ โ
โ โโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ
โ OSBot-Utils โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Type-Safe Core Classes โ โ
โ โ Validation / Sanitization / Defaults โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Caching Layers & Decorators โ โ
โ โ @cache, @cache_on_self, pickle, tmp โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Domain Helpers โ โ
โ โ HTML, AST, SSH, LLMs, SQLite, Tracing โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Key Modules
helpers/safe_*โ Type-Safe primitives for validated strings, ints, floatsdecorators/methodsโ Caching, exception capture, timing, validationhelpers/htmlโ HTML โ dict โ tag classeshelpers/astโ Python AST parsing, visiting, merginghelpers/sqliteโ High-level SQLite APIs, schema generation, temp DBshelpers/sshโ SSH/SCP execution with cachinghelpers/llmsโ LLM request/response handling with cachinghelpers/traceโ Function call tracing with configurable output
๐ฏ Benefits
For Developers
- Strong runtime type validation with Type-Safe classes
- Consistent patterns for caching and decorators
- Rich helper library to avoid reinventing the wheel
For Production
- Deterministic caching with persistence options
- Safe, validated data structures at integration boundaries
- Lightweight, dependency-minimal utilities
For Teams
- Standardized approach to cross-cutting concerns (logging, tracing, caching)
- Modular helpers to fit many contexts (CLI, web apps, serverless)
๐ค Contributing
Pull requests are welcome!
Check existing patterns in /helpers and /decorators for style guidance.
๐ License
Licensed under the Apache 2.0 License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file osbot_utils-3.72.0.tar.gz.
File metadata
- Download URL: osbot_utils-3.72.0.tar.gz
- Upload date:
- Size: 363.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8665738b228016d8d3e54b80298b278c3d75f66ef885fd3a7453fcd8cc84813
|
|
| MD5 |
1aba4d97436ade974ef9ec09e821f6ea
|
|
| BLAKE2b-256 |
10d5b9269318374f523b727750a84db2966684c4313b423e92b37b25e4ea8e10
|
File details
Details for the file osbot_utils-3.72.0-py3-none-any.whl.
File metadata
- Download URL: osbot_utils-3.72.0-py3-none-any.whl
- Upload date:
- Size: 661.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0dda6cdd3e0359d74e33ff63c30b7d2386fe099c021691c16ac0b0af144dfe6a
|
|
| MD5 |
8492a76d377fc819ca6e03da48a56f77
|
|
| BLAKE2b-256 |
fb0a05c582d45b42d19f6dbf3891b96220b0e28b257c08c4ca5b7978d70bfd76
|