Getting started with FastAPI on a Raspberry Pi

First published:

Last Edited:

Number of edits:

<p>Recommended operating system: <strong>Ubuntu Server 20.4</strong>. </p> <p>After loading the operating system on an SSD card, booting, and logging into it, the most important is to perform an update to the latest libraries following the steps that will appear on screen:</p> <pre class="codehilite"><code class="language-bash">sudo apt full-update </code></pre> <p><code>apt-get</code> is the package manager of Ubuntu, and the command <code>apt</code> is a convenient way of using it. <code>sudo</code> instructs the command-line to run the command as the "Super User", a user that can make changes to the entire computer. Use <code>sudo</code> with care. </p> <p>In order to get started with Python, we must install some libraries:</p> <pre class="codehilite"><code class="language-bash">sudo apt install python3 python3-pip python3-venv </code></pre> <p>This will install Python (most likely it is already installed, but just in case), the Python package manager <code>pip</code>, and the <code>venv</code> module to create virtual environments. </p> <p>See: <a class="wikilink" href="/difference_conda_environment_and_virtual_environment_in_pyhon/">Difference conda environment and virtual environment in Pyhon</a></p> <p>Once it is ready, we can proceed to creating a virtual environment, for example:</p> <pre class="codehilite"><code class="language-bash">python3 -m venv fastapi </code></pre> <p>The <code>-m venv</code> is a quick way of using a Python module directly from the command line. To activate the virtual environment we must run:</p> <pre class="codehilite"><code class="language-bash">source fastapi/bin/activate </code></pre> <p>To deactivate the virtual environment:</p> <pre class="codehilite"><code class="language-bash">deactivate </code></pre> <p>We can see that it worked because there'll be a <code>(fastapi)</code> string at the beginning of the command line. </p> <p>Before installing FastAPI, we will need to install <code>cargo</code>, the package manager of Rust, another programming language. </p> <pre class="codehilite"><code class="language-bash">sudo apt install cargo </code></pre> <p>Now we can install the python packages that are needed. It is important to install these packages inside a virtual environment, for example by first activating fastapi as we did earlier. </p> <pre class="codehilite"><code class="language-bash">pip install fastapi[all] </code></pre> <p>It is important to note that all the commands that involve <code>apt</code> are acting at a computer level. Cargo is installed on the computer, not within the virtual environment, for example. Any changes to it will have impact on all the virtual environments that rely on it. </p> <p>To start a FastAPI program and make it accessible through the network, from an outside computer or device:</p> <pre class="codehilite"><code class="language-bash">uvicorn main:app --reload --host 0.0.0.0 </code></pre>

Backlinks

These are the other notes that link to this one.

Nothing links here, how did you reach this page then?

Comment

Share your thoughts on this note. Comments are not public, they are messages sent directly to my inbox.
Aquiles Carattino
Aquiles Carattino
This note you are reading is part of my digital garden. Follow the links to learn more, and remember that these notes evolve over time. After all, this website is not a blog.
© 2026 Aquiles Carattino
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
Privacy Policy