Skip to main content

FastPubSub

A high-performance, asyncio-native framework for Google Cloud Pub/Sub applications.

Quality Checks PyPI Downloads PyPI Supported Python versions


Documentation: https://docs.fastpubsub.dev

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


Features

FastPubSub is a high-performance framework for building applications that process message events on Google Pub/Sub. A compiled core, written in Rust, runs all Pub/Sub network I/O. FastAPI, Pydantic and Uvicorn give it an easy-to-use development experience in Python.

The key features are:

  • Fast: A compiled core runs the streams, the batches and the acknowledgements outside the Python interpreter. It is written in Rust, on Google's official Rust client for Pub/Sub. Your handlers stay plain Python.
  • Intuitive: It is designed to be intuitive and easy to use, even for beginners.
  • Typed: Provides 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 asyncio, which allows it to run on fully asynchronous code.
  • Batteries Included: Provides its own CLI and other widely used tools such as pydantic for data validation and log contextualization.

Quick Start

Installation

FastPubSub has ready wheels for Linux, macOS (arm64) and Windows, for CPython 3.12 and later and for free-threaded Python. You can install it with pip as usual:

pip install fastpubsub

Writing your first application

FastPubSub broker connection provides 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 producers and consumers, 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 one message to another one:

from pydantic import BaseModel, Field

from fastpubsub import FastPubSub, Message, PubSubBroker
from fastpubsub.logger import logger


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

broker = PubSubBroker(project_id="fastpubsub-pubsub-local")
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!")

@app.after_startup
async def publish_initial_message() -> None:
    address = Address(street="Av. Flores", number="213")
    await broker.publish(topic_name="in_topic", data=address)

Running the application

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

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

After that, the application can be started using the built-in FastPubSub CLI which is a core part of the framework. Just execute the command run and pass the module and the app symbol to the command.

fastpubsub run basic:app

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

2026-02-04 21:00:07,469 | INFO     | 88674:8702897216 | runner:run:76 | FastPubSub app starting...
2026-02-04 21:00:07,999 | INFO     | 88674:8702897216 | tasks:start:80 | The handle_message handler is waiting for messages.
2026-02-04 21:00:08,028 | INFO     | 88674:8702897216 | pubsub:publish:248 | Message published for topic projects/fastpubsub-pubsub-local/topics/in_topic with id 17
2026-02-04 21:00:08,094 | INFO     | 88674:8702897216 | e1_01_basic_subscriber:handle_message:25 | The message 1 is processed. | message_id=17 | topic_name=in_topic | subscriber_name=handle_message
2026-02-04 21:00:08,125 | INFO     | 88674:8702897216 | pubsub:publish:248 | Message published for topic projects/fastpubsub-pubsub-local/topics/out_topic with id 18 | message_id=17 | topic_name=in_topic | subscriber_name=handle_message
2026-02-04 21:00:08,125 | INFO     | 88674:8702897216 | tasks:_consume:107 | The message successfully processed. | message_id=17 | topic_name=in_topic | subscriber_name=handle_message

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

We just scratched the surface, but you already get the idea of how the basic structure works. Everything built into FastPubSub is meant to improve the development experience and provide great productivity with high-performance guarantees.

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.

Metadata

Release files for fastpubsub 0.10.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastpubsub 0.10.1
File Size Uploaded Provenance Actions
fastpubsub-0.10.1.tar.gz 47.5 kB Without provenance Details for fastpubsub-0.10.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastpubsub 0.10.1
File Interpreter ABI Platform Actions
fastpubsub-0.10.1-py3-none-any.whl Python 3 none any Details for fastpubsub-0.10.1-py3-none-any.whl

Total release size: 104.8 kB

Release files / fastpubsub-0.10.1.tar.gz

Download URL fastpubsub-0.10.1.tar.gz
Size 47.5 kB
Tags Source
SHA-256 checksum
How to use checksums
70642ada07139ced777866f6b56a6ac4319ab6600280d1c192c69d64334b0eaa
BLAKE2b-256 checksum
How to use checksums
9229d829a10a954ca073d94d8809cc4955cc5dfa3fa05e3ca72d9ab7b1e06a9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fastpubsub-0.10.1-py3-none-any.whl

Download URL fastpubsub-0.10.1-py3-none-any.whl
Size 57.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9b3b876366e900533ec7285e92a5845bae7fc3d3bb3854e729244a7c17a1de4
BLAKE2b-256 checksum
How to use checksums
ed1d2d8b704b46efda970758a1c3b2e6808e921f3fd0b8f808cb16a8f173eb0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for fastpubsub 0.10.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page