Importing Facebook Ads Data Into Python

Facebook Premium Marketing Partner

Importing Facebook ads data has never been easier using the token. With a couple of lines of code, you will be able to fetch the desired data columns into your python project. However, before we start doing that, let’s quickly create a free account on the Windsor website: Grab your API key and let’s get started.

Windsor has its own Facebook Ads python library which makes things simpler. You can install the package by running

pip install FacebookAdsWindsorApi

Next, we need to load the package client

from FacebookAdsWindsorApi.client import Client

Paste your API key into the following code

client = Client(API_KEY)

Lastly, you can fetch the columns you want by running

response = client.connectors(
    fields=["date", "clicks", "spend"]

Which returns the following dictionary

>>> [{'date': '2022-10-28', 'clicks': '3', 'spend': '6.27'},
 {'date': '2022-10-29', 'clicks': '5', 'spend': '6.24'},
 {'date': '2022-10-30', 'clicks': '2', 'spend': '4.5'}]

For a full list of possible Facebook Ads library fields you can visit the connector documentation on Windsor’s official website The official python package can be found in the following GitHub repository:

Moreover, for a more general python package, you can check Windsor’s pywindsorai library where you can integrate all of your ad platforms in no time. Some of the supported platforms are: Google Ads, Facebook Ads, Twitter Ads, TikTok Ads, Linkedin Ads, and more. The full list of the supported platforms can be found here.

For other data python project, you can visit the how-to website where various data analytics solutions are discussed.