Skip to main content

A collection of utility functions and tools for Python development

Project description

obutills

A collection of utility functions and tools for Python development.

Installation

pip install obutills

Features

  • Safe System Commands: Execute system commands safely with safe_system
  • File Utilities: Safely manage files with utilities like safe_mkdir, safe_remove, etc.
  • Configuration Management: Handle application configuration with ConfigManager
  • Logging Utilities: Set up logging easily with setup_logger

Usage Examples

Safe System Commands

from obutills import safe_system

# Execute a command and get the output
output = safe_system("echo Hello World")
print(output)  # Prints: Hello World

# With more options
output = safe_system("ls -la", cwd="/tmp", timeout=5)

File Utilities

from obutills import safe_mkdir, safe_remove, safe_read_json, safe_write_json

# Create directories safely
safe_mkdir("/path/to/directory")

# Write and read JSON
data = {"key": "value"}
safe_write_json("/path/to/file.json", data)
loaded_data = safe_read_json("/path/to/file.json")

# Use temporary files
from obutills import TempFileContext

with TempFileContext() as tmp:
    tmp_file = tmp.create_file(content="test data")
    # Use tmp_file...
# File is automatically deleted when context exits

Configuration Management

from obutills import ConfigManager, get_app_config_dir

# Get platform-specific config directory
config_dir = get_app_config_dir("myapp")

# Load configuration from file with environment variable overrides
config = ConfigManager("config.yaml", env_prefix="MYAPP_")

# Access configuration values
database_url = config.get("database.url", "default_url")
debug_mode = config.get("debug", False)

# Set and save configuration
config.set("logging.level", "DEBUG")
config.save()

Logging Utilities

from obutills import setup_logger, log_function_call

# Set up a logger with file and console output
logger = setup_logger(
    name="myapp",
    level="INFO",
    log_file="/path/to/app.log",
    json_format=False
)

# Use decorator to log function calls
@log_function_call()
def add(a, b):
    return a + b

result = add(1, 2)  # Logs function call and result

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

obutills-0.1.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

obutills-0.1.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file obutills-0.1.0.tar.gz.

File metadata

  • Download URL: obutills-0.1.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for obutills-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c5e5a73a3676fdccfa6481a7d14e8fde79add41062506ea9264c5dd9ff78c375
MD5 59171ad759eae73392212381a67eb02e
BLAKE2b-256 233f34c40ff2932c0e92c9dd5ffcd195e66273a9dad728d6daa6eaea8e03b931

See more details on using hashes here.

File details

Details for the file obutills-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: obutills-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for obutills-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5dc89e20c5e4823d517a415aeb6706ae5145e1cfc060eab26e9558d59df3be9
MD5 3e9f0fea9e0f32a14cbcf6a0c8dc8efd
BLAKE2b-256 0dc5741eb5188d622c03403a7d30b1a467d16a1c26c79482f4217ead5d0befcb

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