Skip to main content

Python bindings for the bytehaul Rust download library

Project description

bytehaul

Python bindings for the bytehaul Rust download library.

中文使用文档

Requirements

  • Python 3.9+
  • Rust toolchain (for building from source)
  • uv

Commands below assume you are running them from the repository root.

Installation

From source (development)

uv sync --project bindings/python
cd bindings/python
uv run --project . maturin develop -m Cargo.toml

Build wheel

cd bindings/python
uv run --project . maturin build --release -m Cargo.toml

Usage

Simple download

import bytehaul

bytehaul.download("https://example.com/file.bin", "output.bin")

With options

bytehaul.download(
    "https://example.com/file.bin",
    "output.bin",
    max_connections=8,
    max_download_speed=1_000_000,  # 1 MB/s
    headers={"Authorization": "Bearer token"},
)

Network settings

bytehaul.download(
    "https://example.com/file.bin",
    "output.bin",
    proxy="http://127.0.0.1:7890",
    dns_servers=["1.1.1.1", "8.8.8.8:53"],
    enable_ipv6=False,
)

Logging

# Enable debug logging on the convenience function
bytehaul.download(
    "https://example.com/file.bin",
    "output.bin",
    log_level="debug",
)

# Or on the Downloader object
from bytehaul import Downloader

downloader = Downloader(log_level="info")

Valid levels: "off" (default), "error", "warn", "info", "debug", "trace".

Object API with progress and cancellation

from bytehaul import Downloader

downloader = Downloader(
    connect_timeout=15.0,
    dns_servers=["1.1.1.1"],
    enable_ipv6=False,
)
task = downloader.download("https://example.com/large.bin", "large.bin")

# Poll progress
snap = task.progress()
print(f"State: {snap.state}, Downloaded: {snap.downloaded}, Speed: {snap.speed:.0f} B/s")

# Cancel if needed
# task.cancel()

# Wait for completion
task.wait()

Error handling

from bytehaul import download, DownloadFailedError, CancelledError, ConfigError

try:
    download("https://example.com/file.bin", "output.bin")
except ConfigError as e:
    print(f"Invalid parameter: {e}")
except CancelledError:
    print("Download was cancelled")
except DownloadFailedError as e:
    print(f"Download failed: {e}")

API Reference

download(url, output_path, **options)

Blocking convenience function. Downloads a file and returns when complete.

Downloader(connect_timeout=None, proxy=None, http_proxy=None, https_proxy=None, dns_servers=None, enable_ipv6=None)

Reusable downloader instance.

  • downloader.download(url, output_path, **options) -> DownloadTask

DownloadTask

Handle to a running download.

  • task.progress() -> ProgressSnapshot — current download progress
  • task.cancel() — cancel the download
  • task.wait() — block until download completes (releases GIL)

ProgressSnapshot

Frozen snapshot of download progress.

Attribute Type Description
total_size int | None Total file size (if known)
downloaded int Bytes downloaded so far
state str "pending", "downloading", "completed", "failed", "cancelled", "paused"
speed float Current speed in bytes/second
elapsed_secs float | None Elapsed time in seconds

Download options

Parameter Type Default
headers dict[str, str] {}
max_connections int 4
connect_timeout float (secs) 30.0
read_timeout float (secs) 60.0
memory_budget int 67108864
file_allocation "none" | "prealloc" "prealloc"
resume bool True
piece_size int 1048576
min_split_size int 10485760
max_retries int 5
retry_base_delay float (secs) 1.0
retry_max_delay float (secs) 30.0
max_download_speed int 0 (unlimited)
checksum_sha256 str | None None
log_level str | None None ("off")

Valid log_level values: "off", "error", "warn", "info", "debug", "trace" (case-insensitive).

Network options

Use these on Downloader(...) for the object API, or pass them directly to the blocking download(...) helper.

Parameter Type Default
proxy str | None None
http_proxy str | None None
https_proxy str | None None
dns_servers list[str] | None None
enable_ipv6 bool | None True

Running tests

uv sync --project bindings/python
cd bindings/python
uv run --project . maturin develop -m Cargo.toml
uv run --project . pytest tests/ -v

Building wheels for release

Single platform:

cd bindings/python
uv run --project . maturin build --release -m Cargo.toml

Cross-platform (via CI):

# Linux x86_64 + aarch64, macOS x86_64 + arm64, Windows x86_64
# Use maturin's GitHub Actions: https://github.com/PyO3/maturin-action

The project uses abi3-py39, so a single wheel per platform covers all Python 3.9+ versions.

License

MIT. See the repository LICENSE file.

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

bytehaul-0.1.2.tar.gz (90.5 kB view details)

Uploaded Source

Built Distributions

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

bytehaul-0.1.2-cp39-abi3-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.9+Windows x86-64

bytehaul-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

bytehaul-0.1.2-cp39-abi3-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

bytehaul-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file bytehaul-0.1.2.tar.gz.

File metadata

  • Download URL: bytehaul-0.1.2.tar.gz
  • Upload date:
  • Size: 90.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bytehaul-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f0ac70c58b0e1b44ba0a04c987dab8d23639493e6a383b2a0c6cf031447f8b49
MD5 ff963f0f03c64d4ebdf7121b9b3e247b
BLAKE2b-256 ee645c33871b8b42c3b1a9dc9697c219ec50bafbd45698fe41728c4e99d7c66c

See more details on using hashes here.

Provenance

The following attestation bundles were made for bytehaul-0.1.2.tar.gz:

Publisher: publish-pypi.yml on triwinds/bytehaul

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bytehaul-0.1.2-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: bytehaul-0.1.2-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bytehaul-0.1.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 605e45b9d368cd6fdca4c759b4b40a32fa2198d4f6d1eb2295e91bccde6c5601
MD5 bb66f26bf675ab8971e6ceab67e768cd
BLAKE2b-256 f5ba7b90bc7666bbb69550a1f2691326d433a8dae39b5cba7e84f3618d6796c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for bytehaul-0.1.2-cp39-abi3-win_amd64.whl:

Publisher: publish-pypi.yml on triwinds/bytehaul

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bytehaul-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bytehaul-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 abd456f25a8e1e5e2104afb23816dc2442e27ba8db903f9cdddaa638c14ef478
MD5 6749a24b776d3cc063bbeb2284b46de4
BLAKE2b-256 d2399ceec0860e2d7397af3a05f2d19eb3749f0d0b562b55dfd251d83c14f103

See more details on using hashes here.

Provenance

The following attestation bundles were made for bytehaul-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on triwinds/bytehaul

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bytehaul-0.1.2-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bytehaul-0.1.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aedf8f7e49748f1cb69238a93e637fd3b20ebb2903809c95e246506b5ad07184
MD5 aa82c0e2421cae8f94a3900501058ade
BLAKE2b-256 80fbaa41071628879047aaffed7463ff9cbcfa233275008495f82c68a0926182

See more details on using hashes here.

Provenance

The following attestation bundles were made for bytehaul-0.1.2-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: publish-pypi.yml on triwinds/bytehaul

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bytehaul-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for bytehaul-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5225b7592dcffb2b1f91cf48dea9a77fdd7eca921a4562f463bc5639915971ff
MD5 eb3ac80d7a3245d04a80e2cdfc53281d
BLAKE2b-256 0400516c9aebe827d28a6af1718b31636e8d8687e55dbedbd6660fe3aa8492cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for bytehaul-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: publish-pypi.yml on triwinds/bytehaul

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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