A wrapper for the facebook-sdk which provides an ergonomic way to manage common interactions using the facebook-sdk
Project description
PyFB-kit
A Python wrapper for the Facebook Graph API that provides convenient abstractions for managing and moderating Facebook pages and comments.
Installation
Install the package using pip:
pip install pyfb-kit
Or using uv (recommended):
uv add pyfb-kit
Prerequisites
Before using this library, you need to obtain a long-lived user access token with the appropriate permissions:
- Create a Facebook developer application at developers.facebook.com/apps
- Add the following permissions to your application:
pages_manage_engagementpages_read_engagementpages_read_user_contentpages_show_list
- Generate a short-lived user access token via the Graph API Explorer with the above permissions
- Exchange it for a long-lived token (valid for up to 60 days) using the following request:
import requests
params = {
"grant_type": "fb_exchange_token",
"client_id": "<YOUR_APP_ID>",
"fb_exchange_token": "<SHORT_LIVED_TOKEN>",
"client_secret": "<YOUR_APP_SECRET>",
}
response = requests.get("https://graph.facebook.com/v24.0/oauth/access_token", params=params)
long_lived_token = response.json()["access_token"]
Usage
Basic Setup
from pyfb_kit import Client, Account, Post, Comment
# Initialize the client with your user access token
client = Client(user_access_token="your_long_lived_token_here")
Managing Accounts
Retrieve all Facebook pages associated with your account:
# Get all accessible accounts/pages
accounts = client.get_accounts()
# Print account information
for account in accounts:
print(f"Page Name: {account.name}, ID: {account.id}")
Working with Posts
Fetch posts from a specific page:
# Get posts from a specific account
first_account = accounts[0]
posts = client.get_posts(first_account)
# Print post information
for post in posts:
print(f"Post ID: {post.id}, Message: {post.message[:50]}...")
Comment Management
Interact with comments on posts:
# Get comments from a specific post
first_post = posts[0]
comments = client.get_comments(first_account, first_post)
# Print comment information
for comment in comments:
print(f"Comment by {comment.from_info.name}: {comment.message[:50]}...")
# Post a new comment on a post
client.put_comment(first_account, first_post, "This is a new comment!")
# Reply to an existing comment
first_comment = comments[0]
client.reply_comment(first_account, first_comment, "Thanks for your comment!")
Advanced Comment Operations
Retrieve replies to a specific comment:
# Get all replies to a specific comment
replies = client.get_comment_replies(first_account, first_comment)
for reply in replies:
print(f"Reply by {reply.from_info.name}: {reply.message[:50]}...")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfb_kit-0.1.1.tar.gz.
File metadata
- Download URL: pyfb_kit-0.1.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53467c046e0b92312f36ea0f3f9dea44822d22198ed443f97862261e03d40e6a
|
|
| MD5 |
52da1d0170d4ab5fca6a686c1feebc0b
|
|
| BLAKE2b-256 |
1335bce1e169c02da1cfcc1cceda2ee0e365bdce88739800002b6cb02b874bbe
|
File details
Details for the file pyfb_kit-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pyfb_kit-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fca205470ab0b442d6a435bdb8b4404fff57e590165c4b79e1b13be93dee728
|
|
| MD5 |
448f4959c392c1fef9decae91f3aae21
|
|
| BLAKE2b-256 |
038758122985b3ffb23136f06a469a3460d9af15a01396db5d1fc176e60dd10d
|