Skip to main content

OWASP Security Bot - Utils

Project description

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.

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

osbot_utils-3.73.0.tar.gz (364.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

osbot_utils-3.73.0-py3-none-any.whl (661.9 kB view details)

Uploaded Python 3

File details

Details for the file osbot_utils-3.73.0.tar.gz.

File metadata

  • Download URL: osbot_utils-3.73.0.tar.gz
  • Upload date:
  • Size: 364.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for osbot_utils-3.73.0.tar.gz
Algorithm Hash digest
SHA256 aa90b7415b8759e60ce165c47f5a4ef62dead33c8f0a2d6e43c29f071e751117
MD5 cc5243d0c3967be31249d5ba49296890
BLAKE2b-256 701038407aa3f4b5c271b464684285e273b66373d2479756b1312349aff78a64

See more details on using hashes here.

File details

Details for the file osbot_utils-3.73.0-py3-none-any.whl.

File metadata

  • Download URL: osbot_utils-3.73.0-py3-none-any.whl
  • Upload date:
  • Size: 661.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for osbot_utils-3.73.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a27d87d22a7e67afaf0b15ef97fe5daed2e05bd3c9e5ca84ab36edc8b4bebc32
MD5 c96506beaa46a87dd790835bbd5d4bf8
BLAKE2b-256 1c27ad88054f7ad138901196e5cce43c63bee3daffca580e5c976bdb8ab93e65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page