Skip to content

Conversation

martinky24
Copy link

@martinky24 martinky24 commented Jul 23, 2023

The note at the top of the websockets doc page implies FastAPI has an implicit dependency on the websockets package. As a result, I mistakenly spent quite a bit of time reading the websockets docs, thinking it would help me work with the fastapi.websocket functionality.

FastAPI itself instead relies solely on the Starlette WebSockets implementation, which has an entirely different API.

This MR attempts to update the documentation to make it more explicit WHY websockets is required. It's not a fastapi dependency by any means, but a uvicorn dependency (and the tutorial makes use of uvicorn)

@tiangolo
Copy link
Member

📝 Docs preview for commit 9944f99 at: https://64bc7cd6a11600468968067f--fastapi.netlify.app

@martinky24 martinky24 force-pushed the km/update-docs-around-websockets branch from 9944f99 to 9df46e2 Compare July 24, 2023 13:48
@tiangolo
Copy link
Member

📝 Docs preview for commit 9df46e2 at: https://64be82424e1061008bd78812--fastapi.netlify.app

@tiangolo tiangolo added the docs Documentation about how to use FastAPI label Oct 2, 2023
@alejsdev alejsdev added the p4 label Jan 16, 2024
Copy link

@codespearhead codespearhead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Uvicorn is even invoked a few paragraphs down in the same tutorial despite not being installed.

https://github.com/tiangolo/fastapi/blob/62705820d60365cdb4b05010c103c07020190e99/docs/en/docs/advanced/websockets.md?plain=1#L75

Copy link
Contributor

Copy link
Contributor

@YuriiMotov YuriiMotov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text of this section was updated since the time this PR was opened.
But it still looks a bit incomplete: it's said that we need to create environment and install websockets, but it's said nothing about installing FastAPI itself.

How about the following?

## Install `uvicorn` and `websockets`

Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and install `fastapi`, `uvicorn` and `websockets`:

<div class="termy">

```console
$ pip install fastapi uvicorn websockets

---> 100%
```

</div>

/// tip 

If you install FastAPI using `pip install fastapi[standard]`, you don't need to install websockets separately - it will be installed by default.

///

/// note

You will not interact with `websockets` package directly, it's required for Uvicorn to handle the websocket protocol.

///

Copy link
Contributor

As this PR has been waiting for the original user for a while but seems to be inactive, it's now going to be closed. But if there's anyone interested, feel free to create a new PR.

@github-actions github-actions bot closed this Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation about how to use FastAPI p4 waiting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants