Skip to main content

A Python Asynchronous Downloader - pyaiodl

Project description

Python Asynchronous Downloader - pyaoidl

Don't Use it in Production or Live Projects Currently Its Unstable


Python 3.6 Maintenance PyPI license Open Source Love png3 Hits


Version

Beta badge

PyPI version

installation

pypi Method (Recommended)

pip3 install pyaiodl

Github repo method

pip3 install git+https://github.com/aryanvikash/pyaiodl.git

Available Methods

  • Downloader class Instance Non-blocking , params = [fake_useragent:bool,chunk_size:int ,download_path:str] optinals

      dl = Downloader()
    
  • Download [ download(self,url) ]

    uuid = await dl.download(url)
    
  • Errors [iserror(self, uuid)] : Returns - Error Or None , Even On cancel It returns an error "{uuid} Cancelled"

    await dl.iserror(uuid)
    
  • cancel [ cancel(self, uuid) ]

     await dl.cancel(uuid)
    
  • Get Status [ status(self, uuid) ]

      response = await dl.status(uuid)
      
    
    
      returns a dict
    
      """
      filename:str
      file_type :str
      total_size :int
      total_size_str : str
      downloaded :int
      downloaded_str :str
      progress:int
      download_speed:str
      complete :bool
      download_path:str
    
      """
    
  • is_active returns : bool [ is_active( self,uuid ) ] - on cancel ,error , download complete return False

      result = await dl.is_active(uuid)
    

Usage

Example :


from pyaiodl import Downloader, errors
import asyncio
url = "https://speed.hetzner.de/100MB.bin"


async def main():
    dl = Downloader()
    # you can pass your
    # custom chunk size and Download Path
    # dl = Downloader(download_path="/your_dir/", chunk_size=10000)
    uuid = await dl.download(url)
    try:
        while await dl.is_active(uuid):

            r = await dl.status(uuid)

               #cancel
            if r['progress'] > 0:
                try:
                    await dl.cancel("your_uuid")
                except errors.DownloadNotActive as na:
                    print(na)


            print(f"""
            Filename: {r['filename']}
            Total : {r['total_size_str']}
            Downloaded : {r['downloaded_str']}
            Download Speed : {r['download_speed']}
            progress: {r['progress']}
             """)

            # let him breath  for a second:P
            await asyncio.sleep(1)

    # If You are putting uuid  manually Than its better handle This Exception
    except errors.InvalidId:
        print("not valid uuid")
        return

    # when loop Breaks There are 2 Possibility
    # either Its An error Or Download Complete
    # Cancelled Is also count as error
    if await dl.iserror(uuid):
        print(await dl.iserror(uuid))

    else:
        # Final filename / path
       print("Download completed : ", r['download_path'])


asyncio.get_event_loop().run_until_complete(main())

known Bugs -

  • None Please Report :)

TODO

  • Multipart Download
  • Queue Download / Parallel Downloads Limit
  • Better Error Handling

Thanks ❤️


Powered badge

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

pyaiodl-0.0.5.tar.gz (9.3 kB view details)

Uploaded Source

File details

Details for the file pyaiodl-0.0.5.tar.gz.

File metadata

  • Download URL: pyaiodl-0.0.5.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.2

File hashes

Hashes for pyaiodl-0.0.5.tar.gz
Algorithm Hash digest
SHA256 e4a04f7594e8ec04e0fbfd4d4f6191aebc0911579d23d446b7f09adfdff69069
MD5 04f6116c81a7a0fc73391a7164b3e752
BLAKE2b-256 f0317071312cca17a7e5df77042b21ada53c6ce982242c51cb34e4acf257006c

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