zipline package

zipline.client module

Copyright 2023 fretgfr

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

Bases: object

A Zipline Client.

Supports being created normally as well as used in an async context manager.

async close() None[source]

Gracefully close the client.

async create_folder(name: str, /, *, files: List[File] | None = None) Folder[source]

This function is a coroutine.

Creates a Folder.

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

  • files (Optional[List[File]], optional) – 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 create_invites(*, count: int = 1, expires_at: datetime | None = None) List[PartialInvite][source]

This function is a coroutine.

Creates user invites.

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

  • expires_at (Optional[datetime], optional) – 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 create_user(*, username: str, password: str, administrator: bool = False) User[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 (bool, optional) – 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 delete_all_files() int[source]

This function is a coroutine.

Deletes all of your Files

Returns:

The number of removed Files

Return type:

int

async delete_invite(code: str, /) Invite[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_files() List[File][source]

This function is a coroutine.

Gets all Files belonging to your user.

Returns:

The returned Files

Return type:

List[File]

async get_all_folders(*, with_files: bool = False) List[Folder][source]

This function is a coroutine.

Returns all Folders

Parameters:

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

Returns:

The retrieved Folders

Return type:

List[Folder]

async get_all_invites() List[Invite][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 get_all_shortened_urls() List[ShortenedURL][source]

This function is a coroutine.

Retrieves all shortened urls for your user.

Returns:

The requested shortened urls.

Return type:

List[ShortenedURL]

async get_all_users() List[User][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 get_folder(id: int, /, *, with_files: bool = False) Folder[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 (bool, optional) – 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_password_protected_image(*, id: int, password: str) bytes[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_recent_files(*, amount: int = 4, filter: Literal['all', 'media'] = 'all') List[File][source]

This function is a coroutine.

Gets recent files uploaded by you.

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

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

Returns:

_description_

Return type:

List[File]

Raises:

ValueError – Amount was not within the specified bounds.

async get_user(id: int, /) User[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 shorten_url(original_url: str, *, vanity: str | None = None, max_views: int | None = None, zero_width_space: bool = False) str[source]

This function is a coroutine.

Shortens a url

Parameters:
  • original_url (str) – The url to shorten

  • vanity (Optional[str], optional) – A vanity name to use. None to shorten normally, by default None

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

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

Returns:

The shortened url

Return type:

str

Raises:
  • ValueError – Invalid value for max views passed.

  • BadRequest – The server could not process your request.

  • NotAuthenticated – An incorrect authorization header was passed

async upload_file(payload: FileData, *, format: NameFormat = NameFormat.uuid, compression_percent: int = 0, expiry: datetime | None = None, password: str | None = None, zero_width_space: bool = False, embed: bool = False, max_views: int | None = None, text: bool = False, override_name: str | None = None, original_name: str | None = None) UploadResponse[source]

This function is a coroutine.

Uploads a File to Zipline

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

  • format (NameFormat, optional) – The format of the name to assign to the uploaded File, by default NameFormat.uuid

  • compression_percent (int, optional) – How compressed should the uploaded File be, by default 0

  • expiry (Optional[datetime], optional) – When the uploaded File should expire, by default None

  • password (Optional[str], optional) – The password required to view the uploaded File, by default None

  • zero_width_space (bool, optional) – Whether to include zero width spaces in the name of the uploaded File, by default False

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

  • max_views (Optional[int], optional) – The number of times the uploaded File can be viewed before it is deleted, by default None

  • text (bool, optional) – Whether the File is a text file, by default False

  • override_name (Optional[str], optional) – A name to give the uploaded file. If provided this will override the server generated name, by default None

  • original_name (Optional[str], optional) – The original_name of the file. None to not preserve this data, by default None

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

  • BadRequest – Server could not process the request

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

zipline.enums module

Copyright 2023 fretgfr

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

Copyright 2023 fretgfr

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

exception zipline.errors.BadRequest[source]

Bases: ZiplineError

Server returned a 400 response.

exception zipline.errors.Forbidden[source]

Bases: ZiplineError

Server returned a 401 response.

exception zipline.errors.NotAuthenticated[source]

Bases: ZiplineError

Requesting data without an Authorization header

exception zipline.errors.NotFound[source]

Bases: ZiplineError

Server returned a 404 response.

exception zipline.errors.ServerError[source]

Bases: ZiplineError

Server returned a 5xx response code.

exception zipline.errors.UnhandledError[source]

Bases: ZiplineError

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

exception zipline.errors.ZiplineError[source]

Bases: Exception

Base class for Zipline related errors.

zipline.models module

Copyright 2023 fretgfr

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class zipline.models.File(_session: ClientSession, created_at: datetime, expires_at: datetime | None, name: str, mimetype: str, id: int, favorite: bool, views: int, folder_id: int | None, max_views: int | None, size: int, url: str, original_name: str | None)[source]

Bases: object

Represents a file stored on Zipline.

Fields

created_at: datetime

When the File was created.

expires_at: Optional[datetime]

When the File expires.

name: str

The name of the File.

mimetype: str

The MIME type of the File.

id: int

The id for the File.

favorite: bool

Whether the File is favorited.

views: int

The number of times the File has been viewed.

folder_id: Optional[int]

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

max_views: Optional[int]

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

size: int

The size of the File in bytes.

url: str

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

original_name: Optional[str]

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

async delete() None[source]

This function is a coroutine.

Delete this File.

Returns:

The deleted File

Return type:

File

Raises:

NotFound – The file could not be found.

async edit(*, favorite: bool | None = None) File[source]

This function is a coroutine.

Edit this File.

Parameters:

favorite (Optional[bool], optional) – 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: str

Returns the full URL of this File.

async read() bytes[source]

This function is a coroutine.

Read the File into memory.

Returns:

The data of the File

Return type:

bytes

class zipline.models.FileData(data: str | bytes | PathLike[Any] | BufferedIOBase, filename: str | None = None, *, mimetype: str | None = None)[source]

Bases: object

Used to upload a File to Zipline.

class zipline.models.Folder(_session: ClientSession, id: int, name: str, user_id: int, created_at: datetime, updated_at: datetime, files: List[File] | None)[source]

Bases: object

Represents a Zipline folder.

Fields

id: int

The id of the Folder

name: str

The name of the Folder

user_id: int

The id of the User that owns the Folder.

created_at: datetime

When the Folder was created.

updated_at: datetime

When the folder was last updated.

files: List[File]

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

async add_file(file: File, /) None[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: 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.Invite(_session: ClientSession, code: str, id: int, created_at: datetime, expires_at: datetime | None, used: bool, created_by_id: int)[source]

Bases: object

Represents a Zipline invite.

Fields

code: str

The Invite code.

id: int

The Invite id.

created_at: datetime

When the Invite was created.

expires_at: Optional[datetime]

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

used: bool

Whether the Invite has been used.

created_by_id: int

The id of the User that created this Invite.

async delete() Invite[source]

This function is a coroutine.

Delete this Invite.

Returns:

The deleted Invite.

Return type:

Invite

Raises:

NotFound – The Invite could not be found

property url

The full url of this invite.

class zipline.models.PartialInvite(code: str, created_by_id: int, expires_at: datetime | None)[source]

Bases: NamedTuple

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

Fields

code: str

The invite code generated.

created_by_id: int

The id of the User that created this invite.

expires_at: Optional[datetime]

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

code: str

Alias for field number 0

created_by_id: int

Alias for field number 1

expires_at: datetime | None

Alias for field number 2

class zipline.models.ShortenedURL(_session: ClientSession, created_at: datetime, id: int, destination: str, vanity: str | None, views: int, max_views: int | None, url: str)[source]

Bases: object

Represents a shortened url on Zipline.

Fields

created_at: datetime

When the url was created.

id: int

The id of the url.

destination: str

The destination url.

vanity: Optional[str]

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

views: int

The number of times this invite has been used.

max_views: Optional[int]

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

url: str

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

async delete() None[source]

This function is a coroutine.

Deletes this ShortenedURL

Returns:

The deleted url.

Return type:

ShortenedURL

class zipline.models.UploadResponse(file_urls: List[str], expires_at: datetime | None, removed_gps: bool | None)[source]

Bases: NamedTuple

Represents a response to a File upload.

Fields

file_urls: List[str]

The urls of the Files that were uploaded.

expires_at: Optional[datetime]

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

removed_gps: Optional[bool]

Whether gps data was removed from the uploads.

expires_at: datetime | None

Alias for field number 1

file_urls: List[str]

Alias for field number 0

removed_gps: bool | None

Alias for field number 2

class zipline.models.User(_session: ClientSession, id: int, username: str, avatar: str | None, token: str, administrator: bool, super_admin: bool, system_theme: str, embed: Dict[str, Any], ratelimit: int | None, totp_secret: str | None, domains: List[str])[source]

Bases: object

Represents a Zipline User.

Fields

id: int

The User’s id.

username: str

The User’s username

avatar: Optional[str]

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

token: str

The User’s token

administrator: bool

Whether the User is an administrator

super_admin: bool

Whether the User is a super admin

system_theme: str

The User’s preferred theme

embed: Dict[str, Any]

The User’s embed data, raw.

ratelimit: Optional[int]

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

totp_secret: Optional[str]

Honestly I have no fucking idea what this is for.

domains: List[str]

List of domains the User has configured.