Package: farcaster-py
farcaster-pyPython bindings forFarcaster.The bindings are based on the protocol implementation byHubblewhich can be found at@farcaster/hub-monorepo.farcaster-py makes use of the gRPC interface exposed by farcaster hubs.Quick startUntil there is a proper pipy package, a quick and easy way to play around:pip install farcaster-pyCreate.envwith the following entries:FARCASTER_HUB="farcaster_hub:grpc_port"

OP_ETH_PROVIDER="OP provider endpoint"

APP_FID="application fid"
APP_PRIVATE_KEY="application private key"

USER_FID="User fid"
USER_PRIVATE_KEY="User private key" 
APP_SIGNER_KEY="You have to create a signer first. Use examples/approve_new_signer.py."Download the examples found inexamples/and trypython ./get_user_casts.pyInternalsI have tried to both follow Farcaster's conventions and naming, but also provide a pythonic API that make sense to use without requiring deep knowledge of the underlying protocols.HubServceTheHubServiceclass uses Hubble's gRPC interface to interact with hubs. Most of the gRPC described inthe protocol specificationis avalable through farcaster-py.Example:fromfarcaster.HubServiceimportHubServicehub=HubService(hub_address,use_async=False)casts=hub.GetCastsByFid(fid=280)forcastincasts.messages:print(cast)Secure connections have not been implemented.99% of the gRPC API is read-only: You get data from the hubs. The only (I think) call that allows you to change the global state isHubService.SubmitMessage(Message) -> Message. (see next section)MessageTheMessage.MessageBuilderclass offers three types of methods:The initializer that creates a newMessageBuilderwith specific characteristics (hash scheme, signature scheme and the user's private key)Methods likeMessageBuilder.link.add(...)andMessage.link.remove(...)that return aMessageDataprotobuf.MessageBuilder.message(self, data: MessageData)that getsMessageDataand hashes, signs, etc and returns aMessageprotobuf object ready to be used byHubService.SubmitMessage(Message)Example:fromfarcaster.HubServiceimportHubServicefromfarcaster.fcproto.message_pb2importSignatureScheme,HashScheme,EmbedfromfarcasterimportMessagehub_address='....'app_signer='....'user_fid='....'hub=HubService(hub_address,use_async=False)message_builder=Message.MessageBuilder(HashScheme.HASH_SCHEME_BLAKE3,SignatureScheme.SIGNATURE_SCHEME_ED25519,bytes.fromhex(app_signer[2:]))data=message_builder.cast.add(fid=user_fid,text="Hello, world!")msg=message_builder.message(data)ret=hub.SubmitMessage(msg)SignerTheSignerclass provides a simple interface to creating signers.To create a signer, you need:Fid and corresponding private key of the user that will approve the signer.The fid and private key of the application that will create and use the signer.Once you have this data, you create a newSigner, and useapprove_signer()to submit the on-chain tx:# snippet from examples/approve_new_signer.pys=Signer(op_eth_provider,user_fid,user_key,app_fid,app_key)tx_hash=s.approve_signer()signer_private_key=s.keysigner_public_key=s.signer_pub()Updating protobuf shemasIf you are installing from source, you usegenerate_proto.sh <HUBBLE VERSION>to generate the corresponding protbuffer Python code../generate_proto.sh1.5.6git:main*
xschemas/
xschemas/gossip.proto
xschemas/hub_event.proto
xschemas/hub_state.proto
xschemas/job.proto
xschemas/message.proto
xschemas/onchain_event.proto
xschemas/request_response.proto
xschemas/rpc.proto
xschemas/sync_trie.proto
xschemas/username_proof.proto

Protobufschemasparsed.VersioningEventually, farcaster-py will follow the version numbers of farcaster protocol buffers (when/if they become a separate package).Until then, I'll keep version numbers low (0.0.x) and update them manually.Licensefarcaster-pyis distributed under theMIT License.CreditsThis package was created and is maintained by@vrypan.eth.An older repository, calledhub_pyhas been a valuable source while building the initial version offarcaster-py.