zipline package

zipline.client module

class zipline.Client(server_url, token)[source]

Bases: object

A 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 create_user(*, username, password, administrator=False)[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.

  • administrator (Optional[bool]) – Whether this user should be an administrator, by default False

Returns:

The created User.

Return type:

User

Raises:
  • BadRequest – Something went wrong handling the request.

  • Forbidden – You are not an administrator and cannot use this method.

async get_password_protected_image(*, id, password)[source]

This function is a coroutine.

Retrieves the content of a password protected File.

Parameters:
  • id (int) – The id of the File to get.

  • password (str) – The password of the File to get.

Returns:

The File’s content.

Return type:

bytes

Raises:
  • BadRequest – Something went wrong handling the request.

  • NotFound – The File could not be found on the server.

async get_all_invites()[source]

This function is a coroutine.

Retrieves all Invites.

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_invites(*, count=1, expires_at=None)[source]

This function is a coroutine.

Creates user invites.

Parameters:
  • count (int) – The number of invites to create, by default 1

  • expires_at (Optional[datetime.datetime]) – When the created invite(s) should expire, by default None

Returns:

The created invites.

Return type:

List[PartialInvite]

Raises:
  • 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 delete_invite(code, /)[source]

This function is a coroutine.

Deletes an Invite with given code.

Parameters:

code (str) – The code of the Invite to delete.

Returns:

The deleted Invite

Return type:

Invite

Raises:
  • Forbidden – You are not an administrator and cannot use this method.

  • NotFound – No Invite was found with the provided code.

async get_all_folders(*, with_files=False)[source]

This function is a coroutine.

Returns all Folders

Parameters:

with_files (Optional[bool]) – Whether the retrieved Folder should contain File information, by default False

Returns:

The retrieved Folders

Return type:

List[Folder]

async create_folder(name, /, *, files=None)[source]

This function is a coroutine.

Creates a Folder.

Parameters:
  • name (str) – The name of the folder to create.

  • files (Optional[List[File]]) – Files that should be added to the created folder, by default None

Returns:

The created Folder

Return type:

Folder

Raises:

BadRequest – The server could not process the request.

async get_folder(id, /, *, with_files=False)[source]

This function is a coroutine.

Gets a folder with a given id.

Parameters:
  • id (int) – The id of the folder to get.

  • with_files (Optional[bool]) – Whether File information should be retrieved, by default False

Returns:

The requested Folder

Return type:

Folder

Raises:
  • Forbidden – You do not have access to the Folder requested.

  • NotFound – A folder with that id could not be found.

async get_user(id, /)[source]

This function is a coroutine.

Returns a User with the given id.

Parameters:

id (int) – The id of the User to get.

Returns:

The retrieved User

Return type:

User

Raises:
  • Forbidden – You are not an administrator and cannot use this method.

  • NotFound – A user with that id could not be found

async get_all_files()[source]

This function is a coroutine.

Gets all Files belonging to your user.

Returns:

The returned Files

Return type:

List[File]

async delete_all_files()[source]

This function is a coroutine.

Deletes all of your Files

Returns:

The number of removed File’s

Return type:

int

async get_recent_files(*, amount=4, filter='all')[source]

This function is a coroutine.

Gets recent files uploaded by you.

Parameters:
  • amount (Optional[int]) – The number of results to return. Must be in 1 <= amount <= 50, by default 4

  • filter (Optional[Literal["all", "media"]]) – What files to get. “all” to get all Files, “media” to get images/videos/etc., by default “all”

Returns:

The requested Files.

Return type:

List[File]

Raises:

ValueError – Amount was not within the specified bounds.

async get_all_shortened_urls()[source]

This function is a coroutine.

Retrieves all shortened urls for your user.

Returns:

The requested shortened urls.

Return type:

List[ShortenedURL]

async shorten_url(original_url, *, vanity=None, max_views=None, zero_width_space=False)[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 shorten normally, by default None

  • max_views (Optional[int]) – The number of times the url can be used before being deleted. None for unlimited uses, by default None

  • zero_width_space (Optional[bool]) – Whether to incude zero width spaces in the returned url, by default False

Returns:

The shortened url

Return type:

str

Raises:
async get_all_users()[source]

This function is a coroutine.

Gets all users.

Returns:

The retrieved users

Return type:

List[User]

Raises:

Forbidden – You are not an administrator and cannot use this method.

async upload_file(payload, *, format=NameFormat.uuid, compression_percent=0, expiry=None, password=None, zero_width_space=False, embed=False, max_views=None, text=False, override_name=None, original_name=None, folder=None)[source]

This function is a coroutine.

Uploads a File to Zipline

Parameters:
  • payload (FileData) – The file to upload.

  • format (Optional[NameFormat]) – The format of the name to assign to the uploaded File, by default NameFormat’s uuid.

  • 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

  • embed (Optional[bool]) – Whether to include embed data for the uploaded File, typically used on Discord, by default False

  • 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

  • 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, int]]) –

    The Folder (or it’s ID) to place this upload into automatically

    New in version 0.15.0.

