Skip to main content

farcaster-py is a Python SDK for the Farcaster Protocol

Project description

farcaster-py

Build status Python Version Dependencies Status Code style: black Security: bandit Pre-commit Semantic Versions License Coverage Report chat

farcaster-py is a modern Python SDK for the Farcaster protocol

Full documentation can be found here

Installation

pip install -U farcaster

or install with Poetry:

poetry add farcaster

Usage

This SDK leverages the Warpcast API. Warpcast is one of many Farcaster clients. As more APIs are created and hosted by different clients, these will be added to the SDK.

To use the Warpcast API you need to have a Farcaster account. We will use the mnemonic or private key of the Farcaster custody account (not your main wallet) to connect to the API.

First, save your Farcaster mnemonic or private key to a .env file. Now you can initialize the client, and automatically connect to the Farcaster API!

import os
from farcaster import Warpcast
from dotenv import load_dotenv # can be installed with `pip install python-dotenv`

load_dotenv()

client = Warpcast(mnemonic=os.environ.get("<MNEMONIC_ENV_VAR>"))

print(client.get_healthcheck())

Examples

Get a cast

response = client.get_cast("0x321712dc8eccc5d2be38e38c1ef0c8916c49949a80ffe20ec5752bb23ea4d86f")
print(response.cast.author.username) # "dwr"

Publish a cast

response = client.post_cast(text="Hello world!")
print(response.cast.hash) # "0x...."

Get a user by username

user = client.get_user_by_username("mason")
print(user.username) # "mason"

Get a user's followers using a fid (farcaster ID)

response = client.get_followers(fid=50)
print(response.users) # [user1, user2, user3]

Stream recent casts

for cast in client.stream_casts():
    if cast:
        print(cast.text) # "Hello world!"

Get users who recently joined Farcaster

response = client.get_recent_users()
print(response.users) # [user1, user2, user3]

Get your own user object

user = client.get_me()
print(user.username) # "you"

Recast a cast

response = client.recast("0x....")
print(response.cast.hash) # "0x...."

and many, many more things. The full specification can be found on the Reference page.

Please note that support for Python 3.7 is no longer actively maintained. Python 3.8, 3.9, or 3.10 are recommended.

🛡 License

License

This project is licensed under the terms of the MIT license. See LICENSE for more details.

Disclaimer

This code is being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of the code. It has not been audited and as such there can be no assurance it will work as intended, and users may experience delays, failures, errors, omissions or loss of transmitted information. Nothing in this repo should be construed as investment advice or legal advice for any particular facts or circumstances and is not meant to replace competent counsel. It is strongly advised for you to contact a reputable attorney in your jurisdiction for any questions or concerns with respect thereto. a16z is not liable for any use of the foregoing, and users should proceed with caution and use at their own risk. See our disclosures page for more info.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

farcaster-0.7.11.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

farcaster-0.7.11-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file farcaster-0.7.11.tar.gz.

File metadata

  • Download URL: farcaster-0.7.11.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.10.9 Linux/6.2.0-1015-azure

File hashes

Hashes for farcaster-0.7.11.tar.gz
Algorithm Hash digest
SHA256 45746e3d1718bed6dd231764da0ad5805f643a23e1a4a07907a8970c4e28e6bf
MD5 9b78fc9a6c438062f521478865f32331
BLAKE2b-256 1966f7048e65f725496a56276d028d7471f1ffdc753ee823f803dc72a16da31e

See more details on using hashes here.

File details

Details for the file farcaster-0.7.11-py3-none-any.whl.

File metadata

  • Download URL: farcaster-0.7.11-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.10.9 Linux/6.2.0-1015-azure

File hashes

Hashes for farcaster-0.7.11-py3-none-any.whl
Algorithm Hash digest
SHA256 b830b8f7683fd01a8d828cac71c59bc3410aa7758c73bdfa391610f9f2bb1517
MD5 72aa7a2c061d8c83688909ae02cb550f
BLAKE2b-256 f447445fff8f34d85f625db4f1b8f0fdd8a58d2817fc70f4cba524c722956383

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page