zipline package
zipline.client module
- class zipline.Client(server_url, token)[source]
Bases:
objectA Zipline Client.
- async with x:
Returns the Client itself. Used to gracefully close the client on exit.
async with zipline.Client(server_url, token) as client: ...
- async get_version()[source]
This function is a coroutine.
Gets the Zipline server version information.
- Returns:
The version information for the server.
- Return type:
- async get_user_stats()[source]
This function is a coroutine.
Retrieve stats about the current user.
- Returns:
Stats for the current user.
- Return type:
- async create_user(*, username, password, role=UserRole.user, avatar=None)[source]
This function is a coroutine.
Creates a user.
- Parameters:
username (
str) – The username of the user to create.password (
str) – The password of the user to create.role (
UserRole) – The permissions level of the created User. Only available if used by a Super Admin.avatar (Optional[
zipline.models.Avatar]) –If given, a tuple containing a string denoting the MIME type of the data being uploaded and the data itself as bytes.
Example:
with open('avatar.png', 'rb') as fp: avatar_bytes = fp.read() avatar_mime = 'image/png' avatar = zipline.Avatar(avatar_mime, avatar_bytes) user = await create_user( username='Example', password='s0m3th!ngs3cur3', avatar=avatar, )
- Returns:
The created user.
- Return type:
- Raises:
BadRequest – Something went wrong handling the request.
Forbidden – You are not an administrator and cannot use this method.
- async delete_user(id, /, *, remove_data=True)[source]
This function is a coroutine.
Delete a user with given id.
- Parameters:
- Returns:
The deleted user.
- Return type:
- Raises:
BadRequest – Something went wrong handling the request.
Forbidden – You are not an administrator and cannot use this method.
- async get_all_invites()[source]
This function is a coroutine.
Retrieves all invites.
Warning
This method may retrieve invites for all users, not just the user the token belongs to.
- Returns:
The invites on the server.
- Return type:
List[
Invite]- Raises:
BadRequest – Something went wrong handling this request.
Forbidden – You are not an administrator and do not have permission to access this resource.
- async create_invite(*, max_uses=1, expires_at=None)[source]
This function is a coroutine.
Creates an invite.
Changed in version 0.21.0: Removed the count parameter as it’s no longer supported. Return type is now a complete Invite object as opposed to a partial model.
- Parameters:
max_uses (Optional[
int]) –The number of times the created invite can be used, by default 1. If None is passed the invite will have unlimited uses.
Added in version 0.21.0.
expires_at (Optional[
datetime.datetime]) –When the created invite(s) should expire. Defaults to 24 hours from creation.
Changed in version 0.21.0: Default expiration removed. This parameter will now accept a timedelta. If None is passed, the invite will never expire.
- Returns:
The created invite.
- Return type:
- Raises:
ValueError – An invalid argument was passed.
ZiplineError – The server returned the invites in an unexpected format.
BadRequest – The server could not process the request.
Forbidden – You are not an administrator and cannot use this method.
- async get_all_folders(*, with_files=True)[source]
This function is a coroutine.
Returns all folders.
- async create_folder(name, /, files=None, public=False)[source]
This function is a coroutine.
Creates a folder.
- Parameters:
- Returns:
The created folder.
- Return type:
- Raises:
BadRequest – The server could not process the request.
- async get_all_urls()[source]
This function is a coroutine.
Retrieves all shortened urls for your user.
- Returns:
The requested shortened urls.
- Return type:
List[
URL]
- async shorten_url(original_url, *, vanity=None, max_views=None, password=None, enabled=True)[source]
This function is a coroutine.
Shortens a url.
- Parameters:
original_url (
str) – The url to shorten.vanity (Optional[
str]) – A vanity name to use. None to receive a randomly assigned name.max_views (Optional[
int]) – The number of times the url can be used before being deleted. None for unlimited uses, by default Nonepassword (Optional[
str]) –The password required to use the URL, if given.
Added in version 0.21.0.
enabled (
bool) –Whether the url should be enabled for use, by default True.
Added in version 0.21.0.
zero_width_space (Optional[
bool]) –Whether to incude zero width spaces in the returned url, by default False
Removed in version 0.21.0: This is no longer supported by the API.
- Returns:
The shortened url.
- Return type:
- Raises:
ValueError – Invalid value for max views passed.
BadRequest – The server could not process your request.
- async get_all_tags()[source]
This function is a coroutine.
Get all tags belonging to the current user.
- Returns:
The requested tags.
- Return type:
List[
Tag]
- async get_files(*, page=1, per_page=10, filter=RecentFilesFilter.all, favorite=None, sort_by=FileSearchSort.created_at, order=Order.asc, search_field=FileSearchField.file_name, search_query=None)[source]
This function is a coroutine.
Get files belonging to your user.
- Parameters:
page (
int) – The page of files to get.per_page (
int) – How many files should be returned per page.filter (
RecentFilesFilter) – A filter to apply to the files retrieved.favorite (Optional[
bool]) – Whether to search for only favorited or unfavorited files. None for all files.sort_by (
FileSearchSort) – How the results should be sorted. Defaults to creation datetime.order (
Order) – How the results should be ordered. Defaults to ascending.search_field (
FileSearchField) – What file attribute to search by. Defaults to file name.search_query (Optional[
str]) – The query to use in the search.
- Returns:
The requested search results.
- Return type:
- async get_recent_files(*, amount=10, filter=RecentFilesFilter.all)[source]
This function is a coroutine.
Gets recent files uploaded by you.
- Parameters:
amount (Optional[
int]) – The number of results to return, by default 10.filter (
RecentFilesFilter) –What files to get.
Changed in version 0.21.0: This is now controlled by an enum.
- Returns:
The requested Files.
- Return type:
List[
File]- Raises:
ValueError – An invalid amount was passed.
- async upload_file(payload, *, format=NameFormat.uuid, compression_percent=0, expiry=None, password=None, max_views=None, override_name=None, original_name=None, folder=None, override_extension=None)[source]
This function is a coroutine.
Upload a file to Zipline.
- Parameters:
payload (
FileData) – Data regarding the file to upload.format (Optional[
NameFormat]) – The format of the name to assign to the uploaded file, by defaultuuid.compression_percent (Optional[
int]) – How compressed should the uploaded file be, by default 0.expiry (Optional[
datetime.datetime]) – When the uploaded file should expire, by default None.password (Optional[
str]) – The password required to view the uploaded File, by default None.zero_width_space (Optional[
bool]) –Whether to include zero width spaces in the name of the uploaded File, by default False.
Removed in version 0.21.0: No longer supported by the API.
embed (Optional[
bool]) –Whether to include embed data for the uploaded File, typically used on Discord, by default False.
Removed in version 0.21.0: No longer supported by the API.
max_views (Optional[
int]) – The number of times the uploaded File can be viewed before it is deleted, by default None.text (Optional[
bool]) –Whether the File is a text file, by default False.
Removed in version 0.21.0: No longer supported by the API.
override_name (Optional[
str]) – A name to give the uploaded file. If provided this will override the server generated name, by default None.original_name (Optional[
str]) – The original_name of the file. None to not preserve this data, by default None.folder (Optional[Union[
Folder,str]]) –The Folder (or it’s ID) to place this upload into automatically.
Added in version 0.15.0.
override_extension (Optional[
str]) –The extension to use for this file instead of the original.
Added in version 0.21.0.
- Returns:
Information about the file uploaded.
- Return type:
- Raises:
ValueError – compression_percent was not in 0 <= compression_percent <= 100.
ValueError – max_views passed was less than 0.
ValueError – The type of the object passed to the folder parameter was incorrect.
BadRequest – Server could not process the request.
ServerError – The server responded with a 5xx error code.
zipline.models module
- class zipline.models.File(_http, id, created_at, updated_at, deletes_at, favorite, original_name, name, size, type, views, max_views, password, folder_id, thumbnail, tags, url)[source]
Bases:
objectRepresents a file stored on Zipline.
- created_at
When the file was created.
- Type:
- updated_at
When the file was last updated.
- Type:
- deletes_at
The scheduled deletion time of the file, if applicable.
- Type:
Optional[
datetime.datetime]
- max_views
The maximum number of times the file can be viewed before being removed, if applicable.
- Type:
Optional[
int]
- property thumbnail_url
returns: The full url for the thumbnail image, if available. :rtype: Optional[
str]
- async download_password_protected(password)[source]
This function is a coroutine.
Download this file if password protected.
- async refresh()[source]
This function is a coroutine.
Retrieve an updated instance of this file.
- Returns:
A new instance with the latest information about this file.
- Return type:
- async delete()[source]
This function is a coroutine.
Delete this file.
- Returns:
A new instance with the latest information about this file.
- Return type:
- async edit(*, favorite=None, tags=None, max_views=None, original_name=None, password=None, type=None)[source]
This function is a coroutine.
Update this file.
- Parameters:
favorite (Optional[
bool]) – The new favorite status of the file, if given.tags (Optional[Sequence[
Tag]]) – Tag to apply to this file, if given.max_views (Optional[
int]) – The new maximum views of the file, if given.original_name (Optional[
str]) – The new original name of the file, if given.password (Optional[
str]) – The new password for the file, if given.type (Optional[
str]) –The new MIME type for the file, if given.
Warning
Misuse of this parameter can cause files to display incorrectly or fail outright.
- Returns:
The updated file.
- Return type:
- async add_favorite()[source]
This function is a coroutine.
Favorite this file.
- Returns:
A new instance with the latest information about this file.
- Return type:
- Raises:
ValueError – The file is already favorited.
- async remove_favorite()[source]
This function is a coroutine.
Unfavorite this file.
- Returns:
A new instance with the latest information about this file.
- Return type:
- Raises:
ValueError – The file is already favorited.
- class zipline.models.Folder(_http, id, created_at, updated_at, name, public, files, user, user_id)[source]
Bases:
objectRepresents a Folder on Zipline.
- created_at
When the folder was created.
- Type:
- updated_at
When the folder was last updated.
- Type:
- async refresh()[source]
This function is a coroutine.
Retrieve an updated instance of this object.
- Returns:
A new instance with the latest information about this folder.
- Return type:
- async delete()[source]
This function is a coroutine.
Delete this folder.
- Returns:
A new instance with the latest information about this folder.
- Return type:
- class zipline.models.User(_http, id, username, created_at, updated_at, role, view, sessions, oauth_providers, totp_secret, passkeys, quota, avatar, password, token)[source]
Bases:
objectRepresents a Zipline user.
- created_at
When this user was created or registered.
- Type:
- updated_at
The last time this user was updated.
- Type:
- view
Custom view info for this user.
- Type:
- oauth_providers
OAuth providers registered for this user.
- Type:
List[
OAuthProvider]
- passkeys
Passkeys registered for this user.
- Type:
List[
UserPasskey]
- async refresh()[source]
This function is a coroutine.
Retrieve the latest information about this user.
- Returns:
A new instance with the latest information about this user.
- Return type:
- async edit(*, username=None, password=None, avatar=None, role=None, quota=None)[source]
This function is a coroutine.
Edit this user.
- Parameters:
username (Optional[
str]) – The new username for this user, if given.password (Optional[
str]) – The new password for this user, if given.avatar (Optional[
Avatar]) – The new avatar for this user, if given.role (Optional[
UserRole]) – The new role for this user, if given.quota (Optional[Union[
UserQuota,PartialQuota]]) – The new quota for this user, if given.
- Returns:
The updated user.
- Return type:
- async delete(*, remove_data=True)[source]
This function is a coroutine.
Delete this user.
- Parameters:
remove_data (
bool) – Whether this user’s files and urls should be deleted as well, by default True- Returns:
A new instance with the latest information about this user.
- Return type:
- Raises:
BadRequest – Something went wrong handling the request.
Forbidden – You are not an administrator and cannot use this method.
- async get_files(*, page=1, per_page=10, filter=RecentFilesFilter.all, favorite=None, sort_by=FileSearchSort.created_at, order=Order.asc, search_field=FileSearchField.file_name, search_query=None)[source]
This function is a coroutine.
Get files belonging to your user.
- Parameters:
page (
int) – The page of files to get.per_page (
int) – How many files should be returned per page.filter (
RecentFilesFilter) – A filter to apply to the files retrieved.favorite (Optional[
bool]) – Whether to search for only favorited or unfavorited files. None for all files.sort_by (
FileSearchSort) – How the results should be sorted. Defaults to creation datetime.order (
Order) – How the results should be ordered. Defaults to ascending.search_field (
FileSearchField) – What file attribute to search by. Defaults to file name.search_query (Optional[
str]) – The query to use in the search.
- Returns:
The requested search results.
- Return type:
- class zipline.models.InviteUser(_http, username, id, role)[source]
Bases:
objectUser information provided with an
Invite.
- class zipline.models.Invite(_http, id, created_at, updated_at, expires_at, code, uses, max_uses, inviter, inviter_id)[source]
Bases:
objectRepresents an invite to a Zipline instance.
- created_at
When this invite was created.
- Type:
- updated_at
When this invite was last updated.
- Type:
- expires_at
When this invite expires, if applicable.
- Type:
Optional[
datetime.datetime]
- max_uses
The number of times this invite can be used before it’s no longer valid, if applicable.
- Type:
Optional[
int]
- inviter
The user that is attributed to the creation of this invite.
- Type:
- class zipline.models.Tag(_http, id, created_at, updated_at, name, color, files)[source]
Bases:
objectRepresents a tag on Zipline.
- created_at
When this tag was created.
- Type:
- updated_at
When this tag was last updated.
- Type:
- class zipline.models.URL(_http, id, created_at, updated_at, code, vanity, destination, views, max_views, password, enabled, user, user_id)[source]
Bases:
objectRepresents a shortened url on Zipline.
- created_at
When this url was created.
- Type:
- updated_at
When this url was last updated.
- Type:
- async edit(max_views=None, vanity=None, destination=None, enabled=None, password=None)[source]
This function is a coroutine.
Edit this url.
- Parameters:
max_views (Optional[
int]) – The new maximum views, if given.vanity (Optional[
str]) – The new vanity code this url should have, if given.destination (Optional[
str]) – The new destination, if given.enabled (Optional[
bool]) – Whether this url should be usable, if given.password (Optional[
str]) – The new password required to use this url, if given.
- Returns:
The updated url.
- Return type:
- class zipline.models.UploadFile(_http, id, type, url)[source]
Bases:
objectFile data given by the API when a file is uploaded.
- class zipline.models.UploadResponse(_http, files, deletes_at)[source]
Bases:
objectResponse given by the API when a file or multiple files are uploaded.
- files
A list of information about the files uploaded.
- Type:
List[
UploadFile]
- class zipline.models.FileData(data, filename=None, *, mimetype=None)[source]
Bases:
objectUsed to upload a File to Zipline.
- data
The file or file like object to open.
- Type:
Union[
str,bytes,os.PathLike,io.BufferedIOBase]
- class zipline.models.PartialQuota(type, value=None, max_urls=...)[source]
Bases:
objectA partial quota useful for creating a new quota for a
User.
- class zipline.models.UserQuota(_http, id, created_at, updated_at, files_quota, max_bytes, max_files, max_urls, user, user_id)[source]
Bases:
objectRepresents a quota assigned to a
Userin Zipline.Note
While this class may be used to update a user’s quota this class is not intended to be created manually and should not be used for this purpose.
Usage of
PartialQuotais recommended this purpose instead.- created_at
When this quota was created.
- Type:
- updated_at
When this quota was last updated.
- Type:
- class zipline.models.OAuthProvider(id, created_at, updated_at, user_id, provider, username, access_token, refresh_token, oauth_id)[source]
Bases:
objectRepresents an OAuth provider being used by a
Useron Zipline.- created_at
When this entry was created.
- Type:
- updated_at
When this entry was updated.
- Type:
- provider
The service this entry is for.
- Type:
- class zipline.models.UserViewSettings(enabled, align, show_mimetype, content, embed, embed_title, embed_description, embed_color, embed_site_name)[source]
Bases:
objectRepresents view settings for a Zipline
User.- align
How the content should be aligned on the page.
- Type:
Optional[Literal[‘left’, ‘center’, ‘right’]]
- class zipline.models.ServerVersionInfo(version)[source]
Bases:
objectVersion information for a Zipline instance.
- class zipline.models.UserStats(files_uploaded, favorite_files, views, avg_views, storage_used, avg_storage_used, urls_created, url_views, sort_type_count)[source]
Bases:
objectStats for a Zipline
User.
zipline.enums module
zipline.utils module
- zipline.utils.get(iterable, /, **attrs)[source]
A helper that returns the first element in the iterable that meets all the traits passed in
attrs.When multiple attributes are specified, they are checked using logical AND, not logical OR. Meaning they have to meet every attribute passed in and not one of them.
To have a nested attribute search (i.e. search by
x.y) then pass inx__yas the keyword argument.If nothing is found that matches the attributes passed, then
Noneis returned.- Parameters:
iterable (Union[
collections.abc.Iterable,collections.abc.AsyncIterable]) – The iterable to search through. Using acollections.abc.AsyncIterable, makes this function return a coroutine.**attrs – Keyword arguments that denote attributes to search with.
- zipline.utils.utcnow()[source]
Returns an aware UTC datetime representing the current time.
- Returns:
The current time in UTC as an aware datetime.
- Return type:
- zipline.utils.as_chunks(iterable, n)[source]
Batches an iterable into chunks of up to size n.
- Parameters:
iterable (
collections.abc.Iterable) – The iterable to batchn (
int) – The number of elements per generated tuple.
- Raises:
ValueError – At least one result must be returned per group.
zipline.errors module
- class zipline.errors.UnhandledError[source]
Bases:
ZiplineErrorRaised by the library if the server returns a status code not handled by the lib.
- class zipline.errors.BadRequest[source]
Bases:
ZiplineErrorServer returned a 400 response.
- class zipline.errors.Forbidden[source]
Bases:
ZiplineErrorServer returned a 401 or 403 response.
- class zipline.errors.NotFound[source]
Bases:
ZiplineErrorServer returned a 404 response.
- class zipline.errors.RateLimited[source]
Bases:
ZiplineErrorServer returned a 429 response.
- class zipline.errors.ServerError[source]
Bases:
ZiplineErrorServer returned a 5xx response code.
- class zipline.errors.NotAuthenticated[source]
Bases:
ZiplineErrorRequesting data without an Authorization header