Skip to main content

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ファイルを参照してください。

Metadata

Release files for simpleud 0.1.1

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

Source distribution (sdist)

Source distribution for simpleud 0.1.1
File Size Uploaded
simpleud-0.1.1.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simpleud 0.1.1
File Interpreter ABI Platform
simpleud-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.8 kB

Release files / simpleud-0.1.1.tar.gz

Download URL simpleud-0.1.1.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6514a3ee49ce2ea7d829026ebf5eb9663f89ee18318fa183bc880b5fc98f4b83
BLAKE2b-256 checksum
How to use checksums
c5a300e65420c5e240f5a1c473983e0f24a8ecd5894d04e1f45a5da5a5aa5af8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.11

Release files / simpleud-0.1.1-py3-none-any.whl

Download URL simpleud-0.1.1-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47ea4a472576b84fcd0ff0771417f6aa564b4939f0cd28a610553b673e490713
BLAKE2b-256 checksum
How to use checksums
b66b092c34a137e4b41356a8988491faedd416ab8ae4714b41814e76a2984a37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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