Skip to main content

A high performance FastAPI-based message consumer framework for PubSub

Project description

FastPubSub

A high performance FastAPI-based message consumer framework for Google PubSub


Documentation: https://github.com/matheusvnm/fastpubsub/wiki

Source Code: https://github.com/matheusvnm/fastpubsub


Features

FastPubSub is a modern, high-performance framework for building modern applications that process event messages on Google PubSub. It combines the standard PubSub Python SDK with FastAPI, Pydantic and Uvicorn to provide an easy-to-use development experience.

The key features are:

  • Fast: FastPubSub is (unironically) fast. It's built on top of FastAPI, uvicorn and Google PubSub Python SDK for maximum performance.
  • Intuitive: It is designed to be intuitive and easy to use, even for beginners.
  • Typed: Provides a great editor support and less time reading docs.
  • Robust: Get production-ready code with sensible default values helping you avoid common pitfalls.
  • Asynchronous: It is built on top of anyio, which allows it to run on top of either asyncio or trio.
  • Batteries Included: Provides its own CLI and other widely used tools such as pydantic for data validation, observability integrations and log contextualization.

Quick Start

Installation

FastPubSub works on Linux, macOS, Windows and most Unix-style operating systems. You can install it with pip as usual:

pip install fastpubsub

Writing your first application

FastPubSub brokers provide convenient function decorators (@broker.subscriber) and methods (broker.publisher) to allow you to delegate the actual process of:

  • Creating Pub/Sub subscriptions to receive and process data from topics.
  • Publishing data to other topics downstream in your message processing pipeline.

These decorators make it easy to specify the processing logic for your consumers and producers, allowing you to focus on the core business logic of your application without worrying about the underlying integration.

Also, Pydantic’s BaseModel class allows you to define messages using a declarative syntax for sending messages downstream, making it easy to specify the fields and types of your messages.

Here is an example Python app using FastPubSub that consumes data from an incoming data stream and outputs two messages to another one:

# basic.py

from pydantic import BaseModel, Field
from fastpubsub import FastPubSub, PubSubBroker, Message
from fastpubsub.logger import logger

class Address(BaseModel):
    street: str = Field(..., examples=["5th Avenue"])
    number: str = Field(..., examples=["1548"])


broker = PubSubBroker(project_id="some-project-id")
app = FastPubSub(broker)

@broker.subscriber(
    alias="my_handler",
    topic_name="in_topic",
    subscription_name="sub_name",
)
async def handle_message(message: Message):
   logger.info(f"The message {message.id} is processed.")
   await broker.publish(topic_name="out_topic", data="Hi!")

   address = Address(street="Av. Flores", number="213")
   await broker.publish(topic_name="out_topic", data=address)

Running the application

Before running the command make sure to set one of the variables (mutually exclusive):

  1. Running PubSub on Cloud: The environment variable GOOGLE_APPLICATION_CREDENTIALS with the path of the service-account on your system.
  2. Running PubSub Emulator: The environment variable PUBSUB_EMULATOR_HOST with host:port of your local PubSub emulator.

After that, the application can be started using built-in FastPubSub CLI which is a core part of the framework.

To run the service, use the FastPubSub embedded CLI. Just execute the command run and pass the module (in this case, the file where the app implementation is located) and the app symbol to the command.

fastpubsub run basic:app

After running the command, you should see the following output:

2025-10-13 15:23:59,550 | INFO     | 97527:133552019097408 | runner:run:55 | FastPubSub app starting...
2025-10-13 15:23:59,696 | INFO     | 97527:133552019097408 | tasks:start:74 | The handle_message handler is waiting for messages.

Also, FastPubSub provides you with a great hot reload feature to improve your development experience

fastpubsub run basic:app --reload

And multiprocessing horizontal scaling feature as well:

fastpubsub run basic:app --workers 3

You can learn more about CLI's features here.

Contact

Feel free to get in touch by:

Sending a email at sandro-matheus@hotmail.com.

Sending a message on my linkedin.

License

This project is licensed under the terms of the Apache 2.0 license.

Download files

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

Source Distribution

fastpubsub-0.2.0.tar.gz (331.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastpubsub-0.2.0-py3-none-any.whl (41.0 kB view details)

Uploaded Python 3

File details

Details for the file fastpubsub-0.2.0.tar.gz.

File metadata

  • Download URL: fastpubsub-0.2.0.tar.gz
  • Upload date:
  • Size: 331.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for fastpubsub-0.2.0.tar.gz
Algorithm Hash digest
SHA256 99a9e2f1fc7a797fa276e57486ed9ddc4d3df2c1cf5379460714eb8daf51e540
MD5 bc3f90217ded8fc69d7fecb28a732a8b
BLAKE2b-256 1e2363682ec747a1229604270ac97c0d8cf26dd30eb8d5f525f4a80173dd147f

See more details on using hashes here.

File details

Details for the file fastpubsub-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: fastpubsub-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 41.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for fastpubsub-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae6f1712127029212fcb5d2f24ab353c4cfa3352e8a129cdc9d5a2ed571cd372
MD5 a09c311a7c2fb2dc56ab7dcb3d7a2e66
BLAKE2b-256 d1af9f99dda4954e0e735697f4f32421de1a8cb1143c9d242dc995f8163e0dca

See more details on using hashes here.

Supported by

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