Skip to main content

Python download library

Project description

Download Boss

Python CI Build PyPI Downloads

Python download library

1. Installation

pip install download_boss

2. Usage

2.1. HttpClient with Wrappers

import requests
import os
import json

from download_boss.RequestEnvelope import RequestEnvelope
from download_boss.HttpClient import HttpClient
from download_boss.RetryWrapper import RetryWrapper
from download_boss.DelayWrapper import DelayWrapper
from download_boss.FileCacheWrapper import FileCacheWrapper

# Cache responses in folder
cacheFolder = os.path.join( os.path.dirname(__file__), "cache" )

# Create HTTP client with wrappers
client = FileCacheWrapper( DelayWrapper( RetryWrapper( HttpClient(clientRetriableStatusCodeRanges=[range(500,600)]) ), length=0 ), cacheFolderPath=cacheFolder )

# Download two responses
jsonBaseUrl = 'https://httpbin.org/anything/'
jsonIds = ['one', 'two']

for id in jsonIds:
    # Send data with the request, so we can use read it from the response
    request = RequestEnvelope(requests.Request(method='POST', url=jsonBaseUrl + id, json=[{"subId": "111"}, {"subId": "222"}]))
    response = client.download(request)
    
    # Use the response to construct sub-requests
    jsonText = json.loads(response.text)
    for o in jsonText['json']:
        sid = o['subId']

        # Download and cache subrequests
        newUrl = 'https://httpbin.org/anything/' + sid
        request = RequestEnvelope(requests.Request(method='GET', url=newUrl), )
        client.download(request)

# The second time this is run, it will run instantly because FileCacheWrapper's cacheLength is not set (=None) so it caches responses indefinitely

Output from first run

(venv) C:\apps\download_boss>python demo\demo1.py
2024-08-11 13:09:08,284 [ INFO] FileCacheWrapper.py :: _getCache() - Cache miss: POST https://httpbin.org/anything/one
2024-08-11 13:09:08,284 [ INFO] DelayWrapper.py :: download() - Delaying by 0s ... POST https://httpbin.org/anything/one
2024-08-11 13:09:08,284 [ INFO] HttpClient.py :: download() - Requesting: POST https://httpbin.org/anything/one
2024-08-11 13:09:08,688 [ INFO] FileCacheWrapper.py :: _getCache() - Cache miss: GET https://httpbin.org/anything/111
2024-08-11 13:09:08,688 [ INFO] DelayWrapper.py :: download() - Delaying by 0s ... GET https://httpbin.org/anything/111
2024-08-11 13:09:08,690 [ INFO] HttpClient.py :: download() - Requesting: GET https://httpbin.org/anything/111
2024-08-11 13:09:08,794 [ INFO] FileCacheWrapper.py :: _getCache() - Cache miss: GET https://httpbin.org/anything/222
2024-08-11 13:09:08,794 [ INFO] DelayWrapper.py :: download() - Delaying by 0s ... GET https://httpbin.org/anything/222
2024-08-11 13:09:08,794 [ INFO] HttpClient.py :: download() - Requesting: GET https://httpbin.org/anything/222
2024-08-11 13:09:08,894 [ INFO] FileCacheWrapper.py :: _getCache() - Cache miss: POST https://httpbin.org/anything/two
2024-08-11 13:09:08,895 [ INFO] DelayWrapper.py :: download() - Delaying by 0s ... POST https://httpbin.org/anything/two
2024-08-11 13:09:08,895 [ INFO] HttpClient.py :: download() - Requesting: POST https://httpbin.org/anything/two
2024-08-11 13:09:08,996 [ INFO] FileCacheWrapper.py :: _getCache() - Cache found: GET https://httpbin.org/anything/111
2024-08-11 13:09:08,999 [ INFO] FileCacheWrapper.py :: _getCache() - Cache found: GET https://httpbin.org/anything/222

Output from second run

(venv) C:\apps\download_boss>python demo\demo1.py
2024-08-11 13:09:10,905 [ INFO] FileCacheWrapper.py :: _getCache() - Cache found: POST https://httpbin.org/anything/one
2024-08-11 13:09:10,907 [ INFO] FileCacheWrapper.py :: _getCache() - Cache found: GET https://httpbin.org/anything/111
2024-08-11 13:09:10,907 [ INFO] FileCacheWrapper.py :: _getCache() - Cache found: GET https://httpbin.org/anything/222
2024-08-11 13:09:10,907 [ INFO] FileCacheWrapper.py :: _getCache() - Cache found: POST https://httpbin.org/anything/two
2024-08-11 13:09:10,909 [ INFO] FileCacheWrapper.py :: _getCache() - Cache found: GET https://httpbin.org/anything/111
2024-08-11 13:09:10,909 [ INFO] FileCacheWrapper.py :: _getCache() - Cache found: GET https://httpbin.org/anything/222

2.2. HttpClient with Kerberos auth

import requests
import os
from requests_kerberos import HTTPKerberosAuth, OPTIONAL

from download_boss.RequestEnvelope import RequestEnvelope
from download_boss.HttpClient import HttpClient
from download_boss.FileCacheWrapper import FileCacheWrapper

# Cache responses in folder
cacheFolder = os.path.join( os.path.dirname(__file__), "cache" )

# Create HTTP client with wrappers
client = FileCacheWrapper( HttpClient(), cacheFolderPath=cacheFolder )

# Create request with Kerberos auth
newUrl = 'https://httpbin.org/anything/kerb'
request = RequestEnvelope(requests.Request(method='POST', url=newUrl, auth=HTTPKerberosAuth(mutual_authentication=OPTIONAL)))
client.download(request)

3. Maintainer documentation

See: docs/README_MAINTAINER.md

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

download_boss-0.0.3.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

download_boss-0.0.3-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file download_boss-0.0.3.tar.gz.

File metadata

  • Download URL: download_boss-0.0.3.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for download_boss-0.0.3.tar.gz
Algorithm Hash digest
SHA256 624b5e2542457f056d499477da4c258b0c5554fe2dee0d8ba115d845dc0a6225
MD5 9dab8bf10db91b770b9b8cf855492335
BLAKE2b-256 df7c722babbf375d776f3ec12d964307d632592194d83558440f5031b43b16a8

See more details on using hashes here.

File details

Details for the file download_boss-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for download_boss-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e7136b051b10c7a397e351c85f067fef5d74b64ffa17d7937e28eab7d647076f
MD5 b4db2ed61fc4b392bdaaa3e4f7170f8e
BLAKE2b-256 b8cc1baab29f15b8a65c2b118853bfa53a9793a500689e3811c21bcf0d9da71d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page