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 get_version()[source]

This function is a coroutine.

Gets the Zipline server version information

Returns:

The version information for the server.

Return type:

ServerVersionInfo

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. Defaults to 24 hours from creation.

    Changed in version 0.17.0: Added default expiration of 24 hours.

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

    Added 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(http, 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(http, 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(http, 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(http, 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.

Added 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(http, 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.

data

The file or file like object to open.

Type:

Union[str, bytes, os.PathLike, io.BufferedIOBase]

filename

The name of the file to be uploaded. Defaults to filename of the given path, if applicable.

Type:

Optional[str]

mimetype

The MIME type of the file, if None the lib will attempt to determine it.

Type:

Optional[str]

class zipline.models.ServerVersionInfo(is_upstream, update_to_type, stable_version, upstream_version, current_version)[source]

Bases: object

Information about the current Zipline version.

is_upstream

Whether the version being run is current.

Type:

bool

update_to_type

The branch being tracked.

Type:

str

stable_version

The current stable version of Zipline.

Type:

str

upstream_version

The current GitHub version of Zipline.

Type:

str

current_version

The version of Zipline installed on this server.

Type:

str

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.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 in x__y as the keyword argument.

If nothing is found that matches the attributes passed, then None is returned.

Parameters:
zipline.utils.utcnow()[source]

Returns an aware UTC datetime representing the current time.

Returns:

The current aware datetime in UTC.

Return type:

datetime.datetime

zipline.utils.as_chunks(iterable, n)[source]

Batches an iterable into chunks of up to size n.

Parameters:
Raises:

ValueError – At least one result must be returned per group.

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