API Reference¶
Client¶
- asynccleanup
- asynccreate_domain
- asyncfetch_client_user
- asyncfetch_config
- asyncfetch_domains
- asyncfetch_upload
- asyncfetch_upload_key
- asyncfetch_uploads
- asyncfetch_user
- defget_domain
- defget_listeners
- defget_partial_upload
- defget_user
- @listen
- defremove_listener
- asyncsearch_upload
- asyncupload
- asyncurl_to_file
- asyncwait_for
- 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 theaiohttp.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 includehttps://
in your domain, just the domain itself. An example of this would betest.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 theuser
method will beClientUser
100% of the time. Defaults toFalse
. 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 toFalse
.- Type
- @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
]
- 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 fromwait_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 theasyncio.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 withon_
, 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 raisingasyncio.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.
- get_domain(url, /)¶
Gets a domain from the internal cache of domains.
- 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
- 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
- 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 notediscord.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 eitherpublic
orprivate
.
- Returns
The response from the upload.
- Return type
- 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 aFile
object with the contents.
- 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 thefetch_client_user_on_start
attribute isTrue
and the client is run in a context manager setting.- Returns
The client’s user.
- Return type
- 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
- 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
- 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 to48
as that’s what Tixte defaults to.min_size (Optional[
int
]) – The minimum size of the upload. Defaults toNone
.max_size (Optional[
int
]) – The maximum size of the upload. Defaults toNone
.sort_by (
str
) – The sort order of the results. This defaults torelevant
. 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. IfFalse
, than the domain must end intixte.co
,likes.cash
,discowd.com
,has.rocks
,is-from.space
,bot.style
,needs.rest
, orwants.solutions
.
- Returns
The domain that was created.
- Return type
ABC¶
Object¶
- class tixte.abc.Object¶
The base object for all objects within the Tixte system. Every class inherits from this.
IDable¶
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.
- 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 adiscord.Embed
class.- Returns
An instance of your embed class.
- Return type
Any
Domain¶
- 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.
- 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
- 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 adomain
key.- Return type
File¶
- 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 offp
if it’s a file-like object. Note if the filename can not be found thenValueError
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 ofio.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 iffp
is a string then thefilename
will default to the string given.- Type
Optional[
str
]
- close()¶
Closes the file.
PartialUpload¶
- 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.
Upload¶
- asyncfetch_domain
- asyncto_file
- 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.
- 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
]
- permissions¶
A mapping of users to their permission levels.
- Type
Dict[
User
,UploadPermissionLevel
]
- type¶
The type of upload.
- Type
- await to_file()¶
This function is a coroutine.
A coroutine to turn this
Upload
to aFile
object.- Returns
The file object created from downloading this upload’s image.
- Return type
- 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
- Raises
Forbidden – You do not have permission to fetch this domain.
HTTPException – An HTTP exception has occurred.
DeleteResponse¶
Permissions¶
- class tixte.Permissions(*, state, upload, permission_mapping=None)¶
Represents the Permissions of a
PartialUpload
orUpload
.Please note that if this stems from a
PartialUpload
, then theget()
method will beNone
100% of the time unless you callfetch()
.- 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 callingfetch()
.- 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()
returnsNone
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 userUploadPermissionLevel.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
- 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.
- 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
Users¶
User¶
- asyncsave_avatar
- 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.
ClientUser¶
- asyncsave_avatar
- 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.
- phone¶
The phone, if any, linked to the user account.
- Type
Optional[Any]
Your current premium status.
- Type
- property last_login¶
The last time the user logged in.
- Type
Enums¶
Region¶
UploadPermissionLevel¶
UploadType¶
Utility Functions¶
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.
- 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
.