Python API Development with FastAPI
Python Setup
Mac Install Vscode Setup
In this guide, we'll walk you through installing Python and setting up Visual Studio Code (VS Code) on a Mac. This step-by-step tutorial is designed to help you create a powerful development environment optimized for Python programming with FastAPI.
Installing Python
Begin by visiting the official Python website and navigating to the Downloads section. The site automatically detects your platform and displays the latest compatible version (for example, Python 3.9.6). Any version after 3.7 is fully supported for this guide.
Click the download button to get the installer. Once the download is complete, open the file and follow the installation prompts: click Continue, agree to the license terms, and then click Install. If prompted, enter your password. When you see the confirmation pop-up, Python is successfully installed. Feel free to close the installer and move it to the trash.
Next, launch the Terminal by searching for it in the top search bar.
In the Terminal, verify your Python installation by running:
python3 --version
This command should output the version you installed (e.g., Python 3.9.6), confirming a successful Python 3 installation on your system.
Installing Visual Studio Code
Visual Studio Code (VS Code) is a versatile editor that serves as an Integrated Development Environment (IDE). To install VS Code, follow these steps:
- Search for "VS Code" online to visit the official Microsoft Visual Studio Code page.
- The website will auto-detect your operating system. Click on "Download Mac Universal" to download the installer.
- Open the downloaded installer. If a security warning appears, simply click "Open" to proceed.
After installation, launch VS Code. Initially, VS Code operates as a basic text editor, but its functionality can be extended using powerful extensions.
Last login: Sat Aug 14 16:16:18 on ttys000
My-MacBook-Pro:~ user$ python3 --version
To enhance VS Code for Python development:
- Click the Extensions icon (depicted as blocks or squares) in the sidebar.
- Search for "Python" and install the extension provided by Microsoft. This extension delivers valuable features such as linting, IntelliSense, and debugging capabilities.
Setting Up Your Project Folder
Once both Python and VS Code are ready, it's time to set up your project folder:
- In VS Code, choose "Open Folder" from the File menu.
- Navigate to your desired directory (for example, inside your Documents folder), and create a new folder named "FastAPI" to store your project files.
- Open the "FastAPI" folder in VS Code. Initially, the folder will be empty, ready for your project.
Inside the folder, right-click and choose "New File." Name the file "main.py" and press Enter. When you create the file, the Python extension activates and automatically selects a Python interpreter. If you have multiple Python versions installed, ensure that the correct interpreter (preferably Python 3.9.6) is selected.
If you need to change the interpreter, open the Command Palette from the View menu and choose "Python: Select Interpreter." This allows you to select or manually specify your desired Python version.
Note
On macOS, the Python executable is not named python.exe. If you need to override the default, locate the appropriate Python installation on your system.
Final Steps
With your system configured, your development environment is now ready for coding. In the future, simply reopen VS Code and load your project folder (e.g., "FastAPI") to continue working seamlessly.
Happy coding!
Watch Video
Watch video content