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.75.0.tar.gz (365.1 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.75.0-py3-none-any.whl (662.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: osbot_utils-3.75.0.tar.gz
  • Upload date:
  • Size: 365.1 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.75.0.tar.gz
Algorithm Hash digest
SHA256 cedbd44a6093a25e2ae1852edf822706163273819f4d4c91b31be2d7e7b61673
MD5 ae22dd2d2683dda10b9f3a596a22187b
BLAKE2b-256 1c970342d2c68ccfc74ab1f3285a8d1de847de13cadc9d9ae58bcfc64cbdbac8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: osbot_utils-3.75.0-py3-none-any.whl
  • Upload date:
  • Size: 662.1 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.75.0-py3-none-any.whl
Algorithm Hash digest
SHA256 784d45c959be216210bb3de07cfc3c309644073a8c0fe656e71dbfb45a294968
MD5 e6134b2b9f9059dc35d195f212675885
BLAKE2b-256 61df4960b491af1d8bc92f3bb9b04310a88698784f8feae976970b6e28d6e491

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