Skip to content

[Python] Use “bypy” Package To Download Baidu Cloud Files

Last Updated on 2021-09-03 by Clay

Sometimes I am looking for some Chinese data, I found many friends in China who have shared the files and models on Baidu cloud. But if I am using a remote server, I need to download them via terminal.

Today, I have the need to download a pre-trained model on Baidu cloud, so I chose bypy to do it. It seems that as long as it is fixed in version 1.6.10, it is possible to download the file.

The following I will introduce how to use bypy package.


Use “bypy” To Download Files


Step 1. Installation

bypy is suitable for Python 2.7+ and Python 3.3+, you can use the following command to download:

pip3 install bypy==1.6.10

Here is an explanation. If you use the updated version, you will encounter the following error when downloading.

So stay in 1.6.10 version!


Step 2. Verify Account and Authorize

The first time you use it, you need to verify the account. (The sample code is list the folders)

from bypy import ByPy


def main():
    bp = ByPy()
    bp.list()


if __name__ == '__main__':
    main()



Output:


Go to the verification URL, enter the account password of the Baidu accout, and the verification code should be generated.


Paste the verification code back to the terminal and press Enter.

You will see that the authorization is successful.


Step 3. Download Files

Remember the /apps/bypy/ folder we saw just now? It’s in your Baidu cloud, it. should be called “application/bypy“… In short, put the file you want to download in it to download it normally.

For example, I put a folder named GPT-2 under application/bypy/, you can use the following code to view it:

from bypy import ByPy


def main():
    bp = ByPy()
    bp.list()


if __name__ == '__main__':
    main()



Output:

/apps/bypy ($t $f $s $m $d):
D GPT2 0 2020-10-22, 06:53:45


After confirming that there is this folder, you can use the following program to download:

from bypy import ByPy


def main():
    bp = ByPy()
    bp.download('GPT-2')


if __name__ == '__main__':
    main()



References

Leave a ReplyCancel reply

Exit mobile version