X Tutup
Skip to content

bertcafecito/py-toolbelt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

py-toolbelt

Python License Code style: black AWS

A collection of Python utilities and tools for common development tasks.

Features

AWS Utilities

  • S3 Object Cleanup: Delete S3 objects older than a specific date with support for dry-run mode and prefix filtering

Logging

  • JSON Logging Configuration: Pre-configured logging setup with JSON formatting
  • Sensitive Data Filtering: Automatically filter sensitive information from logs (passwords, API keys, tokens, etc.)

Installation

Virtual Environment (Recommended)

We strongly recommend using a virtual environment to manage dependencies. Virtual environments:

  • Isolate project dependencies from your system Python and other projects
  • Prevent version conflicts between different projects requiring different package versions
  • Make your project reproducible by keeping dependencies self-contained
  • Simplify dependency management without affecting your global Python installation

Create and activate a virtual environment:

# Create virtual environment
python -m venv venv

# Activate on Windows
venv\Scripts\activate

# Activate on macOS/Linux
source venv/bin/activate

Install Dependencies

Once your virtual environment is activated, install the required dependencies:

pip install -r requirements.txt

Usage

Delete Old S3 Objects

Delete objects from an S3 bucket that are older than a specified date:

python aws/s3/delete_old_s3_objects.py --bucket my-bucket --date 2024-01-01

With prefix and dry-run mode:

python aws/s3/delete_old_s3_objects.py --bucket my-bucket --prefix folder/ --date 2024-06-15 --dry-run

Logging Configuration

Use the pre-configured logging setup in your Python projects:

from logging.config import dictConfig
from logging_config import LOGGING

dictConfig(LOGGING)

Code Formatting with Black

This project uses Black for code formatting. Black is an opinionated code formatter that:

  • Enforces consistent code style across the entire project
  • Eliminates debates about formatting preferences in code reviews
  • Saves time by automatically formatting code instead of manual styling
  • Improves readability with a uniform, predictable format
  • Reduces git diffs by maintaining consistent formatting across commits

Format Your Code

Format a single file:

black path/to/file.py

Format the entire project:

black .

Check what would be reformatted without making changes:

black --check .

License

See LICENSE file for details.

About

py-toolbelt is a versatile collection of Python utilities and ready-to-use scripts designed to streamline common development tasks.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages

X Tutup