API Reference

Client

class tixte.Client(master_key, domain, /, *, session=None, fetch_client_user_on_start=False)

The base Client for the wrapper. Every method on the Client class is used to get other objects from the API. The client should be used as a context manager to ensure the cleanup of the aiohttp session, but it doesn’t have to be.

async with x

Enters the client as a context manager. This will automatically cleanup the aiohttp.ClientSession when the context is exited. Optionally, you can manage the aiohttp.ClientSession yourself and pass it to the client. Regardless of which you do, the client will always close the session when the context is exited.

async with tixte.Client('master_key', 'domain') as client:
    user = await client.fetch_user(user_id)
    print(user)
Parameters
  • master_key (str) – Your Tixte master key. Notes on how this can be obtained can be found on the github readme.

  • domain (str) – The domain you want to upload to. If you haven’t already, you need to create a domain at the tixte domain dashboard. Note you should not include https:// in your domain, just the domain itself. An example of this would be test.tixte.co.

  • session (Optional[aiohttp.ClientSession]) – An optional session to pass for HTTP requests. If not provided, a new session will be created for you.

  • fetch_client_user_on_start (Optional[bool]) – Whether to fetch the client’s user on startup. This means the user method will be ClientUser 100% of the time. Defaults to False. Please note this is only valid if you are using the client within a context manager setting. Otherwise, no user will be fetched.

fetch_client_user_on_start

Whether to fetch the client’s user on startup. This means the fetch_client_user() method will be called upon entering the client as a context manager. Defaults to False.

Type

bool

@listen

A decorator that registers an event to listen for. This is used to register an event to listen for. The name of the coroutine will be used as the event name unless otherwise specified.

@client.event('on_request')
async def on_request(response: aiohttp.ClientRequest):
    print('We requested something!', response.status)
Parameters

event (Optional[str]) – The event to listen for. If not provided, the name of the function will be used.

Raises
  • TypeError – The function passed is not a coroutine.

  • ValueError – The event name does not start with on_.

property user

The client’s user, if in the internal cache.

Type

Optional[ClientUser]

property users

A list of all users within the internal cache.

Type

List[User]

property domains

A list of all domains within the internal cache.

Type

List[Domain]

get_listeners(event)

Retrieve all listeners that fall under the given event name.

Parameters

event (str) – The event to retrieve listeners for.

Returns

A list of all listeners for the event. If the listener is of type asyncio.Future, it was spawned from wait_for().

Return type

List[Union[Callable, asyncio.Future]]

remove_listener(event, *, callback=None)

Removes a listener from the client via the event name and callback.

Parameters
  • event (str) – The event to remove the listener from.

  • callback (Optional[Callable]) – The callback to remove. If not provided, all listeners for the event will be removed.

await wait_for(event, check=None, timeout=None)

This function is a coroutine.

Wait for a specific event to be dispatched, optionally checking for a condition to be met.

This method returns a asyncio.Future that you can await on. Note that if the event dispatched has kwargs, they will be passed to the check but not to the asyncio.Future result.

def check(response: aiohttp.ClientResponse) -> bool:
    return response.status == 200

response = await client.wait_for('request', check=check)
Parameters
  • event (str) – The event to wait for. Note the event passed here should not be prefixed with on_, just the name of the event itself.

  • check (Optional[Callable[..., Optional[bool]]]) – A predicate to check what to wait for. The arguments must match the parameters passed to the event being waited for.

  • timeout (Optional[float]) – The number of seconds to wait before timing out and raising asyncio.TimeoutError.

Raises
  • asyncio.TimeoutError – The event was not dispatched in time and timeout was provided.

  • RuntimeError – This method was called from an OS thread that has no running event loop.

await cleanup()

This function is a coroutine.

A helper cleanup the client’s HTTP session. Internally, this is used in the context manager to cleanup the session, but can be used to manually cleanup the session if needed.

get_user(id, /)

Get a user from the internal cache of users.

Parameters

id (str) – The ID of the user to get.

Returns

The user with the given ID, if it exists within the internal cache.

Return type

Optional[User]

get_domain(url, /)

Gets a domain from the internal cache of domains.

Parameters

