Module Reference
aiomixcloud.auth module
- class aiomixcloud.auth.MixcloudOAuth(oauth_root='https://www.mixcloud.com/oauth', *, client_id=None, client_secret=None, redirect_uri=None, raise_exceptions=None, mixcloud=None)[source]
Bases:
object
Mixcloud OAuth authorization
By having
client_id
andredirect_uri
set, aMixcloudOAuth
object providesauthorization_url
, a URL to forward the end user to, where they will be able to “allow the application access to their data”. It also provides theaccess_token()
method, which trades an OAuth code for an access token (requiringclient_secret
as well as the previously mentionted attributes).- async access_token(code)[source]
Send OAuth code to server and get an access token. If fail raise
MixcloudOAuthError
in case this is the setting (self._raise_exceptions
orself.mixcloud._raise_exceptions
), otherwise returnNone
.
- property authorization_url
Return authorization URL.
- client_id
Client ID, provided by Mixcloud
- client_secret
Client secret, provided by Mixcloud
- mixcloud
The
Mixcloud
object whose session will be used to make the request from. IfNone
, a new session will be created for the access token request.
- oauth_root = 'https://www.mixcloud.com/oauth'
Default Mixcloud OAuth root URL
- redirect_uri
Redirect URI, chosen by the developer
aiomixcloud.constants module
Constant values
This module includes constant, hard-coded values used throughout the package.
- aiomixcloud.constants.API_ROOT = 'https://api.mixcloud.com'
Mixcloud API root URL
- aiomixcloud.constants.DESCRIPTION_MAX_SIZE = 1000
Uploaded description maximum allowed size, in characters
- aiomixcloud.constants.MIXCLOUD_ROOT = 'https://www.mixcloud.com'
Mixcloud root URL
- aiomixcloud.constants.MP3_MAX_SIZE = 4294967296
Uploaded mp3 maximum allowed size, in bytes
- aiomixcloud.constants.OAUTH_ROOT = 'https://www.mixcloud.com/oauth'
Mixcloud OAuth root URL
- aiomixcloud.constants.OEMBED_ROOT = 'https://www.mixcloud.com/oembed'
Mixcloud oEmbed root URL
- aiomixcloud.constants.PICTURE_MAX_SIZE = 10485760
Uploaded picture maximum allowed size, in bytes
- aiomixcloud.constants.TAG_MAX_COUNT = 5
Tag maximum allowed count per upload
aiomixcloud.core module
Main functionality coordination
This module contains the class responsible for aggregating and organizing the main functionality and usage of the package. Specifically:
Mixcloud
, providing the interface of the package. Stores the basic configuration and preferences, holds the session which API calls are made from and has all the methods necessary to reach every endpoint of the API, as well as take advantage of its capabilities.
- class aiomixcloud.core.Mixcloud(api_root='https://api.mixcloud.com', *, access_token=None, mixcloud_root='https://www.mixcloud.com', oembed_root='https://www.mixcloud.com/oembed', json_decoder_class=<class 'aiomixcloud.json.MixcloudJSONDecoder'>, resource_class=<class 'aiomixcloud.models.Resource'>, resource_list_class=<class 'aiomixcloud.models.ResourceList'>, raise_exceptions=False, session=None)[source]
Bases:
object
Asynchronous Mixcloud API handler
This class orchestrates the interaction of the package’s user with the Mixcloud API. Being ready for use with no explicit configuration at all, as well as being capable of customized operation, it provides the methods to hit the API. A common to use method and base for many of the rest, is the
get()
method, which takes a “key”, a URL segment corresponding to a unique API resource and returns a native, yet familiar and handy data structure representing that resource. There, also, exist a family of methods, likepopular()
, which receive pagination arguments and return a list of resources. The class provides some personalized methods, that is methods which require authorization to run, through an access token. These are methods likefollow()
andunfollow()
. In this category belong the methods about uploading data to the server,upload()
andedit()
. Finally, there are methods about getting embedding information for some resource, likeembed_html()
. The class can be used as an asynchronous context manager to avoid having to callclose()
explicitly, which closes the session.- access_token
OAuth Access token
- api_root = 'https://api.mixcloud.com'
Default Mixcloud API root URL
- async edit(key, params, *, name=None)[source]
Edit upload identified by key, as described by specified parameters.
- async embed_html(*args, **kwargs)[source]
Get embed data for given cloudcast, in HTML format using specified display options.
- async embed_json(*args, **kwargs)[source]
Get embed data for given cloudcast, in JSON format using specified display options.
- async get(url, *, relative=True, create_connections=True, **params)[source]
Send a GET request to API and return JSON-decoded data. If relative is
True
, url is considered relative to the API root, otherwise it is considered as an absolute URL.
- json_decoder_class
Default JSON decoder class
alias of
MixcloudJSONDecoder
- async listen_later(cloudcast)[source]
Add cloudcast to “listen later” list and return results of the request.
- mixcloud_root = 'https://www.mixcloud.com'
Default Mixcloud root URL
- async oembed(key, params)[source]
Get oEmbed data for resource identified by key, in desirable format using specified display options.
- oembed_root = 'https://www.mixcloud.com/oembed'
Default Mixcloud oEmbed root URL
- resource_list_class
Resource model list class
alias of
ResourceList
- async search(query, params, *, type='cloudcast')[source]
Search resources of type by query and return found information.
aiomixcloud.datetime module
Datetime formatting
This module contains functions about presenting datetimes in various formats. Specifically:
format_datetime()
, returning a “YYYY-MM-DDTHH:MM:SSZ”-formatted datetime string out of a datetime-like value.
to_timestamp()
, returning a UNIX timestamp out of a datetime-like value.
The datetime-like argument of those functions can be a
datetime
object, a human-readable datetime string
or a timestamp. Timezone-naive values will be treated as being in the
local timezone. Result will be converted in UTC, if not already there.
aiomixcloud.decorators module
Function decorators
This module contains decorators for functions of the package. Specifically:
displayed()
, handling requests with varying response format and HTML display information by defining the proper arguments and passing a dict produced out of them to the decorated coroutine.
paginated()
, handling pagination of resource lists by defining the proper arguments, checking their validity and passing a dict produced out of them to the decorated coroutine.
personal()
, checking that access_token is set on the object which owns the decorated coroutine method, before awaiting it.
targeting()
, marking the decorated coroutine as one that targets a specific resource identified by a key, making said coroutine available as aResource
method.
uploading()
, handling requests that upload data to the server by defining the proper arguments and passing a dict produced out of them to the decorated coroutine.
- aiomixcloud.decorators.displayed(coroutine)[source]
Return a coroutine that takes arguments about desired response format and HTML display and makes a parameters dictionary out of them. Then, it passes that dictionary to the original coroutine, while awaiting it.
- aiomixcloud.decorators.paginated(coroutine)[source]
Return a coroutine that takes pagination arguments, runs checks on them and makes a parameters dictionary out of them. Then, it passes that dictionary to the original coroutine, while awaiting it.
- aiomixcloud.decorators.personal(coroutine)[source]
Return a coroutine method that checks if access_token is set on self.
aiomixcloud.exceptions module
Exception types
This module contains custom exceptions raised during use of the package. Specifically:
MixcloudError
, indicating that API returned an error response.
MixcloudOAuthError
, indicating that something went wrong with the OAuth authorization process.
aiomixcloud.json module
JSON decoder
This module contains the class responsible for decoding the JSON data retrieved from the API requests. Specifically:
MixcloudJSONDecoder
, turning datetime-like strings todatetime
objects.
aiomixcloud.models module
Basic data structures
This module contains the basic data structures used throughout the package. Specifically:
_WrapMixin
, a mixin providing type casting of accessed items.
AccessDict
, dict-like, supports accessing items by attribute. Accessed items are properly wrapped.
AccessList
, list-like, supports accessingResource
items by their “key” key. Accessed items are properly wrapped.
Resource
, like anAccessDict
which has a “type” key. Gets methods for downloading its “connections”, that is the sub-entities “owned” by the resource. Mirrors methods ofMixcloud
marked as “targeted” with their first argument as its key. Also provides aResource.load()
method to download full resource information in case it is partly loaded as an element of another API response.
ResourceList
, like anAccessDict
which delegates string indexing and iterating over, to its “data” item. Supports pagination through theResourceList.previous()
andResourceList.next()
methods, which return a new object with the respective data.
- class aiomixcloud.models.AccessDict(data, *, mixcloud)[source]
Bases:
_WrapMixin
,UserDict
Dict-like model which supports accessing items using keys as attributes. Items are wrapped with a proper model, depending on their type. Original dict is stored in self.data.
- class aiomixcloud.models.AccessList(data, *, mixcloud)[source]
Bases:
_WrapMixin
,UserList
List-like model which supports accessing
Resource
-like items by matching their “key” item. Items are wrapped with a proper model, depending on their type. Original list is stored in self.data.
- class aiomixcloud.models.Resource(data, *, full=False, create_connections=True, mixcloud)[source]
Bases:
AccessDict
Mixcloud API resource
A resource is like an
AccessDict
object which has a “type” key. When a “type” key is present in an API (sub)object, suggesting it has a unique URL, it is considered an API resource, that is an individual entity (a user, a cloudcast, a tag, etc). AResource
object has appropriately named methods for downloading information about its sub-entities (“connections”). It also mirrors “targeted” methods of itsMixcloud
instance, passing them its key as a first argument. Targeted methods include “actions” (e.gfollow()
orunfavorite()
), embed-related methods andedit()
.
- class aiomixcloud.models.ResourceList(data, *, mixcloud)[source]
Bases:
AccessDict
Contains a list of resources, with paging capabilities. Main data is stored in the
'data'
item, while a'paging'
item may be present indicating URLs of the previous and next pages of the resource list, as well as a ‘name’ item describing the collection. Indexing falls back toself['data']
on failure, while iterating over and length concern “data” straight up.
aiomixcloud.sync module
Synchronous operation mode
This module contains synchronous (i.e blocking) versions of the package classes. Specifically:
MixcloudOAuthSync
, synchronous version ofMixcloudOAuth
, handling OAuth authorization.
MixcloudSync
, synchronous version ofMixcloud
, handling main functionality coordination.
- class aiomixcloud.sync.MixcloudOAuthSync(*args, **kwargs)
Bases:
object
Synchronous version of
MixcloudOAuth
.- method(*args, method_name='__repr__')
Mirror original object’s method with given method_name.
- method_name = '__repr__'
- name = 'repr'
- class aiomixcloud.sync.MixcloudSync(*args, **kwargs)[source]
Bases:
MixcloudSync
Synchronous version of
Mixcloud
with synchronous context management capabilities.