Skip to main content

Mixcloud.com API access from Python

Build Status Coverage Status

This provides a Python API for the http://mixcloud.com website.

Example

from mixcloud import Mixcloud
m = Mixcloud()
u = m.user('michelplatiniste')
for c in u.cloudcasts():
    print c.name

Authorization

You must have an application registered with Mixcloud and a corresponding client ID and secret.

Authorization is a multi-step process:

  1. Generate the authorization URL

  2. Redirect the user to the URL to authorize your application

  3. Collect the code query string parameter from the redirect

  4. Exchange the code for an access token

o = mixcloud.MixcloudOauth(
    client_id=client_id, client_secret=client_secret,
    redirect_uri=redirect_uri)

url = o.authorize_url()

# Next redirect the user to `url`. They will be redirected to your
# redirect uri with a `code` query string parameter. This must be
# exchanged with Mixcloud for an access token.

access_token = o.exchange_token(code)

# This can then be used for calls that required authorization.

m = mixcloud.Mixcloud(access_token=access_token)
print(m.me())

Optionally you can store an access token in your .netrc file and it will be used automatically. The machine name must be mixcloud-api.

E.g.:

machine mixcloud-api
password my_access_token

Uploading

It is possible to use this module to upload cloudcasts. In order to do that you need to be authenticated. To do that, provide an API token to the constructor.

m = mixcloud.Mixcloud(access_token=access_token)
cc = Cloudcast(...)
with open(mp3_path) as mp3:
    r = m.upload(cc, mp3)

YML file support

It is possible to represent cloudcasts as YAML files. See example.yml.

The relevant keys are:

Key

Type

title

String

desc

String

tags

List of strings

tracks

List of tracks

Each track is a dict with the following keys:

Key

Type

start

Integer

artist

String

track

String

You can leverage YAML syntax for the “start” field: 2:54 will be parsed directly as 174 (then number of seconds).

It is possible to parse such a file with:

with open(yml_path) as yml:
    cc = mixcloud.Cloudcast.from_yml(yml, None)

Mocking

A mock server is provided for testing purposes in mixcloud.mock.

Changelog

0.4.0

release date: 2015-10-27

  • Switch to semantic versioning.

  • Include access token when calling /me (#10)

  • Add a helper class for OAuth (#11)

  • Support access token stored in netrc (#9, #12)

0.0.3

release date: 2015-03-15

  • Pictures can be uploaded and retrieved (#6)

  • Include LICENSE in tarball (#8)

0.0.2

release date: 2015-01-28

  • Switch from requirements.txt to install_requires (#7)

  • Add HISTORY.rst to MANIFEST.in

0.0.1

release date: 2015-01-28

  • Initial release

Release files for mixcloud 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mixcloud 0.4.0
File Size Uploaded
mixcloud-0.4.0.tar.gz 7.7 kB Details

Release files / mixcloud-0.4.0.tar.gz

Download URL mixcloud-0.4.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
797a7ac23187b033411d2a0897b4068af774eea93e92d18ac4f542f95af0d661
BLAKE2b-256 checksum
How to use checksums
e39e70aedb77e9b5d99b54dd569d0ba2357cb64909b20805f459f90d45c426c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.4.0 This release

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page