freshcrate
Home > Frameworks > facebook-business

facebook-business

Facebook Business SDK

Description

# Facebook Business SDK for Python [![PyPI](https://img.shields.io/pypi/v/facebook-business)](https://pypi.org/project/facebook-business/) [![Build Status](https://img.shields.io/github/actions/workflow/status/facebook/facebook-python-business-sdk/ci.yml)](https://github.com/facebook/facebook-python-business-sdk/actions/workflows/ci.yml) [![License](https://img.shields.io/badge/license-Facebook%20Platform-blue.svg?style=flat-square)](https://github.com/facebook/facebook-python-business-sdk/blob/main/LICENSE.txt) ### Introduction The Facebook <a href="https://developers.facebook.com/docs/business-sdk" target="_blank">Business SDK</a> is a one-stop-shop to help our partners better serve their businesses. Partners are using multiple Facebook API's to serve the needs of their clients. Adopting all these API's and keeping them up to date across the various platforms can be time consuming and ultimately prohibitive. For this reason Facebook has developed the Business SDK bundling many of its APIs into one SDK to ease implementation and upkeep. The Business SDK is an upgraded version of the Marketing API SDK that includes the Marketing API as well as many Facebook APIs from different platforms such as Pages, Business Manager, Instagram, etc. ## Quick Start Business SDK <a href="https://developers.facebook.com/docs/business-sdk/getting-started" target="_blank">Getting Started Guide</a> Python is currently the most popular language for our third-party developers. `facebook_business` is a Python package that provides an interface between your Python application and <a href="https://developers.facebook.com/docs/business-sdk/reference" target="_blank">Facebook's APIs within the Business SDK</a>. This tutorial covers the basic knowledge needed to use the SDK and provides some exercises for the reader. **NOTE**: ``facebook_business`` package is compatible with Python 2 and 3! ## Pre-requisites ### Register An App To get started with the SDK, you must have an app registered on <a href="https://developers.facebook.com/" target="_blank">developers.facebook.com</a>. To manage the Marketing API, please visit your <a href="https://developers.facebook.com/apps/<YOUR APP ID>/dashboard"> App Dashboard </a> and add the <b>Marketing API</b> product to your app. **IMPORTANT**: For security, it is recommended that you turn on 'App Secret Proof for Server API calls' in your app's Settings->Advanced page. ### Obtain An Access Token When someone connects with an app using Facebook Login and approves the request for permissions, the app obtains an access token that provides temporary, secure access to Facebook APIs. An access token is an opaque string that identifies a User, app, or Page. For example, to access the Marketing API, you need to generate a user access token for your app and ask for the ``ads_management`` permission; to access Pages API, you need to generate a Page access token for your app and ask for the ``manage_page`` permission. Refer to our <a href="https://developers.facebook.com/docs/facebook-login/access-tokens" target="_blank"> Access Token Guide</a> to learn more. For now, we can use the <a href="https://developers.facebook.com/tools/explorer" target="_blank">Graph Explorer</a> to get an access token. ## Install package The easiest way to install the SDK is via ``pip`` in your shell. **NOTE**: For Python 3, use ``pip3`` and ``python3`` instead. **NOTE**: Use ``sudo`` if any of these complain about permissions. (This might happen if you are using a system installed Python.) If you don't have pip: ``` easy_install pip ``` Now execute when you have pip: ``` pip install facebook_business ``` If you care for the latest version instead of a possibly outdated version in the <a href="https://pypi.python.org" target="_blank">pypi.python.org</a> repository, <a href="https://github.com/facebook/facebook-python-business-sdk">check out the repository from GitHub or download a release tarball</a>. Once you've got the package downloaded and unzipped, install it: ``` python setup.py install ``` Great, now you are ready to use the SDK! ## Bootstrapping ### Create test.py Create a test.py file with the contents below (assuming your system is using python 2.7 and installed under /opt/homebrew. Update to your proper python location.): ```python import sys sys.path.append('/opt/homebrew/lib/python2.7/site-packages') # Replace this with the place you installed facebookads using pip sys.path.append('/opt/homebrew/lib/python2.7/site-packages/facebook_business-3.0.0-py2.7.egg-info') # same as above from facebook_business.api import FacebookAdsApi from facebook_business.adobjects.adaccount import AdAccount my_app_id = 'your-app-id' my_app_secret = 'your-appsecret' my_access_token = 'your-page-access-token' FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token) my_account = AdAccount('act_<your-adaccount-id>') campaigns = my_account.get_campaigns() print(campaigns) ``` ### Test Your Install Test you

