Reference
Client
Create client
- async aioqbt.client.create_client(url: str, username: str | None = None, password: str | None = None, *, logout_when_close: bool | None = None, http: ClientSession | None = None, ssl: SSLContext | None = None) APIClient [source]
Create
APIClient
.When both
username
andpassword
are given, the returned client will have been successfully authenticated and automatically configured. Otherwise,LoginError
is raised.If they are omitted,
client.auth.login()
need to be called manually.- Parameters:
url (str) – URL to WebUI API, for example,
https://localhost:8080/api/v2/
username (str) – login name
password (str) – login password
logout_when_close – whether logout during
close()
.http –
aiohttp.ClientSession
objectssl –
ssl.SSLContext
for custom TLS connections
- Raises:
LoginError – if authentication is failed.
Client
- class aioqbt.client.APIClient[source]
Represent a remote qBittorrent client.
- property torrents: TorrentsAPI
Torrents API methods.
- property transfer: TransferAPI
Transfer API methods.
- property client_version: ClientVersion | None
qBittorrent client version
- property api_version: APIVersion | None
qBittorrent API version
- async request(method: str, endpoint: str, *, params: Any = None, data: Any = None, max_attempts: int = 3, retry_delay: float = 5, ssl: SSLContext | None = None, **kwargs: object) ClientResponse [source]
Send an HTTP request and return a response object.
Argument
method
specifies the HTTP method (e.g.GET
) whileendpoint
the API endpoint (e.g.torrents/info
).params
forms the query string of the request URL.data
is the payload in the request body. See the underlyingClientSession.request
for their allowed values.max_attempts
is the maximum number of attempts. Retry is performed if two additional conditions are satisfied:GET
orHEAD
requetsRemote disconnection, or repsonse status 429 (Too many requests), 503 (Service unavailable), or 502 (Bad gateway).
The result is
aiohttp.ClientResponse
, and should be used inasync with
.- Parameters:
method (str) – HTTP method.
endpoint (str) – API endpoint.
params – parameters in query string
data – data in request body
max_attempts (int) – maximum number of attempts
retry_delay (float) – maximum delay between attempts
ssl –
SSLContext
, optional
- Raises:
APIError – API errors (non-
200
status).aiohttp.ClientError – connection errors
- Returns:
APIs
API methods by group.
See also the WebUI API reference on qBittorrent wiki.
Torrents
- class aioqbt.api.TorrentsAPI[source]
API methods under
torrents
.- async info(filter: str | None = None, category: str | None = None, sort: str | None = None, reverse: bool | None = None, limit: int | None = None, offset: int | None = None, hashes: Iterable[InfoHash] | Literal['all'] | None = None, tag: str | None = None) List[TorrentInfo] [source]
Get a list of
TorrentInfo
.To obtain a list of completed torrents sorted by name:
torrents = await client.torrents.info( filter=InfoFilter.COMPLETED, sort="name", )
See also torrents/info for filter and result meanings.
- Parameters:
filter – State filter:
InfoFilter
orstr
.category – category filter.
sort – Sort results by an attribute/field.
reverse – Reverse the results.
limit – Maximum number of returned results.
offset – Results starting from the
offset
-th torrents.hashes – A list of info hashes, or a str
all
.tag – Tag filter.
- async properties(hash: InfoHash) TorrentProperties [source]
Get properties of a torrent.
- async files(hash: InfoHash, indexes: Iterable[int] | None = None) List[FileEntry] [source]
Files in a torrent.
- async piece_states(hash: InfoHash) List[int] [source]
A list of piece states in a torrent.
To compare results, use following constants from
PieceState
enum:
- async pause(hashes: Iterable[InfoHash] | Literal['all']) None [source]
Pause torrents.
Torrents can be specified by their info hashes. Passing
all
pauses all torrents.
- async resume(hashes: Iterable[InfoHash] | Literal['all']) None [source]
Resume torrents.
Torrents can be specified by their info hashes. Passing
all
resumes all torrents.
- async delete(hashes: Iterable[InfoHash] | Literal['all'], delete_files: bool) None [source]
Delete torrents.
Torrents can be specified by their info hashes. Passing
all
deletes all torrents.Pass
True
todelete_files
to remove downloaded content.
- async add(form: FormData) None [source]
Add torrents by URLs, info hashes, and/or file blobs.
See
AddFormBuilder
on how to configure and buildFormData
to submit.Note
AddTorrentError
may raise if no new torrents are added.- Parameters:
form – form data to submit.
- async file_prio(hash: InfoHash, id: Iterable[int], priority: int) None [source]
Prioritize files in a torrent.
- Parameters:
hash – Info hash
id – A list of file indices to prioritize.
priority – Priority,
FilePriority
.
- async download_limit(hashes: Iterable[InfoHash] | Literal['all']) Dict[str, int] [source]
Get torrent download limits.
The result is a dict mapping info hash to download speed limit in bytes/second.
- Parameters:
hashes – A list of info hashes or
all
for all torrents.
- async set_download_limit(hashes: Iterable[InfoHash] | Literal['all'], limit: int) None [source]
Update torrent download limits.
- Parameters:
hashes – A list of info hashes or
all
for all torrents.limit – Download limit in bytes/second.
Set share limits for torrents.
- Parameters:
hashes – A list of info hashes or
all
for all torrents.ratio_limit – A number or
RatioLimits.UNSET
.seeding_time_limit –
timedelta
, orSeedingTimeLimits
constants.inactive_seeding_time_limit –
timedelta
, orInactiveSeedingTimeLimits
constants. Required since qBittorrent v4.6.0 (API 2.9.2).
- async upload_limit(hashes: Iterable[InfoHash] | Literal['all']) Dict[str, int] [source]
Get torrent upload limits.
The result is a dict mapping info hash to upload speed limit in bytes/second.
- Parameters:
hashes – A list of info hashes or
all
for all torrents.
- async set_upload_limit(hashes: Iterable[InfoHash] | Literal['all'], limit: int) None [source]
Update torrent upload limits.
- Parameters:
hashes – A list of info hashes or
all
for all torrents.limit – Upload limit in bytes/second.
- async set_location(hashes: Iterable[InfoHash] | Literal['all'], location: str | PathLike[str]) None [source]
Change location (save path) for torrents.
This method also turns off auto torrent management (AutoTMM) for torrents.
See also
set_save_path()
.- Parameters:
hashes – A list of info hashes or
all
for all torrents.location – Location.
- async set_save_path(id: Iterable[InfoHash] | Literal['all'], path: str | PathLike[str]) None [source]
Change save path (location) for torrents.
This method causes no effect to torrents with auto torrent management (AutoTMM) enabled.
Available since qBittorrent v4.4.0.
See also
set_location()
.- Parameters:
id – A list of info hashes or
all
for all torrents.path – Save path.
- async set_download_path(id: Iterable[InfoHash] | Literal['all'], path: str | PathLike[str]) None [source]
Change download path for torrents.
Available since qBittorrent v4.4.0.
- Parameters:
id – A list of info hashes or
all
for all torrents.path – Download path.
- async set_category(hashes: Iterable[InfoHash] | Literal['all'], category: str) None [source]
Change torrents’ category.
- Parameters:
hashes – A list of info hashes or
all
for all torrents.category – Category name. An empty string indicates no category.
- async categories() Dict[str, Category] [source]
Get categories.
A dict mapping category name to
Category
is returned.
- async create_category(category: str, save_path: str | PathLike[str]) None [source]
Create category.
- async toggle_sequential_download(hashes: Iterable[InfoHash] | Literal['all']) None [source]
Flip
seq_dl
values for torrents.
- async set_sequential_download(hashes: Iterable[InfoHash] | Literal['all'], value: bool) None [source]
Change
seq_dl
for torrents.Note
This method is implemented by querying torrent
seq_dl
values, andtoggling
them if needed.
- async toggle_first_last_piece_prio(hashes: Iterable[InfoHash] | Literal['all']) None [source]
Flip
f_l_piece_prio
values for torrents.
- async set_first_last_piece_prio(hashes: Iterable[InfoHash] | Literal['all'], value: bool) None [source]
Change
f_l_piece_prio
for torrents.Note
This method is implemented by querying torrent
f_l_piece_prio
values, andtoggling
them if needed.
- async set_force_start(hashes: Iterable[InfoHash] | Literal['all'], force: bool) None [source]
Set
force_start
flags for torrents.
- async set_super_seeding(hashes: Iterable[InfoHash] | Literal['all'], value: bool) None [source]
Set
super_seeding
flags for torrents.
- async rename_file(hash: str | bytes, id: int, name: str) None [source]
- async rename_file(hash: str | bytes, old_path: str, new_path: str) None
Rename a file in torrent.
On qBittorrent v4.3.3 or later, the signature is
rename_file(hash, old_path, new_path)
.Below qBittorrent v4.3.3, use
rename_file(hash, id, name)
, whereid
is the file index fromfiles()
.Available since qBittorrent v4.2.1 (API 2.4.0).
Signature changed in v4.3.3 (API 2.7.0).
See also: https://github.com/qbittorrent/qBittorrent/pull/13995
AddFormBuilder
- class aioqbt.api.AddFormBuilder[source]
Build
aiohttp.FormData
used inTorrentsAPI.add()
.AddFormBuilder is designed in fluent interface. Most of its methods return a modified copy of the builder.
Here is an example to illustrate:
await client.torrent.add( # Create a builder with a particular client AddFormBuilder.with_client(client) # Set torrent category to "linux" .category("linux") # Set ratio limit to 10 .ratio_limit(10) # Add a torrent by its info hash (debian-11.7.0-amd64-netinst.iso) .include_url("6f84758b0ddd8dc05840bf932a77935d8b5b8b93") # Add a torrent by URL/magnet link (debian-11.6.0-amd64-netinst.iso) .include_url("magnet:?xt=urn:btih:6d4795dee70aeb88e03e5336ca7c9fcf0a1e206d") # Upload a torrent with its bytes data and name .include_url(file_bytes, "debian-12.0.0-amd64-netinst.iso") # Generate FormData object .build() )
See also torrents/add.
- download_path(download_path: str | PathLike[str] | None) Self [source]
Set
downloadPath
value.Also use
use_download_path(True)
to enable download path.
- tags(tags: Iterable[str] | None) Self [source]
Associate torrents being added with tags.
Available since API v2.6.2.
- Parameters:
tags – list of tags.
- root_folder(root_folder: bool | None) Self [source]
Set
root_folder
value.Removed on qBittorrent v4.3.2 and later. Use
content_layout()
instead.
- seeding_time_limit(seeding_time_limit: timedelta | Minutes | SeedingTimeLimits | None) Self [source]
Set
seedingTimeLimit
value.
- inactive_seeding_time_limit(inactive_seeding_time_limit: timedelta | Minutes | SeedingTimeLimits | None) Self [source]
Set
inactiveSeedingTimeLimit
value.
- first_last_piece_prio(first_last_piece_prio: bool | None) Self [source]
Set
firstLastPiecePrio
value.
- stop_condition(stop_condition: StopCondition | None) Self [source]
Set
stopCondition
value.
- content_layout(content_layout: ContentLayout | None) Self [source]
Set
contentLayout
value.
- classmethod with_client(client: APIClient) Self [source]
Return
AddFormBuilder
to buildFormData
used inTorrentsAPI.add()
.- Parameters:
client –
APIClient
.- Returns:
App
- class aioqbt.api.AppAPI[source]
API methods under
app
.- async preferences() Preferences [source]
Get application preferences.
- async set_preferences(prefs: Mapping[str, object]) None [source]
Set application preferences.
- Parameters:
prefs – a mapping of preferences to update.
- async network_interface_list() List[NetworkInterface] [source]
Network interfaces.
Auth
Log
Sync
- class aioqbt.api.SyncAPI[source]
Sync APIs.
In Sync APIs, changes between requests are returned in dict-like objects. Keys may be omitted if their values are unchanged.
- async maindata(rid: int | None = None) SyncMainData [source]
Obtain sync data.
rid
in the previous sync data may be passed to therid
argument to obtain a difference update.If
full_update=True
in the resultant object, the data is a full update. Otherwise, the data only contains changes since the last sync request.
- async torrent_peers(hash: InfoHash, rid: int | None = None) SyncTorrentPeers [source]
Obtain peers for a torrent.
rid
andfull_update
share similar meanings inmaindata()
.
Transfer
RSS
- class aioqbt.api.RSSAPI[source]
RSS APIs
Note
RSS API is experimental. Methods and results may change without notice.
- async add_folder(path: str) None [source]
Add a new folder.
Raise
ConflictError
if error.
- async remove_item(path: str) None [source]
Add a feed/folder.
Raise
ConflictError
if error.
- async move_item(item_path: str, dest_path: str) None [source]
Move a feed/folder.
Raise
ConflictError
if error.
- async items(with_data: bool | None = None) RSSFolder [source]
Get the root folder, which consists of all feeds and sub-folders.
If
with_data=True
, feed title and a list of articles will also be available. SeeRSSFeed
.
- async mark_as_read(item_path: str, article_id: str | None = None) None [source]
Mark an article as read.
- async set_rule(rule_name: str, rule_def: str | RSSRule | Mapping[str, object]) None [source]
Add/update a rule.
Search
- class aioqbt.api.SearchAPI[source]
Search APIs.
Note
Search API is experimental. Methods and results may change without notice.
- async start(pattern: str, plugins: List[str] | Literal['all'] | Literal['enabled'], category: str | Literal['all']) SearchJobStart [source]
Start a search job.
The result consists of only the search job
id
.- Parameters:
pattern – Search pattern.
plugins – Plugins used in search. Special values:
all
uses all plugins whileenabled
uses enabled plugins only.category – Search specific category or
all
.
- Raises:
ConflictError – if error.
- async stop(id: int) None [source]
Stop a search job.
- Raises:
NotFoundError – if the search job is not found.
- async status(id: int | None = None) List[SearchJobStatus] [source]
Query search job statuses.
- Raises:
NotFoundError – if the search job is specified but not found.
- async results(id: int, limit: int | None = None, offset: int | None = None) SearchJobResults [source]
Get search job results.
- Raises:
NotFoundError – if the search job is not found.
ConflictError – if
offset
is out of range.
- async delete(id: int) None [source]
Delete a search job.
- Raises:
NotFoundError – if the search job is not found.
- async plugins() List[SearchPlugin] [source]
Get all plugins.
Constants
- class aioqbt.api.TorrentState[source]
Possible torrent states in
TorrentInfo.state
.- ERROR = 'error'
- MISSING_FILES = 'missingFiles'
- UPLOADING = 'uploading'
- PAUSED_UP = 'pausedUP'
- QUEUED_UP = 'queuedUP'
- STALLED_UP = 'stalledUP'
- CHECKING_UP = 'checkingUP'
- FORCED_UP = 'forcedUP'
- ALLOCATING = 'allocating'
- DOWNLOADING = 'downloading'
- META_DL = 'metaDL'
- PAUSED_DL = 'pausedDL'
- QUEUED_DL = 'queuedDL'
- STALLED_DL = 'stalledDL'
- CHECKING_DL = 'checkingDL'
- FORCED_DL = 'forcedDL'
- CHECKING_RESUME_DATA = 'checkingResumeData'
- MOVING = 'moving'
- UNKNOWN = 'unknown'
- class aioqbt.api.InfoFilter[source]
Torrent state filter in
TorrentsAPI.info()
.- ALL = 'all'
- DOWNLOADING = 'downloading'
- SEEDING = 'seeding'
- COMPLETED = 'completed'
- RESUMED = 'resumed'
- PAUSED = 'paused'
- ACTIVE = 'active'
- INACTIVE = 'inactive'
- STALLED = 'stalled'
- STALLED_UPLOADING = 'stalled_uploading'
- STALLED_DOWNLOADING = 'stalled_downloading'
- ERRORED = 'errored'
- class aioqbt.api.PieceState[source]
Piece state in
TorrentsAPI.piece_states()
results.- UNAVAILABLE = 0
- DOWNLOADING = 1
- DOWNLOADED = 2
- class aioqbt.api.TrackerStatus[source]
Tracker status in
Tracker.status
.- DISABLED = 0
- NOT_CONTACTED = 1
- WORKING = 2
- UPDATING = 3
- NOT_WORKING = 4
- class aioqbt.api.SeedingTimeLimits[source]
Special values of seeding time limit.
- GLOBAL = -2
- UNLIMITED = -1
- class aioqbt.api.StopCondition[source]
Stopping condition to pause torrents.
- NONE = 'None'
- METADATA_RECEIVED = 'MetadataReceived'
- FILES_CHECKED = 'FilesChecked'
- class aioqbt.api.ContentLayout[source]
Content layout that downloaded files are organized.
- ORIGINAL = 'Original'
- SUBFOLDER = 'Subfolder'
- NO_SUBFOLDER = 'NoSubfolder'
- class aioqbt.api.FilePriority[source]
File priority in
TorrentsAPI.file_prio()
andFileEntry.priority
.- NO_DOWNLOAD = 0
- NORMAL = 1
- HIGH = 6
- MAXIMAL = 7
Data structures
- class aioqbt.api.BuildInfo[source]
See
AppAPI.build_info()
.
- class aioqbt.api.Preferences[source]
Bases:
TypedDict
Dict of preferences.
Note
Preference keys may be added/changed/removed across versions. Please refer to the documentation.
- class aioqbt.api.TorrentInfo[source]
Obtained from
TorrentsAPI.info()
.Also see qBittorrent Wiki for attribute meanings.
Note
Some attributes may not be available from older qBittorrent version.
AttributeError
may raise when accessing these attributes.Use try-except block or
getattr()
to handle these cases.- state: str | TorrentState
- ratio_limit: float | RatioLimits
- seeding_time_limit: timedelta | int | SeedingTimeLimits
- class aioqbt.api.TorrentProperties[source]
Obtained from
TorrentsAPI.properties()
.Note
Some attributes may not be available from older qBittorrent version.
AttributeError
may raise when accessing these attributes.Use try-except block or
getattr()
to handle these cases.
- class aioqbt.api.Tracker[source]
-
- status: int | TrackerStatus
- class aioqbt.api.FileEntry[source]
See
TorrentsAPI.files()
.- priority: int | FilePriority
- class aioqbt.api.LogMessage[source]
See
LogAPI.main()
.
- class aioqbt.api.LogPeer[source]
See
LogAPI.peers()
.
- class aioqbt.api.TransferInfo[source]
See
TransferAPI.info()
.- connection_status: str | ConnectionStatus
- class aioqbt.api.SyncMainData[source]
Sync results obtained from
SyncAPI.maindata()
.- torrents: Dict[str, SyncTorrentInfo]
- categories: Dict[str, SyncCategory]
- server_state: SyncServerState
- class aioqbt.api.SyncTorrentInfo[source]
Bases:
TypedDict
Dict of torrent info in
SyncMainData.torrents
.
- class aioqbt.api.SyncCategory[source]
Bases:
TypedDict
Dict of category properties in
SyncMainData.categories
.
- class aioqbt.api.SyncServerState[source]
Bases:
TypedDict
Dict of qBittorrent status and statistics in
SyncMainData.server_state
.- connection_status: str | ConnectionStatus
- class aioqbt.api.SyncPeer[source]
Bases:
TypedDict
Dict of peer info in
SyncTorrentPeers.peers
.
- class aioqbt.api.RSSFeed[source]
RSS feed returned from
RSSAPI.items()
.Attributes
url
anduid
are always available.The other attributes are available if
with_data=True
is passed toRSSAPI.items()
. Otherwise,AttributeError
raises when accessed.Use
hasattr()
to check if doubted.- articles: List[RSSArticle]
- class aioqbt.api.RSSFolder[source]
RSSFolder is a container in hierarchical tree.
folder |-- linux |-- news | |-- local | |-- world
RSSFolder is a dict-like object that children
RSSFeed
andRSSFolder
are accessed by their names:folder["linux"]
. The number of direct children is returned bylen(folder)
while the names of them byfolder.keys()
.Further children can be accessed by joining names with backslashes. The following lines are equivalent:
folder["news"]["local"] folder[r"news\local"]
- class aioqbt.api.RSSRule[source]
Bases:
TypedDict
RSS rule configuration dict.
Rule dict is returned from
RSSAPI.rules()
. It can be passed as argument toRSSAPI.set_rule()
.
- class aioqbt.api.SearchJobResults[source]
Search job results.
- results: List[SearchResultEntry]
- class aioqbt.api.SearchJobStart[source]
Result of
SearchAPI.start()
.
- class aioqbt.api.SearchPlugin[source]
Search plugin information.
- supportedCategories: List[SearchPluginCategory] | List[str]
A list of supported categories.
In qBittorrent 4.3.x and later, this attribute is a list of
SearchPluginCategory
; in earlier versions, a list of localized strings.
Utilities
bittorrent
- aioqbt.bittorrent.InfoHash
- aioqbt.bittorrent.InfoHashes
- aioqbt.bittorrent.InfoHashesOrAll
Type hints related to info hash.
InfoHash
represents an info hash (str
orbytes
).InfoHashes
is an iterable ofInfoHash
.InfoHashOrAll
is an extension toInfoHashes
. It allow the string literalall
, which specifies all torrents in some API methods.
chrono
- aioqbt.chrono.Seconds
- aioqbt.chrono.Minutes
Type hints (similar to
int
) for time durations in specific units.
- class aioqbt.chrono.TimeUnit(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
TimeUnit enum.
Conversion helper between time units
- from_duration(d: float, unit: TimeUnit) float [source]
Convert value from the given unit to the self unit (float)
version
- class aioqbt.version.ClientVersion(major: int, minor: int, patch: int, build: int = 0, status: str = '')[source]
Represent client version.
- classmethod parse(version: str) ClientVersion [source]
Parse client version.
Format:
major.minor.patch[.build][status]
Examples:
4.2.5 4.4.0beta2 4.4.3.1
- class aioqbt.version.APIVersion(major: int, minor: int, release: int = 0)[source]
Represent API version.
Instances can also be compared with 3-tuple of
int
.- classmethod parse(version: str) APIVersion [source]
Parse API version.
Format:
major.minor[.release]
where
major
,minor
andrelease
are all digits.
- classmethod compare(a: Self | Tuple[int, int, int] | None, b: Self | Tuple[int, int, int] | None) int [source]
Compare two API versions.
Return zero if
a == b
; a negative value ifa < b
; or a positive value ifa > b
.None
is a special value treated as the latest version.- Returns:
integer value indicating version relationship.
Exceptions
aioqbt.exc
Exceptions raised in aioqbt
.
- exception aioqbt.exc.LoginError[source]
Bases:
APIError
Login has failed.
This is raised by
AuthAPI.login()
and HTTP status is 200.
- exception aioqbt.exc.AddTorrentError[source]
Bases:
APIError
No new torrents were added.
This is raised by
TorrentsAPI.add()
and HTTP status is 200.
- exception aioqbt.exc.BadRequestError[source]
Bases:
APIError
Bad request.
The error is usually raised because of missing or invalid parameters. This may be caused by empty value sometimes.
HTTP status is usually 400.
- exception aioqbt.exc.ForbiddenError[source]
Bases:
APIError
Forbidden.
The request to resources is explicitly denied due to permission.
HTTP status is usually 403.