Skip to content

owasp-sbot/OSBot-Utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2,863 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

OSBot-Utils

Current Release Python Type-Safe Caching codecov

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, floats
  • decorators/methods β€” Caching, exception capture, timing, validation
  • helpers/html β€” HTML ↔ dict ↔ tag classes
  • helpers/ast β€” Python AST parsing, visiting, merging
  • helpers/sqlite β€” High-level SQLite APIs, schema generation, temp DBs
  • helpers/ssh β€” SSH/SCP execution with caching
  • helpers/llms β€” LLM request/response handling with caching
  • helpers/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.

About

Project with multiple Util classes (to streamline development)

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 5

Languages