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.
- π‘οΈ 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
pip install osbot-utils
From source:
pip install git+https://github.com/owasp-sbot/OSBot-Utils.git@dev
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_'
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
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))
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())
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)
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 β β
β ββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββ
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
- Strong runtime type validation with Type-Safe classes
- Consistent patterns for caching and decorators
- Rich helper library to avoid reinventing the wheel
- Deterministic caching with persistence options
- Safe, validated data structures at integration boundaries
- Lightweight, dependency-minimal utilities
- Standardized approach to cross-cutting concerns (logging, tracing, caching)
- Modular helpers to fit many contexts (CLI, web apps, serverless)
Pull requests are welcome!
Check existing patterns in /helpers
and /decorators
for style guidance.
Licensed under the Apache 2.0 License.