Release History

VersionChangesUrgencyDate
25.0.1Imported from PyPI (25.0.1)Low4/21/2026
25.0.0In this release, Advantage+ Shopping Campaigns (ASC) and Advantage+ App Campaigns (AAC) can no longer be created or updated via the Marketing API starting v25.0, extending to all versions by May 19, 2026, as part of the Automation Unification toward the streamlined Advantage+ setup. The Ads Insights Async API now returns detailed error information on report failures, and several legacy metrics including Page Reach, Impressions, and 3-second Viewers are planned for deprecation in June 2026 in favLow3/10/2026
24.0.1**Full Changelog**: https://github.com/facebook/facebook-python-business-sdk/compare/24.0.0...24.0.1Low11/20/2025
24.0.0In this release, there are major changes like Dynamic Media will be enabled by default for Advantage+ Catalog ads via the Marketing API, requiring developers to explicitly opt out if desired. The daily budget flexibility is increased from 25% to 75%, allowing higher spend on days with better opportunities while maintaining weekly spend limits. A new feature allows up to 20% of an ad set’s daily budget to be shared with other ad sets in the same campaign for improved performance without campaign Low10/24/2025
23.0.3**Full Changelog**: https://github.com/facebook/facebook-python-business-sdk/compare/23.0.2...23.0.3Low10/14/2025
23.0.2**Full Changelog**: https://github.com/facebook/facebook-python-business-sdk/compare/23.0.1...23.0.2Low9/26/2025
23.0.1**Full Changelog**: https://github.com/facebook/facebook-python-business-sdk/compare/23.0.0...23.0.1Low7/18/2025
23.0.0In this release, we introduced version one of ThirdPartyAccount library in Python and Node.js SDKs to simplify the usage of the 2Tier APIs. Additionally, updated parameter list for the original_event_data parameter. We are planning to extend these features to other languages soon. **Full Changelog**: https://github.com/facebook/facebook-python-business-sdk/compare/22.0.5...23.0.0Low6/17/2025
22.0.5This release contains V1 of ThirdPartyAccount Library - SDK library to simplify the usage of the 2 Tier APIs **Full Changelog**: https://github.com/facebook/facebook-python-business-sdk/compare/22.0.4...22.0.5Low5/6/2025
22.0.4**Full Changelog**: https://github.com/facebook/facebook-python-business-sdk/compare/22.0.3...22.0.4Low4/11/2025
22.0.3Hey Everyone, We are releasing latest minor version of Meta Business SDK v22.0.3. **Full Changelog**: https://github.com/facebook/facebook-python-business-sdk/compare/22.0.2...22.0.3Low4/1/2025
22.0.2Hey Everyone, We are thrilled to announce the release of Meta Business SDK v22.0, which now supports [Graph API v22.0 and Marketing API v22.0](https://developers.facebook.com/blog/post/2025/01/21/introducing-graph-api-v22-and-marketing-api-v22/). This release will include bug fixes, dependency upgrades, new features, and most importantly, an updated API interface to match Graph API v22. Here are few highlighted changes Added support on POST /{ad-account-id}/video_ads, deprecation of few instagraLow2/14/2025
21.0.5**Full Changelog**: https://github.com/facebook/facebook-python-business-sdk/compare/21.0.0...21.0.5Low1/16/2025
21.0.0**Full Changelog**: https://github.com/facebook/facebook-python-business-sdk/compare/20.0.3...21.0.0Low10/10/2024
20.0.0**Full Changelog**: https://github.com/facebook/facebook-python-business-sdk/compare/19.0.3...20.0.0Low8/15/2024
19.0.2**Full Changelog**: https://github.com/facebook/facebook-python-business-sdk/compare/19.0.1...19.0.2Low4/15/2024
19.0.1Hello again! Apologies for the delay in rolling out this minor version update. Your patience is to be rewarded! We're offering much more than you might expect from a typical minor version bump. **Full Changelog**: https://github.com/facebook/facebook-python-business-sdk/compare/19.0.0...19.0.1Low3/14/2024
19.0.0**Happy New Year!** As of January 23, 2024, we are thrilled to announce the release of Meta Business SDK v19.0, which now supports [[Graph API v19.0 and Marketing API v19.0](https://developers.facebook.com/blog/post/2024/01/23/introducing-facebook-graph-and-marketing-api-v19/)]. Due to the code freeze in December, we bypassed the minor version increments for v18.0. However, during this period, our developers remained actively engaged in our community, submitting issues and pull requests. While wLow1/24/2024
18.0.5[18.0.4..18.0.5](https://github.com/facebook/facebook-python-business-sdk/compare/18.0.4..18.0.5)Low12/4/2023
18.0.4[18.0.3..18.0.4](https://github.com/facebook/facebook-python-business-sdk/compare/18.0.3..18.0.4)Low11/6/2023
18.0.3[18.0.2..18.0.3](https://github.com/facebook/facebook-python-business-sdk/compare/18.0.2..18.0.3)Low10/15/2023
18.0.2[18.0.1..18.0.2](https://github.com/facebook/facebook-python-business-sdk/compare/18.0.1..18.0.2) πŸ› **Bug Fix** πŸ”¨ Address Python Single Quote Escape Issue https://github.com/facebook/facebook-python-business-sdk/commit/22d7355fbe25b390ca4936684140b124ddb024a9Low10/2/2023
18.0.1[18.0.0..18.0.1](https://github.com/facebook/facebook-python-business-sdk/compare/18.0.0..18.0.1)Low9/26/2023
18.0.0### Introducing Meta Business SDK v18.0 for Python Time flies. Today, (September 15, 2023) we’re announcing the release of **Meta Business SDK v18.0** to support the [[Graph API v18.0 and Marketing API v18.0](https://developers.facebook.com/blog/post/2023/09/12/introducing-facebook-graph-and-marketing-api-v18/)]. It represents a major update which addresses numerous longstanding issues and expands support to additional features, nodes, and types. While you can find a comprehensive list of chaLow9/15/2023
3.1.8* Various bug fixes See https://developers.facebook.com/docs/business-sdk/ for more detailsLow10/9/2018
3.0.0In this release we named facebook python ads sdk to facebook python business sdk. See https://developers.facebook.com/docs/business-sdk/ for more detailsLow5/19/2018
2.10.1Changelog: https://developers.facebook.com/ads/blog/post/2017/07/18/marketing-api-2.10/Low7/18/2017
2.8.1# Changes in v2.8 ## New Features - **Instant Articles** is now a separate ads placement, so that advertisers can enable or disable showing ads in Instant Articles. This new placement options is under `/ACCOUNT_ID/adsets` and `/AD_SET_ID`. See [Targeting Specs](https://developers.facebook.com/docs/marketing-api/targeting-specs). If you use this placement you must also select `feed` as a position and for `device_platforms` select `mobile` since Instant Articles is for mobile only. - **Facebook OLow10/6/2016
2.7.1This is a new major release, which diverges in behavior from the previous one. **Please review these changes:** - **New Daily Budget Limits**: We changed the logic around ads delivery which impacts the interpretation of the daily ad budget limits. Starting from v2.7, you may be charged up to **125%** of your daily budget. For example, if your daily budget is $10, you may be charged up to $12.50. However, your weekly spend will NOT exceed 7 times the daily amount, or $70 in this example. We will Low7/14/2016
2.6.2.01. Allowing version to be passed in api call 2. Fixes to objects for batch call Low7/8/2016
2.6.21. Setup.py is the file which installs facebookads packages. Adding adobjects.helpers module to this. 2. Abstract crud updated for api instance to flow Low5/18/2016
2.6.11. Setup.py is the file which installs facebookads packages. Adding adobjects module to this. 2. api.py method open_files updated to be compatible with PY 2.6 Low4/13/2016
2.6.01. The new SDK is an improved SDK version, autogenerated using our Marketing API. Hence there is greater coverage to features provided by our API. 2. The adobjects folder contains separate classes for every ad object and possible CRUD operation on these objects can be based on the presence/absence of api_create, api_get, api_update and api_delete methods. 3. This SDK also contains all the breaking changes for v2.6 API version and is compatible with the manual (legacy) SDK. The legacy branch conLow4/12/2016
2.5.11. status is not a valid field under ad objects. It needs to be passed as a parameter during create/update calls 2. Fixing duplicaiton of Aggregation fields on AdsPixel class 3. Adding back the AdGroupPreview equivalent class and reaming AdPreview to GeneratePreview Low10/20/2015
2.5.0- Renaming across the API to point to campaigns, adset and ad instead of older adcampaigngroup, adcampaign and adgroup. - Breaking changes in [change log](https://developers.facebook.com/docs/marketing-api/changelog) incorporated - Lead Ads has been released, and the SDK now supports this API. - Minimum Budgets endpoint support - Labels API support incorporated Low10/8/2015
2.4.2- Fixed a bug with the AsyncJob object - Added support for adcreativesbylabels for Labels API Low7/29/2015
2.4.1- New module was not defined in setup.py for pypi Low7/16/2015
2.4.0- Now supports API v2.4 - facebookads.**version** is now available, thanks @m-vdb ! - Encoding for other language now properly handled, thanks @m-vdb ! - Added new fields for OptimizationGoal, BillingEvent, and DPA - Removed HasObjective mixin from AdGroup - Async support for reportstats and insights - get_product_sets now added to ProductCatalog, thanks @lucascosta Low7/16/2015
2.3.3- We added hourly stats to insights. - Improved error message display slightly - Bug fixes Low5/27/2015
2.3.2- Added call_to_action_clicks to insights - `build_objects_from_response` now checks if the `data` object in the response is a `list` - Added `RateCard` subclass to `AdAccount` - `app_id` and `app_secret` are no longer required in `FacebookAdsApi.init` - `lifetime_impressions` added to `AdSet` - `creative_sequence` now supported - `get_ad_conversion_pixels` added for `AdAccount` Low5/18/2015
2.3.1- This release fixes an issue where 2.3.0 could not be pulled from pypi Low3/25/2015
2.3.0- Video chunk uploader is now available - New insights object is available in the SDK - Fixed uploading zip files - Added remote_save to the SDK (deprecated save, to be removed next major release) - Added is_autobid to AdSet Low3/25/2015
2.2.7- Fixed instantiation of Lookalike Audience object - Added test ensuring all ACO objects can have the ID field Low3/11/2015
2.2.6Fixed a few minor issues with new DPA Objects - id field missing in ProductAudience - Fixed add_user/remove_user calls in ProductCatalog Low3/3/2015
2.2.5- Added Business object - Added DPA objects - Added rf_prediction_id to AdSet - Objects that can archive will POST status as delete instead of issuing a DELETE request Low2/17/2015
2.2.4- Added more integration tests - Delete remote objects after tests run - Fixed get_ad_images() failing - Added CanValidate mixin for remote_validate() feature - Fix printing nested AbstractObjects Low1/24/2015
2.2.3- Added thumbnail_url to AdCreative object - Added AutoComplete object - Added get_by_ids() method e.g. `AdSet.get_by_ids(ids=[123123,123123])` - Added the ability to define default account ID e.g. `FacebookAdsApi.set_default_account_id('act_123123')` - Python 3 and 2.6 dict comprehension compatibility (thanks @agriffis!) - Failing tests fixed - Fixed bug with ABSOLUTE_OCPM not supplying API with allcaps (as speced) Low12/12/2014
2.2.2- Calling `del object['key']` will correctly update the change history, thus removing the key as a parameter in API request. - `CanArchive` mixin has been added which allows campaigns, ad sets, and ad groups to be archived by calling `remote_archive()` - Error handling has been much improved ``` try: account = AdAccount('invalid-account-id') account.remote_read() except FacebookRequestError, e: print e.api_error_message() print e.api_error_code() ``` Check the exceptions.FaceboLow11/21/2014
2.2.1- You can now optionally specify an access token inside your config.json to make it easier to run tests. - Object collections are friendlier to native python functions: `print adaccount_object` or `print len(adaccount.get_ad_groups())` will behave as expected and not spit out random strings - You can also now call .total() on object collections: `print adaccount.get_ad_groups().total()` will output total number of ad groups for that account (not just what's in the array) - Pagination has been twLow11/7/2014
2.2.0- Added changes for Custom Audiences - Added support for Reach Frequency Predictions - Some code organization Low10/30/2014

Dependencies & License Audit

Loading dependencies...

Similar Packages

pre-commitA framework for managing and maintaining multi-language pre-commit hooks.v4.6.0
azure-core-tracing-opentelemetryMicrosoft Azure Azure Core OpenTelemetry plugin Library for Pythonazure-template_0.1.0b6187637
spdx-toolsSPDX parser and tools.0.8.5
lacesDjango components that know how to render themselves.0.1.2
django-tasksA backport of Django's built in Tasks framework0.12.0