EnsembleData Python API
Documentation
Check out the API docs to see which endpoints are available for each social media and for detailed descriptions of their parameters and functionality.
Installation
Install the package with pip as you would any other python package.
pip install ensembledata-python
Requirements
- The package only supports Python 3.7 and above.
Usage
Register to get your free API token.
from ensembledata.api import EDClient
client = EDClient("API-TOKEN")
result = client.tiktok.user_info_from_username("daviddobrik")
print("Data: ", result.data)
print("Units charged:", result.units_charged)
TikTok Usage Docs
Explore the extensive usage documentation for the TikTok API.
Instagram Usage Docs
Explore the extensive usage documentation for the Instagram API.
Youtube Usage Docs
Explore more extensive usage documentation for the Youtube API.
Missing Endpoints / Parameters
If you find that one of the endpoints from our API docs is not yet available in this package, you can use the EDClient.request
method to specify the endpoint manually in the meantime.
from ensembledata.api import EDClient
client = EDClient("API-TOKEN")
result = client.request("/instagram/[example]", params={"foo": "...", "bar": "..."})
If you find that one the parameters to an existing endpoint is missing, you can still send this parameter via the extra_params
dictionary which is available on all endpoint methods. See the example below:
from ensembledata.api import EDClient
client = EDClient("API-TOKEN")
result = client.instagram.user_info(username="...", extra_params={"baz": "..."})
Handling Errors
In the API docs, each endpoint lists a handful of possible errors the API may respond with. You can handle these errors by catching the EDError
exception.
from ensembledata.api import EDClient, EDError
client = EDClient("API-TOKEN")
try:
result = client.tiktok.user_info_from_username("daviddobrik")
except EDError as e:
if e.status_code == 429:
print(e.detail)
if e.status_code == 493:
print(e.detail)
except Exception as e:
pass
Async
This package provides an asynchronous client, EDAsyncClient
, which will give you access to async versions of all the same methods that can be found on the EDClient
.
import asyncio
from ensembledata.api import EDAsyncClient
async def main():
client = EDAsyncClient("API-TOKEN")
result = await client.tiktok.user_info_from_username("daviddobrik")
if __name__ == "__main__":
asyncio.run(main())
Types
The package uses type hints, and is type checked with the latest version of mypy
. If you experience any type checking related issues with the package, please let us know by creating an issue.