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.74.0.tar.gz (365.0 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.74.0-py3-none-any.whl (662.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: osbot_utils-3.74.0.tar.gz
  • Upload date:
  • Size: 365.0 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.74.0.tar.gz
Algorithm Hash digest
SHA256 2e90ae6f669ffac856e5749b73a9e74ffa4e840d2ff0f75514f2044a939edcfc
MD5 6c37586420f121aca1e53de76c19a283
BLAKE2b-256 d3eab7b8242e3c8311012332a3597554fabb881370bb07cfee8925ddc93a40be

See more details on using hashes here.

File details

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

File metadata

  • Download URL: osbot_utils-3.74.0-py3-none-any.whl
  • Upload date:
  • Size: 662.0 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.74.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5cd5cfa6137bfa6f4f6dff069b589b2252227bbb1751108d7761eca2aaa9340c
MD5 f28fc34f087373be9509e393420e2c07
BLAKE2b-256 cd160abdd1cc4f52817101c19eedb972013c970fcbe65a26d833c32028dbced0

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