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.72.0.tar.gz (363.2 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.72.0-py3-none-any.whl (661.3 kB view details)

Uploaded Python 3

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

Hashes for osbot_utils-3.72.0.tar.gz
Algorithm Hash digest
SHA256 d8665738b228016d8d3e54b80298b278c3d75f66ef885fd3a7453fcd8cc84813
MD5 1aba4d97436ade974ef9ec09e821f6ea
BLAKE2b-256 10d5b9269318374f523b727750a84db2966684c4313b423e92b37b25e4ea8e10

See more details on using hashes here.

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

Hashes for osbot_utils-3.72.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0dda6cdd3e0359d74e33ff63c30b7d2386fe099c021691c16ac0b0af144dfe6a
MD5 8492a76d377fc819ca6e03da48a56f77
BLAKE2b-256 fb0a05c582d45b42d19f6dbf3891b96220b0e28b257c08c4ca5b7978d70bfd76

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