url (str) – The url of the domain to get.

Returns

The domain with the given url, if it exists within the internal cache.

Return type

Optional[Domain]

get_partial_upload(id, /)

A method used to get a partial upload from its ID. This will create a partial upload object that can be used to delete the upload without having to fetch it.

Parameters

id (str) – The ID of the partial upload to get.

Returns

The partial upload with the given ID.

Return type

PartialUpload

await fetch_user(id, /)

This function is a coroutine.

Fetches a user from the given ID.

Parameters

id (str) – The ID of the user to fetch.

Returns

The fetched user.

Return type

User

Raises
  • Forbidden – You do not have permission to fetch the user.

  • NotFound – The user with the given ID does not exist.

  • HTTPException – An HTTP error occurred.

await upload(file, /, *, domain=None, upload_type=UploadType.public)

This function is a coroutine.

Upload a file to Tixte.

Parameters
  • file (File) – The file to upload. Please note discord.File objects work as well.

  • domain (Optional[Union[Domain, str]]) – Optionally, upload to a different domain than the client’s default.

  • upload_type (UploadType) – Which type of upload to use. This can be either public or private.

Returns

The response from the upload.

Return type

Upload

Raises
  • Forbidden – You do not have permission to upload this file.

  • HTTPException – An HTTP exception has occurred.

await url_to_file(url, /, *, filename=None)

This function is a coroutine.

Converts the given URL to a File object. This will fetch the contents of the image URL, and then create a File object with the contents.

Parameters
  • url (str) – The URL to convert.

  • filename (Optional[str]) – The filename to use for the file. Note that this must include the extension, such as some_file.png. If this is None, tixte will assume this to be a bin file.

Returns

The file with the given URL.

Return type

File

await fetch_client_user()

This function is a coroutine.

Fetch the client’s user. Once fetched for the first time, this can be accessed via the user attribute. Note that the client does not fetch this on login unless specifically requested via the fetch_client_user_on_start attribute is True and the client is run in a context manager setting.

Returns

The client’s user.

Return type

ClientUser

await fetch_domains()

This function is a coroutine.

A coroutine to fetch all domains registered with Tixte. Once fetched once, you can get all of the domains via domains.

Returns

A list of all domains registered with Tixte.

Return type

List[Domain]

await fetch_config()

This function is a coroutine.

Fetch the configuration settings you have within Tixte. Those settings can be found on the Tixte website on the Embed Editor page, and the Page Design page within your Tixte dashboard.

Returns

The configuration settings.

Return type

Config

await fetch_upload(upload_id, /)

This function is a coroutine.

Fetch an upload from its ID. Please note this is a wrapper around search_upload() as the API doesn’t have a direct endpoint for fetching an upload.

Parameters

upload_id (str) – The ID of the upload to fetch.

Returns

The upload that was requested.

Return type

Upload

Raises
  • Forbidden – You do not have permission to fetch this upload.

  • HTTPException – An HTTP exception has occurred.

await fetch_uploads()

This function is a coroutine.

Fetches all of the existing uploads from Tixte.

Returns

A list of all uploads that you have uploaded to Tixte.

Return type

List[Upload]

await search_upload(query, /, *, domains=[], limit=48, min_size=None, max_size=None, sort_by='relevant')

This function is a coroutine.

Search for an upload by its name.

Parameters
  • query (str) – The query to search for.

  • domains (List[Domain]) – Limit your query to a specific domain(s).

  • limit (int) – The maximum number of results to return. This defaults to 48 as that’s what Tixte defaults to.

  • min_size (Optional[int]) – The minimum size of the upload. Defaults to None.

  • max_size (Optional[int]) – The maximum size of the upload. Defaults to None.

  • sort_by (str) – The sort order of the results. This defaults to relevant. Other sort_by options are currently unknown.

Returns

A list of all uploads that match the query.

Return type

List[Upload]

await create_domain(domain, /, *, is_custom=False)

This function is a coroutine.

Creates a domain on Tixte.

Parameters
  • domain (str) – The url of the domain to create.

  • is_custom (Optional[bool]) – Denotes if the domain is a custom domain that you personally own, instead of a subdomain that tixte creates for you. If False, than the domain must end in tixte.co, likes.cash, discowd.com, has.rocks, is-from.space, bot.style, needs.rest, or wants.solutions.

