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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_utils-5.tar.gz.
File metadata
- Download URL: simple_utils-5.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5513cd17ee3fbc69107923f3758dd47828836513404c3a096b7a1aaeb9bf1ef6
|
|
| MD5 |
9862aae357341e6dd979affe61aad0be
|
|
| BLAKE2b-256 |
cac0d53f8abcb27c8d0aecde7d121fe1e1ff4ff221c1735fcd739e8f4640d281
|
Provenance
The following attestation bundles were made for simple_utils-5.tar.gz:
Publisher:
publish.yml on i-tems/simple-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simple_utils-5.tar.gz -
Subject digest:
5513cd17ee3fbc69107923f3758dd47828836513404c3a096b7a1aaeb9bf1ef6 - Sigstore transparency entry: 789247884
- Sigstore integration time:
-
Permalink:
i-tems/simple-utils@baca32978e100bcac898ef07811f850fed264289 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/i-tems
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@baca32978e100bcac898ef07811f850fed264289 -
Trigger Event:
push
-
Statement type:
File details
Details for the file simple_utils-5-py3-none-any.whl.
File metadata
- Download URL: simple_utils-5-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2533b4b0a62da0515ffb3dffb4c150b8175706fa5cd6160a931ac63eb5029dd
|
|
| MD5 |
0ac027ea4ff415dfd64366f66212d8a2
|
|
| BLAKE2b-256 |
2fe0f9db399e43efd28ab846e0b7fbb51c84e34013ef60c3abc373a9eac3c594
|
Provenance
The following attestation bundles were made for simple_utils-5-py3-none-any.whl:
Publisher:
publish.yml on i-tems/simple-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simple_utils-5-py3-none-any.whl -
Subject digest:
a2533b4b0a62da0515ffb3dffb4c150b8175706fa5cd6160a931ac63eb5029dd - Sigstore transparency entry: 789247890
- Sigstore integration time:
-
Permalink:
i-tems/simple-utils@baca32978e100bcac898ef07811f850fed264289 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/i-tems
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@baca32978e100bcac898ef07811f850fed264289 -
Trigger Event:
push
-
Statement type: