Skip to main content

echoss AI Bigdata Solution - Object Storage like S3 handler

Project description

v2.0.0 BREAKING: build system moved from setup.py to pyproject.toml + pytest.ini,

requires-python raised to >=3.12, dependency floors raised (numpy>=2.0, Pillow>=12.0, opencv-python>=4.10.0,<5.0, boto3>=1.40.0, echoss-fileformat>=1.3.2). Public API unchanged.

v1.2.1 bump package version and update Pillow dependency to >=10.1.0,<11

v1.2.0 update package dependency constraints for boto3, opencv-python, tqdm, and Pillow

v1.1.6 hot fix as_pil_image() and add get_content_type() and is_image()

v1.1.4 remove S3ClientHandler, add S3ResourceFileView class, change internal implementation

  • initial config: str or dict
  • add internal class S3ResouceFileView as return object get_object_file()
  • move read_file() to S3ResouceFileView as_json() or as_text()
  • move read_image() to S3ResouceFileView as_pil_image() or as as_cv2_image()

v1.1.3 change package name from echoss_s3handler to echoss_storage and use echoss-fileformat

install 방법

pip install -U echoss-storage

import 방법

from echoss_storage import S3ResourceHandler

custom yolov7과 image_utils의 함수 사용시 S3에 있는 데이터를 사용하고자 하여 만든 Class

Resource Class

내부 주요 함수

    # s3 config 파일 읽기
    s3_config = "../s3 config file path/ai_solution_dataset_test.yaml"
    # class 할당
    s3_resource = S3ResourceHandler(config, env=None)
    
    s3_resource.get_bucket_list(data_info=False)
     - 현재 config 파일에 해당하는 접속 계정에 있는 bucket들의 정보를 출력해준다.(버킷명, 버킷 생성날짜 등)
     - data_info를 True로 하게 되면 출력이 버킷명이 key값, 마지막 생성일자를 vlaue로 하는 Dict형태로 출력되며,
     false로 하면 버킷의 목록만 list형태로 출력.
    
    s3_resource.get_object_info(bucket, file_path)
     - parameter로 입력된 object의 마지막 수정일시(YYYY-MM-DD HH:MM:SS 꼴)와 s3link를 출력해준다.
  
    s3_resource.get_object_list(bucket, s3_prefix, after_ts=0, pattern=None, tqdm_=True)
     - s3_prefix는 버킷 이후 공통되는 경로 입력
     - after_ts는 입력된 이후 추가/수정된 데이터만 추리기 위함(포맷 : "2023-02-28 00:00:00")
     - patter은 확장자와 같은 부분
     - object들의 path를 list로 반환한다.
    
    s3_resource.download_object(bucket_name, target_file_path, download_file_path)
     - S3에 있는 object를 local에 다운로드하기 위한 함수
     - target_file_path는 다운로드 하고자하는 버킷 내의 object 경로
     - download_file_path는 로컬에 다운받고자 하는 경로 입력(파일의 이름 포함)
    
    s3_resource.upload_object(bucket_name, target_file_path, upload_file_path, ExtraArgs=None)
     - locla에 있는 데이터를 S3에 업로드하기 위한 함수
     - target_file_path는 업로드 하고자하는 로컬의 파일 경로
     - upload_file_path는 s3에 업로드 하고자하는 경로
     - ExtraArgs는 metadata 예를들어 {'ContentType': "video/mp4", 'ACL': "public-read"}위와 같이 입력
    
    s3_resource.put_object(object_body, object_name, trg_bucket)
     - 메모리상으로 저장되어있는 json혹은 txt 데이터를 S3 object로 업로드하는데 사용하는 함수
     - object_body는 메모리 상으로 저장되어 있는 데이터
     - object_name은 업로드 하고자하는 경로및 파일명의 path
     - trg_bucket은 업로드 하고자하는 버킷명
     - 이미지도 업로드할 수 있으나 이때에는 아래와 같이 이미지를 PIL, io라이브러리를 이용하여 가공한 뒤 업로드를 해야합니다.
        img0 = Image.fromarray(im0, mode='RGB')
        out_img = io.BytesIO()
        img0.save(out_img, format='png')
        out_img.seek(0)
    
    s3_resource.s3tos3_put_object(src_file_name, trg_file_name, trg_s3_config, fin_print=True)
     - 서로 다른 S3계정간의 데이터를 local에 따로 다운로드 한 뒤 업로드 하는 것이 아닌 메모리상으로 불러 업로드하는 함수
     - src_file_name은 옮기고자하는 s3 파일의 전체 경로(버킷명은 안적어주어도 무방 -> class를 호출할때의 config파일에서 가지고 옴)
     - trg_file_name은 옮겨가야할 s3에서의 경로 입력(파일명까지)
     - trg_s3_config는 옮겨가야할 s3의 config파일(확장자는 yaml)

    s3_resource.move_object(src_file_name, trg_file_name, bucket)
     - 같은 s3내 같은 버킷에서의 파일 이동
     - src_file_name은 원본 파일
     - trg_file_name은 이동되어야 할 경로
    
    s3_resource.read_file(bucket, file_name)
     - S3에 있는 파일을 메모리로 읽기 위한 함수
    
    s3_resource.read_image(bucket, file_name, library="cv2")
     - S3에 있는 이미지 파일을 메모리로 읽는 함수
     - 이후 사용되는 이미지 형식에 따라 옵션에 "cv2", "PIL"을 선택하여 사용 가능
    

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

echoss_storage-2.0.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

echoss_storage-2.0.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file echoss_storage-2.0.0.tar.gz.

File metadata

  • Download URL: echoss_storage-2.0.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for echoss_storage-2.0.0.tar.gz
Algorithm Hash digest
SHA256 d1619d0e766ecc8f5edf8916af616f5d151d946a29362ca7711ce100575ec650
MD5 00d8d34bd0fcd338f69cb354a909ee5a
BLAKE2b-256 8ef20ac50cafb086a0a1e41a7492bc8cb2852b40531a6d8f1f8d945e28ba154d

See more details on using hashes here.

File details

Details for the file echoss_storage-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: echoss_storage-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for echoss_storage-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da3cc4078588f122cfae6a7109d64837f0a1da635e0a6bb553d094237d351de3
MD5 87e1843a0c1ae018ea2d6399a67a0dc7
BLAKE2b-256 20d4a84cd31b343577fa4508c27281b1e352beb18fa1b0601f60dd8931a0eb65

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