Returns

The domain that was created.

Return type

Domain

await fetch_upload_key()

This function is a coroutine.

Fetches your Tixte upload key. This upload key can be used on Tixte Snap, ShareX, or MagicCap. You can learn more on your Tixte Dashboard under the “Integrations” section.

Returns

Your upload key.

Return type

str

ABC

Object

class tixte.abc.Object

The base object for all objects within the Tixte system. Every class inherits from this.

IDable

class tixte.abc.IDable

Represents a Tixte Object with an ID. This implements common comparison and hashing methods.

This inherits Object.

x == y

Deteremines if two objects are equal.

x != y

Deteremines if two objects are not equal.

hash(x)

Returns the hash of the object.

Objects

Config

class tixte.Config(*, state, data)

The base Config class you gget when using get_config.

repr(x)

Returns a string representation of the config object.

x == y

Returns True if the config objects are equal. Please note this comparison is evaluated by comparing the custom_css, hide_branding, and base_redirect attributes.

x != y

Returns True if the config objects are not equal. Please note this comparison is evaluated by comparing the custom_css, hide_branding, and base_redirect attributes.

hash(x)

Returns the hash of the config object.

custom_css

The custom CSS of your config

Type

str

hide_branding

Whether or not you hide branding.

Type

bool

base_redirect

Whether or not you base redirect

Type

bool

to_dict()

Dict[str, Any]: Returns a formatted dictionary representing your embed from the embed editor.

to_embed(embed_cls)

Returns an instance of your embed class from the embed editor.

Parameters

embed_cls (Type[Any]) – The embed class you want to use. Must implement a from_dict classmethod. Something you could pass here would be a discord.Embed class.

Returns

An instance of your embed class.

Return type

Any

Domain

Attributes
Methods
class tixte.Domain(*, state, data)

The class that represents a domain.

repr(x)

Returns a string representation of the domain object.

x == y

Deteremines if two domains are equal. This will compare using the url, upload count, and owner ID. If you are comparing two equal domains with different uploads, they will show as not equal.

x != y

Deteremines if two domains are not equal. This will compare using the url, upload count, and owner ID. If you are comparing two equal domains with different uploads, they will show as not equal.

hash(x)

Returns the hash of the domain.

str(x)

Returns the url of the domain.

url

The url of the domain.

Type

str

uploads

The total amount of uploads on the domain.

Type

int

owner_id

The id of the owner of the domain.

Type

str

property owner

The owner of the domain, None if not cached.

Type

Optional[User]

await fetch_owner()

This function is a coroutine.

A coroutine used to fetch the owner of the domain.

Returns

The owner of the domain.

Return type

User

Raises
  • Forbidden – You do not have permission to fetch the user.

  • NotFound – The user with the given ID does not exist.

  • HTTPException – An HTTP error occurred.

await delete()

This function is a coroutine.

Deletes the domain.

Returns

The response from the delete request. DeleteResponse.extra will contain a domain key.

Return type

DeleteResponse

File

Attributes
Methods
class tixte.File(fp, filename=None)

An object used to represent a file that can be used to upload an image.

Parameters
  • fp (Union[os.PathLike, io.BufferedIOBase]) – A file-like object, or file path, or file-like buffer.

  • filename (Optional[str]) – The filename of the file. If not provided, the filename will be the resolved value of fp if it’s a file-like object. Note if the filename can not be found then ValueError is raised. This is due to the fact that the filename is needed to upload.

fp

A file-like object opened in binary mode and read mode or a filename representing a file in the hard drive to open. Please note, if the file-like object passed is opened via open then the modes ‘rb’ should be used. To pass binary data, consider usage of io.BytesIO.

Type

Union[os.PathLike, io.BufferedIOBase]

filename

The filename to display when uploading to Discord. If this is not given then it defaults to fp.name or if fp is a string then the filename will default to the string given.

Type

Optional[str]

close()

Closes the file.

PartialUpload

Attributes
Methods
class tixte.PartialUpload(*, state, id)

