Python SDK
The Python SDK for using the Platform API is available on our GitHub.
Installation
Install the dailymotion module:
$ pip install dailymotionOr:
$ git clone [email protected]:dailymotion/dailymotion-sdk-python.git
$ cd dailymotion-sdk-python
$ python setup.py installAuthentication
The Platform API requires OAuth 2.0 authentication to access protected resources.
The Dailymotion Python SDK uses lazy authentication, meaning no authentication request is made until data is actually requested. When the first request is made, the SDK sends two back‑to‑back calls: one for authentication, one for data.
The SDK abstracts the entire OAuth flow, automatically handling access tokens, refresh tokens, and session management.
Session storage is enabled by default and can be disabled using:
dailymotion.Dailymotion(session_store_enabled=False)Access tokens are stored in memory by default, but storing them in your OS file system is recommended:
import dailymotion
# The ./data directory
file_session = dailymotion.FileSessionStore('./data')
d = dailymotion.Dailymotion(session_storage=file_session)
...Tests
- Install dependencies:
$ pip install -r requirements.txt- Update the file
config.pyor use environment variables with:
CLIENT_ID = '[YOUR API KEY]'
CLIENT_SECRET = '[YOUR API SECRET]'
USERNAME = '[YOUR USERNAME]'
PASSWORD = '[YOUR PASSWORD]'
REDIRECT_URI = '[YOUR REDIRECT URI]'
BASE_URL = 'https://api.dailymotion.com'
OAUTH_AUTHORIZE_URL = 'https://www.dailymotion.com/oauth/authorize'
OAUTH_TOKEN_URL = 'https://api.dailymotion.com/oauth/token'- Run tests:
$ py.test TestDailymotion.pyExamples
API call without authentication
d = dailymotion.Dailymotion()
d.get('/videos')Set your own access token (your token must still be valid)
d = dailymotion.Dailymotion()
d.set_access_token(YOUR_ACCESS_TOKEN)
d.get('/me')Authenticated call
d = dailymotion.Dailymotion()
d.set_grant_type(
'password',
api_key=API_KEY,
api_secret=API_SECRET,
scope=['userinfo'],
info={'username': USERNAME, 'password': PASSWORD}
)
d.get('/me', {'fields': 'id,fullname'})Video Upload
d = dailymotion.Dailymotion()
d.set_grant_type(
'password',
api_key=API_KEY,
api_secret=API_SECRET,
scope=['manage_videos'],
info={'username': USERNAME, 'password': PASSWORD}
)
url = d.upload('./video.mp4')
d.post(
"/me/videos",
{
"url": url,
"title": "MyTitle",
"published": "true",
"channel": "news",
"is_created_for_kids": "false",
},
)Updated 9 days ago
