freesound.py
A Python client for the Freesound APIv2.
This is a cold fork of https://github.com/MTG/freesound-python for publishing on pypi
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).
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.
Example usage:
import freesound
client = freesound.FreesoundClient()
client.set_token("<your_api_key>","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
pip install freesound-api
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:
proxies = {
'http': 'http://10.10.1.10:3128',
'https': 'http://10.10.1.10:1080',
}
client.session.proxies.update(proxies)
or adding rate limiting:
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.
from requests_oauthlib import OAuth2Session
import freesound
client_id = "<your_client_id>"
client_secret = "<your_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")
Metadata
Release files for freesound-api 1.1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| freesound_api-1.1.0.2.tar.gz | 6.8 kB | Without provenance | Details for freesound_api-1.1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| freesound_api-1.1.0.2-py3-none-any.whl | Python 3 | none | any | Details for freesound_api-1.1.0.2-py3-none-any.whl |
Total release size: 14.5 kB
Release files / freesound_api-1.1.0.2.tar.gz
| Download URL | freesound_api-1.1.0.2.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
125ea71f627a1bc7dacfd2ddf181a15ded3d0544028057ce5b95b19ee168c960
|
|
BLAKE2b-256 checksum How to use checksums |
4051de0a0dc0e84b6a6524fb2ffc88cfd310d60193b8f2167ad1ddec10eeff1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-56-generic
|
Release files / freesound_api-1.1.0.2-py3-none-any.whl
| Download URL | freesound_api-1.1.0.2-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
765436f015046ec9f12e1bc111076aff1a05ba5c3fdba1bc1338d567bc62aaf2
|
|
BLAKE2b-256 checksum How to use checksums |
a404f7b380d0f6705df2163be1eb9d05e856929711092c6db14b2247e3169d76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-56-generic
|
Security for freesound-api 1.1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.