Represents a Partial Uploaded File. This can be used to delete an upload with only it’s ID.

This object can get obtained by calling Client.get_partial_upload().

repr(x)

Returns a string representation of the partial upload.

x == y

Deteremines if two partial uploads are equal.

x != y

Deteremines if two partial uploads are not equal.

hash(x)

Returns the hash of the partial upload.

id

The ID of the partial upload.

Type

str

await delete()

This function is a coroutine.

Delete the file from Tixte.

Returns

The response from Tixte with the status of the deletion.

Return type

DeleteResponse

Upload

class tixte.Upload(*, state, data)

The class that represents the response from Tixte when uploading a file.

repr(x)

Returns a string representation of the upload.

x == y

Deteremines if two uploads are equal.

x != y

Deteremines if two uploads are not equal.

hash(x)

Returns the hash of the upload.

id

The ID of the file.

Type

str

name

The name of the file.

Type

str

filename

The filename of the file. This is the combined name and extension of the file. Can be None if the file was uploaded via the search uploads endpoint.

Type

Optiona;[str]

extension

The file extension. For example .png or .jpg.

Type

str

url

The URL for the newly uploaded image.

Type

str

direct_url

The Direct URL for the newly uploaded image.

Type

str

permissions

A mapping of users to their permission levels.

Type

Dict[User, UploadPermissionLevel]

type

The type of upload.

Type

UploadType

property domain

The domain that the upload is located in.

Type

Optional[Domain]

await to_file()

This function is a coroutine.

A coroutine to turn this Upload to a File object.

Returns

The file object created from downloading this upload’s image.

Return type

File

await fetch_domain()

This function is a coroutine.

A method used to fetch the domain this upload is registered under. Consider using domain first before calling this.

Returns

The domain that this upload is registered under.

Return type

Domain

Raises
  • Forbidden – You do not have permission to fetch this domain.

  • HTTPException – An HTTP exception has occurred.

DeleteResponse

Attributes
class tixte.DeleteResponse(*, state, data)

Represents the response from Tixte when deleting a file.

message

The message from Tixte with the status of the deletion.

Type

str

extra

Any extra metadata that Tixte passed along with the deletion.

Type

Dict[str, str]

Permissions

Attributes
Methods
class tixte.Permissions(*, state, upload, permission_mapping=None)

Represents the Permissions of a PartialUpload or Upload.

Please note that if this stems from a PartialUpload, then the get() method will be None 100% of the time unless you call fetch().

upload

The upload that these permissions are for.

Type

Union[PartialUpload, Upload]

get()

Get the permissions of the upload.

Please note this can be incomplete if you haven’t called fetch().

Returns

A mapping of users to their permissions. If this is None, you can fetch the permissions by calling fetch().

Return type

Optional[Mapping[User, UploadPermissionLevel]]

await fetch()

This function is a coroutine.

Fetch the permissions for the upload. This is a helpful method if get() returns None as it will fill the attribute.

Returns

A mapping of users to their permissions.

Return type

Mapping[User, UploadPermissionLevel]

await add(user, /, *, level, message=None)

This function is a coroutine.

Add a user to this upload’s permissions. For example, if this is a private upload you can grant this user access to view the upload.

Parameters
  • user (User) – The user to add to the permissions.

  • level (UploadPermissionLevel) – The permission level to grant the user. Note that granting the user UploadPermissionLevel.owner will transfer ownership to the user and you will no longer be able to edit the upload as you won’t own it.

  • message (Optional[str]) – An optional message to pass along to the user.

Returns

The user that was added to the permissions.

Return type

User

Raises

HTTPException – This user is already in the permissions.

await remove(user, /)

This function is a coroutine.

Remove the current permissions of a user. For example, if this is a private upload you can revoke the user’s access to view the upload.

Parameters

user (User) – The user to remove from the permissions.

Raises

NotFound – This user is not in the permissions so you can not remove them.

await edit(user, /, *, level)

This function is a coroutine.

Edit the permissions of a user. For example, if this is a private upload you can edit the user’s access to view the upload.

Note

Granting the user UploadPermissionLevel.owner will transfer ownership to the user and you will no longer be able to manage this upload.

