Skip to main content
https://travis-ci.org/soundcloud/soundcloud-python.svg

A friendly wrapper around the Soundcloud API.

Installation

To install soundcloud-python, simply:

pip install soundcloud

Or if you’re not hip to the pip:

easy_install soundcloud

Basic Use

To use soundcloud-python, you must first create a Client instance, passing at a minimum the client id you obtained when you registered your app:

import soundcloud

client = soundcloud.Client(client_id=YOUR_CLIENT_ID)

The client instance can then be used to fetch or modify resources:

tracks = client.get('/tracks', limit=10)
for track in tracks:
    print track.title
app = client.get('/apps/124')
print app.permalink_url

Authentication

All OAuth2 authorization flows supported by the Soundcloud API are available in soundcloud-python. If you only need read-only access to public resources, simply provide a client id when creating a Client instance:

import soundcloud

client = soundcloud.Client(client_id=YOUR_CLIENT_ID)
track = client.get('/tracks/30709985')
print track.title

If however, you need to access private resources or modify a resource, you will need to have a user delegate access to your application. To do this, you can use one of the following OAuth2 authorization flows.

Authorization Code Flow

The Authorization Code Flow involves redirecting the user to soundcloud.com where they will log in and grant access to your application:

import soundcloud

client = soundcloud.Client(
    client_id=YOUR_CLIENT_ID,
    client_secret=YOUR_CLIENT_SECRET,
    redirect_uri='http://yourapp.com/callback'
)
redirect(client.authorize_url())

Note that redirect_uri must match the value you provided when you registered your application. After granting access, the user will be redirected to this uri, at which point your application can exchange the returned code for an access token:

access_token, expires, scope, refresh_token = client.exchange_token(
    code=request.args.get('code'))
render_text("Hi There, %s" % client.get('/me').username)

User Credentials Flow

The User Credentials Flow allows you to exchange a username and password for an access token. Be cautious about using this flow, it’s not very kind to ask your users for their password, but may be necessary in some use cases:

import soundcloud

client = soundcloud.Client(
    client_id=YOUR_CLIENT_ID,
    client_secret=YOUR_CLIENT_SECRET,
    username='jane@example.com',
    password='janespassword'
)
print client.get('/me').username

Examples

Resolve a track and print its id:

import soundcloud

client = soundcloud.Client(client_id=YOUR_CLIENT_ID)

track = client.get('/resolve', url='http://soundcloud.com/forss/flickermood')

print track.id

Upload a track:

import soundcloud

client = soundcloud.Client(access_token="a valid access token")

track = client.post('/tracks', track={
    'title': 'This is a sample track',
    'sharing': 'private',
    'asset_data': open('mytrack.mp4', 'rb')
})

print track.title

Start following a user:

import soundcloud

client = soundcloud.Client(access_token="a valid access token")
user_id_to_follow = 123
client.put('/me/followings/%d' % user_id_to_follow)

Update your profile description:

import soundcloud

client = soundcloud.Client(access_token="a valid access token")
client.put('/me', user={
    'description': "a new description"
})

Proxy Support

If you’re behind a proxy, you can specify it when creating a client:

import soundcloud

proxies = {
    'http': 'example.com:8000'
}
client = soundcloud.Client(access_token="a valid access token",
                           proxies=proxies)

The proxies kwarg is a dictionary with protocols as keys and host:port as values.

Redirects

By default, 301 or 302 redirects will be followed for idempotent methods. There are certain cases where you may want to disable this, for example:

import soundcloud

client = soundcloud.Client(access_token="a valid access token")
track = client.get('/tracks/293/stream', allow_redirects=False)
print track.location

Will print a tracks streaming URL. If allow_redirects was omitted, a binary stream would be returned instead.

Running Tests

To run the tests, run:

$ pip install -r requirements.txt
$ nosetests --with-doctest
..................

Success!

Contributing

Contributions are awesome. You are most welcome to submit issues, or fork the repository.

soundcloud-python is published under a BSD License.

Metadata

Release files for soundcloud 0.5.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 soundcloud 0.5.0
File Size Uploaded
soundcloud-0.5.0.tar.gz 10.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for soundcloud 0.5.0
File Interpreter ABI Platform
soundcloud-0.5.0-py2-none-any.whl Python 2 none any Details

Total release size: 23.5 kB

Release files / soundcloud-0.5.0.tar.gz

Download URL soundcloud-0.5.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
aad2003592cec945f835f158f7b41ba8bf805c5738a2fcc5629668ea1df653d5
BLAKE2b-256 checksum
How to use checksums
17b5fb20e83bae6dfbebb6f36e566111d2e8eb39ad068ddb93b4f04bb42a2b57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / soundcloud-0.5.0-py2-none-any.whl

Download URL soundcloud-0.5.0-py2-none-any.whl
Size 12.6 kB
Tags Python 2
SHA-256 checksum
How to use checksums
16ac26b6942b7c8ff76f32fdccefdb70c22f430e65b256c28e5b1c53ef573d1f
BLAKE2b-256 checksum
How to use checksums
68f2b6ddd262786f3a31db342ad223feebb9774e4809672106b9cfc9b4798d87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.2

2 release files

0.4.1

1 release file

0.4.0

1 release file

0.3.9

1 release file

0.3.8

1 release file

0.3.7

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

2 release files

0.3.3

0.3.2

0.3.1

1 release file

0.3

1 release file

0.2

1 release file

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