Skip to main content

simple-utils

날짜/시간, 문자열, 파일, 데코레이터 등 다양한 Python 유틸리티 모음입니다.

설치

pip install simple-utils

선택적 의존성

# Iceberg 지원
pip install simple-utils[iceberg]

모듈

  • datetime_utils - 날짜 및 시간 연산
  • string_utils - 문자열 변환 및 조작
  • file_utils - 파일 및 경로 작업
  • decorators - 유용한 함수 데코레이터
  • storage - 객체 저장소 유틸리티
  • platform - 플랫폼 연동 (Iceberg, DuckDB)

사용법

DateTime Utilities

from simple_utils import datetime_utils

# 현재 날짜/시간
now = datetime_utils.now()
today = datetime_utils.today()

# 타임스탬프
ts = datetime_utils.now_timestamp()
ts_ms = datetime_utils.now_timestamp_ms()

# 파싱 및 포맷
date = datetime_utils.parse_date("2024-01-15")
dt = datetime_utils.parse_datetime("2024-01-15 10:30:00")
formatted = datetime_utils.format_date(date, "%Y/%m/%d")

# 날짜 연산
dates = datetime_utils.date_range("2024-01-01", "2024-01-10")
days = datetime_utils.days_between("2024-01-01", "2024-01-10")
new_date = datetime_utils.add_days("2024-01-01", 7)

# 하루의 시작/끝
start = datetime_utils.start_of_day()
end = datetime_utils.end_of_day()

# 주말 확인
is_weekend = datetime_utils.is_weekend("2024-01-13")  # True (토요일)

# 타임스탬프 변환
dt = datetime_utils.timestamp_to_datetime(1705312200)
ts = datetime_utils.datetime_to_timestamp(dt)

String Utilities

from simple_utils import string_utils

# 케이스 변환
string_utils.to_snake_case("HelloWorld")      # "hello_world"
string_utils.to_camel_case("hello_world")     # "helloWorld"
string_utils.to_pascal_case("hello_world")    # "HelloWorld"
string_utils.to_kebab_case("HelloWorld")      # "hello-world"

# 문자열 연산
string_utils.truncate("Hello World", 8)        # "Hello..."
string_utils.slugify("Hello World!")           # "hello-world"
string_utils.reverse("hello")                  # "olleh"

# 랜덤 문자열
string_utils.random_string(16)                 # "aB3xKm9pQr2sT5vW"
string_utils.random_hex(8)                     # "a1b2c3d4"

# 검사
string_utils.is_empty("")                      # True
string_utils.is_not_empty("hello")             # True
string_utils.contains_any("hello", ["he", "x"]) # True
string_utils.contains_all("hello", ["he", "lo"]) # True

# 접두사/접미사 제거
string_utils.remove_prefix("prefix_text", "prefix_")  # "text"
string_utils.remove_suffix("text_suffix", "_suffix")  # "text"

# 마스킹
string_utils.mask("1234567890", 2, 2)          # "12******90"

# 추출
string_utils.extract_numbers("abc123def456")   # ["123", "456"]
string_utils.split_words("helloWorld")         # ["hello", "world"]

File Utilities

from simple_utils import file_utils

# 텍스트 파일
content = file_utils.read_text("file.txt")
file_utils.write_text("file.txt", "content")

lines = file_utils.read_lines("file.txt")
file_utils.write_lines("file.txt", ["line1", "line2"])

# JSON 파일
data = file_utils.read_json("data.json")
file_utils.write_json("data.json", {"key": "value"})

# 바이너리 파일
bytes_data = file_utils.read_bytes("file.bin")
file_utils.write_bytes("file.bin", b"binary data")

# 디렉토리 작업
file_utils.ensure_dir("path/to/dir")
file_utils.ensure_parent_dir("path/to/file.txt")
files = file_utils.list_files("dir", "*.py", recursive=True)