Parameters
  • user (User) – The user to edit the permissions of.

  • level (UploadPermissionLevel) – The permission level to grant the user.

Returns

The user that was edited.

Return type

User

Users

User

Attributes
Methods
class tixte.User(*, state, data)

This class holds all attributes and methods that are unique to users.

repr(x)

Returns a string representation of the User.

str(x)

Returns the username of the user.

x == y

Deteremines if two Users are equal.

x != y

Deteremines if two Users are not equal.

hash(x)

Returns the hash of the User.

id

The ID of the user.

Type

str

username

The username of the user.

Type

str

avatar

The user’s avatar, if any.

Type

Optional[str]

await save_avatar(*, filename)

This function is a coroutine.

Save the user’s avatar to a File obj. Could return None if the user has not set an avatar.

Returns

The file object, or None if the User has not set an avatar.

Return type

Optional[File]

ClientUser

class tixte.ClientUser(*, state, data)

The Clent’s User profile. This contains metadata specific to the user, such as their email address and phone number.

This inherits from User.

repr(x)

Returns a string representation of the ClientUser.

str(x)

Returns the username of the ClientUser.

x == y

Deteremines if two ClientUsers are equal.

x != y

Deteremines if two ClientUsers are not equal.

hash(x)

Returns the hash of the ClientUser.

mfa_enabled

Whether or not the user has MFA enabled.

Type

bool

email

The email registered to the user.

Type

str

email_verified

If the email has been verified.

Type

bool

phone

The phone, if any, linked to the user account.

Type

Optional[Any]

upload_region

The user’s upload region.

Type

str

premium

Your current premium status.

Type

Premium

property last_login

The last time the user logged in.

Type

datetime.datetime

await save_avatar(*, filename)

This function is a coroutine.

Save the user’s avatar to a File obj. Could return None if the user has not set an avatar.

Returns

The file object, or None if the User has not set an avatar.

Return type

Optional[File]

Enums

Region

class tixte.Region

Represents an upload region.

us_east_one

Represents the US East region.

Premium

class tixte.Premium

Represents the premium tiers of Tixte.

free

The free tier. All default members have this tier.

turbo

Turbo tier. All members with this tier have an increased upload limit.

turbo_charged

Turbo charged tier. This is the highest tier. All members with this tier have an increased upload limit.

UploadPermissionLevel

class tixte.UploadPermissionLevel

Represents an upload permission level. This level determines which members can view an upload.

viewer

A viewer of this upload.

manager

A manager of this upload. Can manage viewers.

owner

The owner of this upload. Can manage everything.

UploadType

class tixte.UploadType

Represents the type of file being uploaded.

public

A public file. Anyone can view this file.

private

A private file. Only the owner can view this file.

Utility Functions

tixte.utils.parse_time(time_strp)

Parses the given tixte time string into a datetime object.

Parameters

time_strp (str) – The time string to parse.

Returns

The parsed datetime object.

Return type

datetime.datetime

Event Reference

Events

tixte.on_request(response)

A listener that gets dispatched everytime a request is made from the library.

Parameters

response (aiohttp.ClientResponse) – The response from the server when making a HTTP request.

Exceptions

Exceptions

exception tixte.TixteException

The base Tixte Exception. All Tixte Exceptions inherit from this.

exception tixte.HTTPException(response=None, data=None, *args, **kwargs)

An exception raised when an HTTP Exception occurs from the API.

response

The response from the API.

Type

aiohttp.ClientResponse

data

The data returned from the API.

Type

Any

exception tixte.NotFound(response=None, data=None, *args, **kwargs)

An exception raised when an object is not Found.

This inherits from HTTPException.

exception tixte.Forbidden(response=None, data=None, *args, **kwargs)

An exception raised when the user does not have permission to perform an action.

This inherits from HTTPException.

exception tixte.TixteServerError(response=None, data=None, *args, **kwargs)

An exception raised when an internal Tixte server error occurs from the API.

This inherits from HTTPException.

exception tixte.PaymentRequired(response=None, data=None, *args, **kwargs)

An exception raised when you attempt to perform an operation on your account with the wrong payment tier.

This inherits from HTTPException.

Exception Hierarchy