Returns:

The uploaded File

Return type:

UploadResponse

Raises:
  • ValueError – compression_percent was not in 0 <= compression_percent <= 100

  • ValueError – max_views passed was less than 0

  • ValueError – type passed for folder was incorrect

  • BadRequest – Server could not process the request

  • ServerError – The server responded with a 5xx error code.

async close()[source]

Gracefully close the client.

zipline.models module

class zipline.models.File(_session, created_at, expires_at, name, mimetype, id, favorite, views, folder_id, max_views, size, url, original_name)[source]

Bases: object

Represents a file stored on Zipline.

created_at

When the File was created.

Type:

datetime.datetime

expires_at

When the File expires.

Type:

Optional[datetime.datetime]

name

The name of the File.

Type:

str

mimetype

The MIME type of the File.

Type:

str

id

The id for the File.

Type:

int

favorite

Whether the File is favorited.

Type:

bool

views

The number of times the File has been viewed.

Type:

int

folder_id

The id of the Folder this File belongs to, None if the File is not in a Folder.

Type:

Optional[int]

max_views

The number of times the File can be viewed before being removed. None if there is no limit.

Type:

Optional[int]

size

The size of the File in bytes.

Type:

int

url

The url if the File. Note this does not contain the base url.

Type:

str

original_name

The original_name of the File. None if this information wasn’t kept on upload.

Type:

Optional[str]

async read()[source]

This function is a coroutine.

Read the File into memory.

Returns:

The data of the File

Return type:

bytes

async delete()[source]

This function is a coroutine.

Delete this File.

Raises:

NotFound – The file could not be found.

async edit(*, favorite=None)[source]

This function is a coroutine.

Edit this File.

Parameters:

favorite (Optional[bool]) – Whether this File is favorited., by default None

Returns:

The edited File.

Return type:

File

Raises:

NotFound – The File could not be found.

property full_url

Returns the full URL of this File.

class zipline.models.User(_session, id, username, avatar, token, administrator, super_admin, system_theme, embed, ratelimit, totp_secret, domains)[source]

Bases: object

Represents a Zipline User.

id

The User’s id.

Type:

int

username

The User’s username

Type:

str

avatar

The User’s avatar, encoded in base64. None if they don’t have one set.

Type:

Optional[str]

token

The User’s token

Type:

str

administrator

Whether the User is an administrator

Type:

bool

super_admin

Whether the User is a super admin

Type:

bool

system_theme

The User’s preferred theme

Type:

str

embed

The User’s embed data, raw.

Type:

Dict[str, Any]

ratelimit

The User’s ratelimit between File uploads, in seconds.

Type:

Optional[int]

totp_secret

The User’s Time-based One-Time Password (TOTP) secret. This secret is used for two-factor authentication (2FA). It is a unique secret key associated with the user’s account. If set, the user can generate time-based one-time passwords using this secret to enhance the security of their account.

Type:

Optional[str]

domains

List of domains the User has configured.

Type:

List[str]

class zipline.models.PartialInvite(code, created_by_id, expires_at)[source]

Bases: object

Represents a partial Zipline invite. This is returned by Client.create_invites.

