Skip to main content

シンプルなファイルアップロード・ダウンロードライブラリ

Project description

SimpleUD

SimpleUDは、サーバーとの間でファイルをアップロード・ダウンロードするためのシンプルで使いやすいPythonライブラリです。

特徴

  • 同期処理と非同期処理の両方をサポート
  • リトライ機能を内蔵
  • 環境変数からの設定読み込みをサポート
  • シンプルで使いやすいAPI

インストール

pip install simpleud

または、GitHubからソースコードをクローンしてインストールすることもできます:

git clone https://github.com/yourusername/simpleud.git
cd simpleud
pip install -e .

使用方法

基本的な使い方

from simpleud import FileUploaderDownloader

# インスタンスの作成
uploader = FileUploaderDownloader(
    server_address='https://your-server.com',
    upload_path='upload.php',
    download_base_path='uploaded_files'
)

# 同期アップロード
uploader.upload('example.txt')

# 同期ダウンロード
uploader.download('example.txt', save_path='downloaded_example.txt')

非同期処理の使い方

import asyncio
from simpleud import FileUploaderDownloader

async def main():
    # インスタンスの作成
    uploader = FileUploaderDownloader(
        server_address='https://your-server.com',
        upload_path='upload.php',
        download_base_path='uploaded_files'
    )
    
    # 非同期アップロード
    await uploader.async_upload('example.txt')
    
    # 非同期ダウンロード
    await uploader.async_download('example.txt', save_path='downloaded_example.txt')

# 非同期処理の実行
asyncio.run(main())

環境変数を使用する場合

環境変数を設定することで、コード内でサーバー情報を直接指定する必要がなくなります:

# 環境変数の設定
export UPLOAD_DOWNLOAD_SERVER_ADDRESS="https://your-server.com"
export UPLOAD_PATH="upload.php"
export DOWNLOAD_BASE_PATH="uploaded_files"
from simpleud import FileUploaderDownloader

# 環境変数から設定を読み込む
uploader = FileUploaderDownloader()

# アップロード・ダウンロード
uploader.upload('example.txt')
uploader.download('example.txt')

リトライ設定

アップロードとダウンロードのリトライ回数と待機時間を設定できます:

# リトライ回数を5回、待機時間を2秒に設定
uploader.upload('example.txt', retries=5, retry_delay=2.0)
uploader.download('example.txt', retries=5, retry_delay=2.0)

# 非同期処理でも同様に設定可能
await uploader.async_upload('example.txt', retries=5, retry_delay=2.0)
await uploader.async_download('example.txt', retries=5, retry_delay=2.0)

サーバーサイドの設定

SimpleUDを使用するには、ファイルをアップロードするためのサーバーサイドスクリプトが必要です。examples/serverディレクトリにサンプルのPHPスクリプトが用意されています:

examples/server/
├── README.md                                      # サーバーサイドスクリプトの説明
└── uploader_e5796bd71a1642e97258a1835419f431.php # アップロード処理用PHPスクリプト

このPHPスクリプトをWebサーバーにアップロードし、SimpleUDの設定で指定することで、ファイルのアップロード・ダウンロードが可能になります:

from simpleud import FileUploaderDownloader

uploader = FileUploaderDownloader(
    server_address='https://your-server.com',
    upload_path='path/to/uploader_e5796bd71a1642e97258a1835419f431.php',
    download_base_path='uploaded_files_e5796bd71a1642e97258a1835419f431'
)

詳細な設定方法や注意点については、examples/server/README.mdを参照してください。

ライセンス

このプロジェクトは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

simpleud-0.1.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

simpleud-0.1.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file simpleud-0.1.1.tar.gz.

File metadata

  • Download URL: simpleud-0.1.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for simpleud-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6514a3ee49ce2ea7d829026ebf5eb9663f89ee18318fa183bc880b5fc98f4b83
MD5 99b1891b86349ca18dc7c1c5cb47046d
BLAKE2b-256 c5a300e65420c5e240f5a1c473983e0f24a8ecd5894d04e1f45a5da5a5aa5af8

See more details on using hashes here.

File details

Details for the file simpleud-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: simpleud-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for simpleud-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 47ea4a472576b84fcd0ff0771417f6aa564b4939f0cd28a610553b673e490713
MD5 d31f52a47c99ec4319e19c1d1b2330b1
BLAKE2b-256 b66b092c34a137e4b41356a8988491faedd416ab8ae4714b41814e76a2984a37

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