# 파일 정보
file_utils.exists("file.txt")
file_utils.is_file("file.txt")
file_utils.is_dir("directory")
file_utils.get_extension("file.txt")     # ".txt"
file_utils.get_stem("file.txt")          # "file"
file_utils.get_name("path/to/file.txt")  # "file.txt"
file_utils.get_parent("path/to/file.txt") # Path("path/to")
file_utils.get_size("file.txt")          # 바이트 크기
file_utils.get_size_human("file.txt")    # "1.5 MB"

# 파일 작업
file_utils.copy_file("src.txt", "dst.txt")
file_utils.move_file("src.txt", "dst.txt")
file_utils.delete_file("file.txt")
file_utils.delete_dir("directory")

# 경로 유틸리티
path = file_utils.join_path("path", "to", "file.txt")
abs_path = file_utils.resolve_path("./file.txt")

Decorators

from simple_utils import decorators

# 지수 백오프 재시도
@decorators.retry(max_attempts=3, delay=1.0, backoff=2.0)
def unstable_function():
    ...

# 실행 시간 측정
@decorators.timing
def slow_function():
    ...

# 결과 캐싱
@decorators.memoize
def expensive_function(x):
    ...

# 지원 중단 표시
@decorators.deprecated(message="new_func을 사용하세요", version="2.0")
def old_function():
    ...

# 싱글톤 패턴
@decorators.singleton
class Database:
    ...

# 호출 제한
@decorators.throttle(interval=1.0)  # 초당 최대 1회
def rate_limited_function():
    ...

@decorators.debounce(wait=0.5)      # 마지막 호출 후 0.5초 대기
def debounced_function():
    ...

# 로깅
@decorators.log_calls(log_args=True, log_result=True)
def logged_function(x, y):
    ...

# 에러 처리
@decorators.catch_exceptions(default=None, exceptions=(ValueError,))
def safe_function():
    ...

# 1회만 실행
@decorators.run_once
def initialize():
    ...

# 인자 검증
@decorators.validate_args(x=lambda x: x > 0, name=lambda s: len(s) > 0)
def validated_function(x, name):
    ...

Object Storage

from simple_utils.storage import ObjectStorage

# 스토리지 초기화
storage = ObjectStorage("/path/to/storage")

# 데이터 쓰기
storage.write("config.json", {"key": "value"})
storage.write("data.txt", "텍스트 내용")
storage.write("binary.bin", b"바이너리 데이터")

# 데이터 읽기
data = storage.read("config.json")       # JSON 자동 파싱
text = storage.read_text("data.txt")
binary = storage.read_bytes("binary.bin")

# 확인 및 목록
storage.exists("config.json")            # True
storage.list_keys()                       # ["config.json", "data.txt", ...]
storage.list_keys(prefix="config")        # ["config.json"]
storage.list_dirs()                       # 하위 디렉토리 목록

# 삭제
storage.delete("config.json")

Platform 연동

요구사항

  • Python >= 3.8

라이선스

MIT

Metadata

Release files for simple-utils 15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple-utils 15
File Size Uploaded Provenance Actions
simple_utils-15.tar.gz 15.9 kB With provenance Details for simple_utils-15.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for simple-utils 15
File Interpreter ABI Platform Actions
simple_utils-15-py3-none-any.whl Python 3 none any Details for simple_utils-15-py3-none-any.whl

Total release size: 40.1 kB

Release files / simple_utils-15.tar.gz

Download URL simple_utils-15.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d374104b5099b046b22493ac012f82f736de7a54e24be29677d0dc8a46ac0227
BLAKE2b-256 checksum
How to use checksums
eb012afb96dc78c8ce95108647743062b3499ed6be6984776a599cb73f0aba18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 31, 2026.

Transparency log

Release files / simple_utils-15-py3-none-any.whl

Download URL simple_utils-15-py3-none-any.whl
Size 24.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e39fa2a55899fabf5d43a2c0ebd45af3ea053ea38da1a885deb03db08818aa5c
BLAKE2b-256 checksum
How to use checksums
28071669a60a4d60bf162a3c5a28444a9ffdf6c52045cf9fc70552ad0927ed3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 31, 2026.

Transparency log

Security for simple-utils 15

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for simple_utils-15.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 31, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

15 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page