code

The invite code generated.

Type:

str

created_by_id

The id of the User that created this invite.

Type:

int

expires_at

When this invite expires. None if the invite does not expire.

Type:

Optional[datetime.datetime]

class zipline.models.Invite(_session, code, id, created_at, expires_at, used, created_by_id)[source]

Bases: object

Represents a Zipline invite.

code

The Invite code.

Type:

str

id

The Invite id.

Type:

int

created_at

When the Invite was created.

Type:

datetime.datetime

expires_at

When the Invite expires. None if it does not expire.

Type:

Optional[datetime.datetime]

used

Whether the Invite has been used.

Type:

bool

created_by_id

The id of the User that created this Invite.

Type:

int

property url

The full url of this invite.

async delete()[source]

This function is a coroutine.

Delete this Invite.

Returns:

The deleted Invite.

Return type:

Invite

Raises:

NotFound – The Invite could not be found

class zipline.models.Folder(_session, id, name, user_id, created_at, updated_at, files, public)[source]

Bases: object

Represents a Zipline folder.

id

The id of the Folder

Type:

int

name

The name of the Folder

Type:

str

user_id

The id of the User that owns the Folder.

Type:

int

created_at

When the Folder was created.

Type:

datetime.datetime

updated_at

When the folder was last updated.

Type:

datetime.datetime

files

The Files in this Folder, if any. None if the Folder was fetched without files.

Type:

List[File]

public

Whether this folder is public.

New in version 0.16.0.

Type:

bool

async add_file(file, /)[source]

This function is a coroutine.

Adds a File to this Folder

Parameters:

file (File) – The File to add.

Raises:
  • BadRequest – There was an error adding the file

  • UnhandledError – An unexpected exception occured, please report this to the developer.

async remove_file(file, /)[source]

This function is a coroutine.

Removes a File from this Folder

Parameters:

file (File) – The File to remove.

Raises:
  • BadRequest – There was an error removing the file

  • UnhandledError – An unexpected exception occured, please report this to the developer.

class zipline.models.ShortenedURL(_session, created_at, id, destination, vanity, views, max_views, url)[source]

Bases: object

Represents a shortened url on Zipline.

created_at

When the url was created.

Type:

datetime.datetime

id

The id of the url.

Type:

int

destination

The destination url.

Type:

str

vanity

The vanity url of this invite. None if this isn’t a vanity url.

Type:

Optional[str]

views

The number of times this invite has been used.

Type:

int

max_views

The number of times this url can be viewed before deletion. None if there is no limit.

Type:

Optional[int]

url

The url path to use this. Note this does not include the base url.

Type:

str

async delete()[source]

This function is a coroutine.

Deletes this ShortenedURL.

class zipline.models.UploadResponse(file_urls, expires_at, removed_gps)[source]

Bases: object

Represents a response to a File upload.

file_urls

The urls of the Files that were uploaded.

Type:

List[str]

expires_at

When the uploads expire. None if they do not expire.

Type:

Optional[datetime.datetime]

removed_gps

Whether gps data was removed from the uploads.

Type:

Optional[bool]

class zipline.models.FileData(data, filename=None, *, mimetype=None)[source]

Bases: object

Used to upload a File to Zipline.

zipline.enums module

class zipline.enums.NameFormat(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Format for the name of uploaded Files

zipline.errors module

class zipline.errors.ZiplineError[source]

Bases: Exception

Base class for Zipline related errors.

class zipline.errors.UnhandledError[source]

Bases: ZiplineError

Raised by the library if the server returns a status code not handled by the lib.

class zipline.errors.BadRequest[source]

Bases: ZiplineError

Server returned a 400 response.

class zipline.errors.Forbidden[source]

Bases: ZiplineError

Server returned a 401 or 403 response.

class zipline.errors.NotFound[source]

Bases: ZiplineError

Server returned a 404 response.

class zipline.errors.ServerError[source]

Bases: ZiplineError

Server returned a 5xx response code.

class zipline.errors.NotAuthenticated[source]

Bases: ZiplineError

Requesting data without an Authorization header