Skip to main content

Python 유틸리티 모음 라이브러리: 로깅, Pandas 확장, 출력, 경로 관리

Project description

helper-dev-utils

PyPI version Python License: MIT

Python 개발 시 자주 사용하는 유틸리티 모음 라이브러리

주요 기능

  • helper_logger: 로깅 유틸리티 (콘솔/파일 핸들러, 환경변수 기반 설정, KST 타임존)
  • helper_pandas: Pandas 확장 기능 (한글 컬럼 설명, 데이터 출력, HTML/콘솔 지원)
  • helper_utils_print: 출력 유틸리티 (디렉토리/JSON/딕셔너리 트리 구조 출력)
  • helper_utils_colab: 경로 관리 유틸리티 (로컬/Colab 환경 경로 자동 탐색)

설치

기본 설치

pip install helper-dev-utils

# 테스트 서버
pip install --index-url https://test.pypi.org/simple/ helper-dev-utils

선택적 의존성 설치

# .env 파일 지원
pip install helper-dev-utils[dotenv]

# Jupyter/Colab 지원
pip install helper-dev-utils[jupyter]

# PyTorch Tensor 지원
pip install helper-dev-utils[torch]

# 모든 선택적 의존성 설치
pip install helper-dev-utils[all]

사용법

1. Logger (helper_logger)

환경변수 또는 코드 기반으로 로깅을 쉽게 설정할 수 있습니다.

from helper_dev_utils import get_auto_logger, sample_logger_env

# .env.example_logger 샘플 파일 생성
sample_logger_env()

# 자동으로 호출자 모듈명을 로거 이름으로 사용
logger = get_auto_logger()
logger.info("Hello World")
logger.debug("디버그 메시지")
logger.warning("경고 메시지")
logger.error("에러 메시지")

환경변수 설정 예시 (.env 파일):

LOG_LEVEL=INFO
LOG_CONSOLE_LEVEL=WARNING
LOG_FILE_LEVEL=DEBUG
LOG_DIR=./logs
LOG_FILE_ENABLED=true

로거 재구성:

# 방법 1: logger.set() 메서드 (권장)
logger = get_auto_logger(console_level=logging.INFO)
logger.info("초기 설정")
logger.set(console_level=logging.DEBUG, file=True)
logger.debug("재구성 후 DEBUG 출력")

# 방법 2: reconfigure_logger() 함수
from helper_dev_utils import reconfigure_logger
logger = reconfigure_logger("app", console_level=logging.WARNING, file=True)

2. Pandas Extension (helper_pandas)

DataFrame과 Series에 한글 컬럼 설명 기능을 추가합니다.

from helper_dev_utils import set_pandas_extension
import pandas as pd

# Pandas 확장 등록
set_pandas_extension()

# DataFrame 생성
df = pd.DataFrame({
    'name': ['Alice', 'Bob', 'Charlie'],
    'age': [25, 30, 35],
    'city': ['Seoul', 'Busan', 'Incheon']
})

# 컬럼 설명 추가 (개별)
df.set_head_att('name', '사용자 이름')
df.set_head_att('age', '나이')
df.set_head_att('city', '거주 도시')

# 컬럼 설명 추가 (딕셔너리)
df.set_head_att({
    'name': '사용자 이름',
    'age': '나이',
    'city': '거주 도시'
})

# 한글 컬럼명과 함께 출력
df.head_att()
# 출력:
# 사용자 이름    나이  거주 도시
# name          age   city
# Alice          25   Seoul
# Bob            30   Busan
# Charlie        35   Incheon

# 또는 head() 메서드 오버라이드 사용 (enable_head_override=True일 때)
df.head()

# 다양한 출력 형식
df.head_att(rows=10)              # 10행 출력
df.head_att(rows='all')           # 전체 출력
df.head_att(out='html')           # HTML 형태로 출력
df.head_att(out='str')            # 문자열로 반환

# 컬럼 설명 조회
print(df.get_head_att('name'))    # 출력: 사용자 이름
print(df.get_head_att())          # 전체 딕셔너리 출력

# 컬럼 설명 삭제
df.remove_head_att('age')         # 단일 삭제
df.remove_head_att(['name', 'city'])  # 여러 개 삭제
df.clear_head_att()               # 전체 초기화

3. Print Utilities (helper_utils_print)

디렉토리, JSON, 딕셔너리를 트리 구조로 출력합니다.

from helper_dev_utils import print_dir_tree, print_json_tree, print_dic_tree

# 디렉토리 트리 출력
print_dir_tree('/path/to/directory', max_depth=3)

