Features
- ⚡ Fully asynchronous (
asyncio) - 🌐 HTTP client based on
aiohttp - 🔐 Authentication and session handling
- 📂 File and directory operations
- ⬆️ File uploads and downloads
Installation
pip install aioterabox
Install from source
git clone https://github.com/devbis/aioterabox.git
cd aioterabox
pip install -e .
Usage
import asyncio
import aiohttp
from aioterabox.api import TeraboxClient
from aioterabox.exceptions import TeraboxLoginChallengeRequired
async def main():
async with aiohttp.ClientSession() as session:
tb = TeraboxClient(
session=session,
email='your_email',
password='your_password',
)
try:
await tb.login()
except TeraboxLoginChallengeRequired as exc:
# TeraBox may require a simple-verify continuation step.
await tb.complete_login_challenge(exc.challenge)
# get quota
print('quota = ', await tb.get_storage_quota())
# list files
files = await tb.list_remote_directory('/path/to/directory')
print(files)
# create directory
await tb.create_directory('/remote/directory')
# upload file
await tb.upload_file('/home/user/localfile.zip', f'/remote/directory/remotefile.zip')
# download file
meta = await tb.get_files_meta(['/remote/directory/remotefile.zip'])[0]
async with session.get(meta['dlink']) as resp:
# the link is signed and can be downloaded without authentication
with open('/tmp/downloadedfile.zip', 'wb') as f:
while chunk := await resp.content.read(1024):
f.write(chunk)
# rename file
await tb.rename_file('/remote/directory/remotefile.zip', 'newname.zip')
# delete file
await tb.delete_files(['/remote/directory/newname.zip'])
asyncio.run(main())
The client can now start from only email/password and establish the session cookies on its own.
When TeraBox responds with need verify, the library raises TeraboxLoginChallengeRequired and
stores the in-progress session so the caller can continue the flow with complete_login_challenge().
If you want to persist a working session between restarts, store the cookies returned by login() or
complete_login_challenge(). The useful fields are usually jstoken, csrfToken, browserid,
ndus, TSID, shareUpdateRandom, and lang.
For file operations you should always use absolute paths starting from the root directory /.
Configuration
Manual cookie bootstrap
If you prefer to start from an existing browser session, you can still extract the session JS Token and cookies manually.
Getting the JS Token
To use this tool you need to have a Terabox account and a JS Token key. You can get the session JS Token by logging into your Terabox account and following the sequence of steps below:
- Open your Terabox cloud.
- Open the browser's developer tools (F12).
- Enable the "Device Toolbar" then click the back arrow to get back to Terabox.
- Go to the "Network" tab.
- Select the "XHR" filter.
- Click any directory or file in the cloud.
- Look for any request made to the Terabox cloud URL and click on it.
- Select the "Payload" tab.
- Look for the jsToken parameter in the list and copy its value.
If you can't find the jsToken parameter, try selecting any other directory or file in the cloud and look for the jsToken parameter in the request payload. Make sure that you have the "XHR" filter selected and that you are looking at the "Payload" tab.
Getting the cookies values
Additionally to the JS Token, you will need to capture the cookies values. You can get them by following the sequence of steps below:
- Open your Terabox cloud.
- Open the browser's developer tools (F12).
- Go to the "Application" tab.
- Select the "Cookies" item in the left panel.
- Look for the cookies values and copy them.
You will need to copy the csrfToken, browserid, and ndus values. Once the values are provided the library will refresh the csrfToken and jstoken values on login automatically.
Requirements
- Python 3.10+
- aiofiles >= 25.1.0, < 26.0.0
- aiohttp
- cryptography
Thanks
https://github.com/seiya-npm/terabox-api for reverse engineering the TeraBox API and JavaScript implementation. https://github.com/dnigamer/TeraboxUploaderCLI/ for the instructions on obtaining session cookies.
Disclaimer
This project is not affiliated with or endorsed by TeraBox. The API behavior may change at any time, which can break compatibility.
Use at your own risk.
License
Apache License 2.0
See LICENSE for more information.
Release files for aioterabox 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aioterabox-0.2.4.tar.gz | 21.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aioterabox-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 41.0 kB
Release files / aioterabox-0.2.4.tar.gz
| Download URL | aioterabox-0.2.4.tar.gz |
|---|---|
| Size | 21.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4035dbf378ad9a1fa66ec34d1420bd536d18c5c8384cd6050b849817cf4b8d68
|
|
BLAKE2b-256 checksum How to use checksums |
92a82b2340914e5c322eee69d6fbcb950db4e03c70da1df8f636e492b822608f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Release files / aioterabox-0.2.4-py3-none-any.whl
| Download URL | aioterabox-0.2.4-py3-none-any.whl |
|---|---|
| Size | 20.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ad7470e6173cb8b39928cb029b479eb07698deea84e23d91bce454a9befa2b83
|
|
BLAKE2b-256 checksum How to use checksums |
e5df7da7f5d4ac15ed923c78effa553ab6008d979e723825293d78c1ccd87196
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|