farcaster-py is a Python SDK for the Farcaster Protocol
Reason this release was yanked:
Deprecated
Project description
farcaster-py
Installation
pip install -U farcaster
or install with Poetry:
poetry add farcaster
Usage
To use the Farcaster API you need to generate an access token. Here is one way to do that:
First install eth-account and dotenv:
pip install eth-account python-dotenv # Or 'poetry add eth-account python-dotenv'
Then you can use a script like this to generate the access token. Note that you can increase the expiration date of the token if you don't want to worry about rotation.
import time
import os
from farcaster import MerkleApiClient
from eth_account.account import Account
from dotenv import load_dotenv
load_dotenv()
Account.enable_unaudited_hdwallet_features()
ETH_ACCOUNT_SIGNER = Account.from_mnemonic(os.environ.get("<MNEMONIC_ENV_VAR>"))
client = MerkleApiClient(wallet=ETH_ACCOUNT_SIGNER)
expiry_ms = int(time.time() + 600)*1000 # This auth token will be valid for 10 minutes. You can increase this up to 1 year
access_token = client.create_new_auth_token(expires_at=expiry_ms)
print(access_token) # "MK-...."
Save the auth token somewhere like a .env
file in your working directory.
From now on you can initialize your client like this:
from farcaster import MerkleApiClient
from dotenv import load_dotenv
load_dotenv()
client = MerkleApiClient(access_token=os.environ.get("<AUTH_ENV_VAR>"))
print(client.get_healthcheck())
Examples
Get a cast
response = fcc.get_cast("0x321712dc8eccc5d2be38e38c1ef0c8916c49949a80ffe20ec5752bb23ea4d86f")
print(response.cast.author.username) # "dwr"
Publish a cast
from farcaster.models import CastsPostRequest
cast_body = CastsPostRequest(text="Hello world!")
response = fcc.post_cast(cast_body)
print(response.cast.hash) # "0x...."
Get a user by username
response = fcc.get_user_by_username("mason")
print(response.user.username) # "mason"
Get a user's followers using a fid (farcaster ID)
response = fcc.get_followers(fid=50)
print(response.users) # [user1, user2, user3]
Get users who recently joined Farcaster
response = fcc.get_recent_users()
print(response.users) # [user1, user2, user3]
Get your own user object
response = fcc.get_me()
print(response.user.username) # "you"
Recast a cast
response = fcc.recast("0x....")
print(response.cast.hash) # "0x...."
and many, many more things. The full specification can be found on the Reference page.
🛡 License
This project is licensed under the terms of the MIT
license. See LICENSE for more details.
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
Hashes for farcaster-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39df4b0091301f3d834a66a4438938cbf1ed73d054ecaeecb2629fa0bc44e1db |
|
MD5 | 11559b254d6fbad16f45827436716407 |
|
BLAKE2b-256 | 1f06a5f5adb16c75cd23ffdfdbbde25183f0649b5b1cbddd135a62b8647e2c5e |