Skip to main content

A collection of simple Python utilities for datetime, string, file, and decorator operations

Project description

simple-utils

A collection of simple Python utilities for everyday tasks.

Installation

pip install simple-utils

Features

  • DateTime Utils: Date and time manipulation utilities
  • String Utils: String processing utilities
  • File Utils: File and path handling utilities
  • Decorators: Useful decorators like retry, timing, etc.

Usage

DateTime Utils

from simple_utils import datetime_utils

# Get current timestamp
ts = datetime_utils.now_timestamp()

# Parse date string
dt = datetime_utils.parse_date("2024-01-15")

# Format datetime
formatted = datetime_utils.format_datetime(dt, "%Y/%m/%d")

# Get date range
dates = datetime_utils.date_range("2024-01-01", "2024-01-07")

String Utils

from simple_utils import string_utils

# Convert case
snake = string_utils.to_snake_case("HelloWorld")  # "hello_world"
camel = string_utils.to_camel_case("hello_world")  # "helloWorld"
pascal = string_utils.to_pascal_case("hello_world")  # "HelloWorld"

# Truncate string
truncated = string_utils.truncate("Hello World", 8)  # "Hello..."

# Generate random string
random_str = string_utils.random_string(10)

File Utils

from simple_utils import file_utils

# Read/Write JSON
data = file_utils.read_json("config.json")
file_utils.write_json("output.json", data)

# Ensure directory exists
file_utils.ensure_dir("/path/to/directory")

# Get file extension
ext = file_utils.get_extension("document.pdf")  # ".pdf"

Decorators

from simple_utils import decorators

# Retry decorator
@decorators.retry(max_attempts=3, delay=1.0)
def unstable_function():
    # May fail sometimes
    pass

# Timing decorator
@decorators.timing
def slow_function():
    # Takes some time
    pass

# Cache decorator
@decorators.memoize
def expensive_calculation(x):
    return x ** 2

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

simple_utils-6.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.

simple_utils-6-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file simple_utils-6.tar.gz.

File metadata

  • Download URL: simple_utils-6.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for simple_utils-6.tar.gz
Algorithm Hash digest
SHA256 2a88ae58591536bc24917aaeb1a5a07068c1d0d9d4659b234dc9f73b3279aa1f
MD5 ba3981a0c23a297eea3b770c308681a4
BLAKE2b-256 c322b9f787f5b8174b18b302d416cdee730061163e016de323e746140138717e

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_utils-6.tar.gz:

Publisher: publish.yml on i-tems/simple-utils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simple_utils-6-py3-none-any.whl.

File metadata

  • Download URL: simple_utils-6-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for simple_utils-6-py3-none-any.whl
Algorithm Hash digest
SHA256 1a7f53e9beee9465ea9a93a43f57c9bd427e3f8da0728f6a538373ad442f0e98
MD5 f6104732c3f1eb3d767854e75fa73283
BLAKE2b-256 1ea10ca4e9515c38da48f6082d5b542bafdb878b20ef62aac3c71ca7ab6f75b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_utils-6-py3-none-any.whl:

Publisher: publish.yml on i-tems/simple-utils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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