An unofficial Python SDK for SonicBit which uses the internal API to interact with the application.
Project description
SonicBit Python SDK
An unofficial Python SDK for SonicBit which uses the internal API to interact with the application.
[!WARNING]
This SDK is provided as-is and is not officially supported by SonicBit. The author is not responsible for any damages or losses caused by the use of this SDK. Use it at your own risk. Please use it responsibly and with the understanding that it may not be fully functional or reliable. Check SonicBit's terms of service for more information.
Installation
Install the package using pip:
pip install sonicbit
Install bleeding edge version:
pip install git+https://github.com/viperadnan-git/sonicbit-python-sdk.git
Usage
[!IMPORTANT]
This SDK is still in development and may not be fully functional. Please report any issues or bugs you encounter. The below documentation is generated by AI and is subject to change as the SDK evolves.
To use the SDK, you need to create an instance of the SonicBit
class and provide your email and password:
from sonicbit import SonicBit
sb = SonicBit(email='your_email@example.com', password='your_password')
Once you have an instance of SonicBit
, you can use its various methods to interact with the application. For example, to list the files in your storage:
files = sb.list_files()
print(files)
Token Handling
By default, the SDK will store your authentication token in a file named .sonicbit.cache
in the current working directory. If you want to specify a different location for the token file, you can pass a token_handler
argument to the SonicBit
constructor:
sb = SonicBit(email='your_email@example.com', password='your_password', token_handler=MyTokenHandler())
The token_handler
should implement the following methods:
read(email: str) -> str | None
: Reads the token for the given email from the token file.write(email: str, token: str) -> None
: Writes the token for the given email to the token file.
The token_handler
is optional and will default to a TokenFileHandler
if not provided.
[!TIP]
You can use theTokenHandler
class to store and update tokens in a database or other storage mechanism. Simply implement theread
andwrite
methods and pass an instance of your custom class to theSonicBit
constructor. This will allow you to store tokens in a secure location and easily update them as needed.
User Module
The User
module provides methods for interacting with the user's account, such as getting their user details and storage details.
User Details
To get the user's details, you can use the get_user_details
method:
details = sb.get_user_details()
print(details)
This will print a UserDetails
object containing information about the user's account, such as their email, plan name, and more.
Storage Details
To get the storage details, you can use the get_storage_details
method:
details = sb.get_storage_details()
print(details)
This will print a StorageDetails
object containing information about the user's storage, such as their total storage size, free space, and more.
Clear Storage
To clear the user's storage, you can use the clear_storage
method:
success = sb.clear_storage()
print(success)
This will return True
if the storage was successfully cleared, or False
if there was an error.
Torrent Management
The Torrent
module provides methods for interacting with the user's torrents, such as adding, listing, and deleting torrents.
Add Torrent
To add a torrent, you can use the add_torrent
method:
torrents = sb.add_torrent("https://example.com/torrent.torrent")
print(torrents)
This will return a list of torrent hashes that were added.
List Torrents
To list the user's torrents, you can use the list_torrents
method:
torrents = sb.list_torrents()
print(torrents)
This will print a TorrentList
object containing information about each torrent in the user's storage, such as the torrent name, hash, size, progress, and more.
Get Torrent Details
To get the details of a torrent, you can use the get_torrent_details
method:
details = sb.get_torrent_details("hash")
print(details)
This will print a TorrentDetails
object containing information about the torrent, such as the files it contains, the download rate, and more.
Delete Torrent
To delete a torrent, you can use the delete_torrent
method:
success = sb.delete_torrent("hash")
print(success)
This will return True
if the torrent was successfully deleted, or False
if there was an error.
Remote Download Management
The RemoteDownload
module provides methods for interacting with the user's remote downloads, such as adding, listing, and deleting remote downloads.
Add Remote Download
To add a remote download, you can use the add_remote_download
method:
success = sb.add_remote_download("https://example.com/file.torrent", PathInfo.root())
print(success)
This will return True
if the remote download was successfully added, or False
if there was an error.
List Remote Downloads
To list the user's remote downloads, you can use the list_remote_downloads
method:
downloads = sb.list_remote_downloads()
print(downloads)
This will print a RemoteTaskList
object containing information about each remote download in the user's storage, such as the download URL, progress, and more.
Delete Remote Download
To delete a remote download, you can use the delete_remote_download
method:
success = sb.delete_remote_download(id)
print(success)
This will return True
if the remote download was successfully deleted, or False
if there was an error.
File Management
The File
module provides methods for interacting with the user's files, such as listing, deleting, and moving files.
List Files
To list the user's files, you can use the list_files
method:
files = sb.list_files()
print(files)
This will print a FileList
object containing information about each file in the user's storage, such as the file name, size, and more.
Delete File
To delete a file, you can use the delete_file
method:
success = sb.delete_file("path/to/file")
print(success)
This will return True
if the file was successfully deleted, or False
if there was an error.
Sign Up
The Signup
module provides methods for signing up to SonicBit.
Sign Up
To sign up to SonicBit, you can use the signup
method:
def otp_callback(email):
return input(f"Enter OTP for {email}: ")
success = SonicBit.signup("John Doe", "email@example.com", "password", otp_callback)
print(success)
This will return True
if the signup was successful, or False
if there was an error.
[!NOTE]
Ifotp_callback
is provided thesignup
method will automatically complete the signup process by submitting the OTP code and skipping tutorial. Ifotp_callback
is not provided, the user will need to manually complete the signup process by submitting the OTP code and skipping tutorial. Once signup is complete, the user can use thesubmit_otp
method to submit the OTP code.
Submit OTP
To submit the OTP code, you can use the submit_otp
method:
success = SonicBit.submit_otp("123456")
print(success)
This will return True
if the OTP code was successfully submitted, or False
if there was an error.
Complete Signup Tutorial (Optional)
To complete the signup tutorial, you can use the _complete_tutorial
method:
SonicBit._complete_tutorial("token")
This will mark the tutorial as completed and allow the user to access their account.
Contributing
Contributions are welcome! If you find a bug or have a suggestion for a new feature, please open an issue or submit a pull request on the GitHub repository.
License
This project is licensed under the GNU General Public License v3.0. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sonicbit-0.2.1.tar.gz
.
File metadata
- Download URL: sonicbit-0.2.1.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 692881921c6e7695f0ef01deeff1388e591e21774c0e101811740971ae9819f6 |
|
MD5 | 8644b2849ee952ff215d7dcd447ef48b |
|
BLAKE2b-256 | e0b5b7eb949fa950125a681372c4e341122e4fe850c37f458c890360875029af |
File details
Details for the file sonicbit-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: sonicbit-0.2.1-py3-none-any.whl
- Upload date:
- Size: 35.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9ece726fba1d607bc5200e1e9f47036acb105cb5fa588945b1286f10a82fbf7 |
|
MD5 | 79877222cb85e7715e98b64a55802d4e |
|
BLAKE2b-256 | c6744226b147067d1ae37be39dfa2f048580378012ac2bea00694469099065f8 |