Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MTG/freesound-python
python client for the freesound API
https://github.com/MTG/freesound-python
Last synced: 3 months ago
JSON representation
python client for the freesound API
- Host: GitHub
- URL: https://github.com/MTG/freesound-python
- Owner: MTG
- License: mit
- Created: 2010-10-01T15:32:55.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2023-07-28T03:23:08.000Z (over 1 year ago)
- Last Synced: 2024-06-03T10:48:31.360Z (5 months ago)
- Language: Python
- Homepage:
- Size: 189 KB
- Stars: 126
- Watchers: 22
- Forks: 36
- Open Issues: 8
-
Metadata Files:
- Readme: Readme.md
- License: COPYING.txt
Awesome Lists containing this project
- awesome-python-audio - freesound-python
README
freesound.py
============A Python client for the [Freesound](https://freesound.org) APIv2.
Find the API documentation at http://www.freesound.org/docs/api/.
Apply for an API key at https://www.freesound.org/apiv2/apply/.The client automatically maps function arguments to http parameters of the API.
JSON results are converted to python objects, but are also available in their original form (JSON loaded into dictionaries) using the method `.as_dict()` of returned objets (see [examples file](https://github.com/MTG/freesound-python/blob/master/examples.py)).
The main object types (`Sound`, `User`, `Pack`) are augmented with the corresponding API calls.Note that POST resources are not supported. Downloading full quality sounds requires Oauth2 authentication (see https://freesound.org/docs/api/authentication.html). Oauth2 authentication is supported by passing an access token, but you are expected to implement the workflow to obtain that access token. Here is an [example implementation of the Freesound OAuth2 workflow using Flask](https://gist.github.com/ffont/3607ba4af9814f3877cd42894a564222).
Example usage:
```python
import freesoundclient = freesound.FreesoundClient()
client.set_token("","token")results = client.text_search(query="dubstep",fields="id,name,previews")
for sound in results:
sound.retrieve_preview(".",sound.name+".mp3")
print(sound.name)```
## Installation
1) clone or download2) run:
```
python setup.py install
```Alternatively you should also be able to install directly from GitHub with:
```
pip install git+https://github.com/MTG/freesound-python
```## Advanced usage
### Modifying the requests' session:
You can easily extend/modify the way how requests are done by interacting directly with
the session object of the client.For example, adding proxies:
```python
proxies = {
'http': 'http://10.10.1.10:3128',
'https': 'http://10.10.1.10:1080',
}
client.session.proxies.update(proxies)
```or adding [rate limiting](https://github.com/JWCook/requests-ratelimiter):
```python
from requests_ratelimiter import LimiterSession# Apply a rate-limit (59 requests per minute) to all requests
client.session = LimiterSession(per_minute=59)
```### Authenticating with OAuth
Here is an example authentication flow with the help of [Requests-OAuthlib](https://requests-oauthlib.readthedocs.io/).
```python
from requests_oauthlib import OAuth2Sessionimport freesound
client_id = ""
client_secret = ""# do the OAuth dance
oauth = OAuth2Session(client_id)authorization_url, state = oauth.authorization_url(
"https://freesound.org/apiv2/oauth2/authorize/"
)
print(f"Please go to {authorization_url} and authorize access.")authorization_code = input("Please enter the authorization code:")
oauth_token = oauth.fetch_token(
"https://freesound.org/apiv2/oauth2/access_token/",
authorization_code,
client_secret=client_secret,
)client = freesound.FreesoundClient()
client.set_token(oauth_token["access_token"], "oauth")
```