# JSON/딕셔너리 트리 출력 (파이프 스타일)
data = {
    'users': [
        {'name': 'Alice', 'age': 25},
        {'name': 'Bob', 'age': 30}
    ],
    'config': {'debug': True}
}
print_json_tree(data, max_depth=5, max_list_items=10)

# 딕셔너리 트리 출력 (박스 드로잉 스타일)
print_dic_tree(data, max_depth=5, show_values=True)

4. Colab/Path Utilities (helper_utils_colab)

로컬 및 Google Colab 환경에서 경로를 자동으로 관리합니다.

from helper_dev_utils import my_driver, my_cache

# Google Drive 경로 가져오기 (Colab에서 자동 마운트)
drive_path = my_driver()
print(drive_path)  # /content/drive/MyDrive (Colab) 또는 로컬 경로

# 캐시 디렉토리 가져오기 (OS별 자동 탐색)
cache_path = my_cache()
print(cache_path)  # ~/.cache (Linux/Mac) 또는 로컬 경로

# 하위 경로 지정
model_cache = my_cache('models/bert')
data_drive = my_driver('datasets/images')

환경변수 우선 지원:

MY_DRIVER_PATH=/custom/drive/path
MY_CACHE_PATH=/custom/cache/path

의존성

필수 의존성

  • matplotlib >= 3.2.0
  • numpy >= 1.16.0
  • pandas >= 1.0.0
  • pytz >= 2021.1

선택적 의존성

  • python-dotenv >= 0.19.0 - .env 파일 지원
  • IPython >= 7.0.0 - Jupyter/Colab 지원
  • torch >= 1.0.0 - PyTorch Tensor 지원

개발 및 테스트

개발 환경 설정

# 저장소 클론
git clone https://github.com/c0z0c-helper/helper_dev_utils.git
cd helper_dev_utils

# 개발 의존성 설치
pip install -r requirements-dev.txt

# 편집 가능 모드로 설치
pip install -e .

테스트 실행

# 전체 테스트 실행
pytest tests -v

# 특정 테스트 파일 실행
pytest tests/test_helper_logger.py -v
pytest tests/test_helper_utils_colab.py -v

# 커버리지 포함 실행
pytest tests --cov=helper_dev_utils --cov-report=html

테스트 환경 설정

테스트에서 helper_utils_colab 함수를 검증하려면 .env.test 파일을 사용합니다:

  1. .env.test 파일을 프로젝트 루트에 생성 (이미 샘플이 제공됨)
  2. 테스트용 캐시 및 드라이버 경로 설정:
# Windows
MY_CACHE_LOCAL=C:/Users/YOUR_USERNAME/AppData/Local/Temp/helper_dev_utils_test_cache
MY_DRIVER_PATH=C:/Users/YOUR_USERNAME/AppData/Local/Temp/helper_dev_utils_test_driver

# Linux/macOS
# MY_CACHE_LOCAL=/tmp/helper_dev_utils_test_cache
# MY_DRIVER_PATH=/tmp/helper_dev_utils_test_driver

conftest.py가 자동으로 .env.test를 로드하여 테스트 실행 전 환경을 설정합니다.

라이선스

MIT License - 자세한 내용은 LICENSE 파일을 참조하세요.

기여

이슈 리포트 및 풀 리퀘스트는 GitHub Repository에서 환영합니다!

작성자

c0z0c - c0z0c.dev@gmail.com

관련 라이브러리

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

helper_dev_utils-0.5.7.tar.gz (43.8 kB view details)

Uploaded Source

Built Distribution

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

helper_dev_utils-0.5.7-py3-none-any.whl (35.5 kB view details)

Uploaded Python 3

File details

Details for the file helper_dev_utils-0.5.7.tar.gz.

File metadata

  • Download URL: helper_dev_utils-0.5.7.tar.gz
  • Upload date:
  • Size: 43.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for helper_dev_utils-0.5.7.tar.gz
Algorithm Hash digest
SHA256 8f3cbe82070a0e4f70471f5d7b0a946239953ae586905105ab214f43ebe2cc96
MD5 f6bc007ee0b94164601ddf5c9f282ca0
BLAKE2b-256 d7f59aca78cf322238f0ccf6dd33570d96f2cba24149c6c563ae1b8d8e7887be

See more details on using hashes here.

File details

Details for the file helper_dev_utils-0.5.7-py3-none-any.whl.

File metadata

File hashes

Hashes for helper_dev_utils-0.5.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2f3f07b7527b4b1065d4eda0736f0ac17dcf3a16042e52df8e1dc9c2351874f8
MD5 aed8975056e85a9ee06563c3c96dc21a
BLAKE2b-256 fa3a77c398e484e56a1f8a9ed53e96e01dc3421636cad06a630c4534a3187bc0

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