Skip to content

Do we have any official documentation about Websockets? #104

Closed

Description

@thongtrump

We can implement WebSocket in FastAPI like this:

from fastapi import FastAPI, WebSocket

app = FastAPI()
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
    await websocket.accept()
    while True:
        data = await websocket.receive_text()
        await websocket.send_text(f"Message text was: {data}")

So, as the title suggests, is there an official way to handle WebSockets in PyNest API?

I tried import WebSocket from nest.core but there's no definition for it.

Activity

  1. ItayTheDar commented on Mar 15, 2025

    @ItayTheDar
    Contributor

    Hi @thongtr-dev

    Thanks for bringing this up. As of now, there’s no official WebSocket support in PyNest. We totally get how handy it can be, and it’s definitely on our roadmap. If you have any ideas or rough proof-of-concept code, feel free to share! We’d love to hear your thoughts on what a clean, developer-friendly API might look like.

  2. thongtrump commented on Apr 4, 2025

    @thongtrump
    Author

    Thank you for your comment @ItayTheDar .

    I initially closed the issue yesterday, as I was considering rearchitecting our app to use only FastAPI instead of continuing with PyNest. However, since we've already invested significant effort into building with PyNest, a full rearchitecture might be too much work at this stage.

    I've reopened the issue for further discussion. Our team is developing an app that requires a WebSocket-like connection to an endpoint to fetch real-time data from background tasks. If PyNest doesn’t support WebSockets, polling might be our only option. Do you have any suggestions on how we can work around this?

  3. thongtrump commented on Apr 4, 2025

    @thongtrump
    Author

    Just write down another comment here that I found something called Server-sent Events, which might benefit our team. Does PyNest support Server-sent Events?

  4. ItayTheDar commented on Apr 6, 2025

    @ItayTheDar
    Contributor

    Hi @thongtr-dev

    Why don't we just implement support in Web Sockets? It shouldn't be a huge effort and if you and your team can benefit from it, then as the maintainer of pynest this is something I want to support.

    But for that, I need to have better understand of your use case. could you share here or in private (itay2803@gmail.com) your use case and your needs (why do you need web sockets, how this is integrate with the rest of your app and more)

    Thank you!

  5. thongtrump commented on Apr 11, 2025

    @thongtrump
    Author

    Hi @ItayTheDar,

    We’re building a system that interacts with a third-party API to handle creation tasks. Since the API doesn’t provide a callback or status endpoint to indicate when the creation is complete, we’ve moved the task to the background using Redis and Dramatiq.

    When a user initiates creation, they’re redirected to a listing page where items show badges indicating whether they’re ready to view/edit or still pending. This is where we think WebSocket support would be especially useful—to push real-time status updates for each item’s creation progress.

  6. ItayTheDar commented on May 9, 2026

    @ItayTheDar
    Contributor

    PyNest 0.5.0 comes with built-in WebSocket support.

    The release includes first-class gateway APIs such as @WebSocketGateway, @SubscribeMessage, MessageBody, ConnectedSocket, lifecycle hooks, and official documentation for the recommended PyNest WebSocket pattern.

  7. ItayTheDar commented on Jul 28, 2026

    @ItayTheDar
    Contributor

    Resolved by #127 and released in PyNest v0.5.0. PyNest now provides native WebSocket gateways with @WebSocketGateway, @SubscribeMessage, MessageBody, ConnectedSocket, dependency injection, guards, rooms/broadcasting, CLI scaffolding, tests, and official documentation.

    Closing as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions