Author: Lawrence Li
-
The first step for local project execution is to create a virtual environment. This is a best practice for developing, testing and running multiple Python applications on a single system. There are many explanatiosn online for the benefits of virtual environments.
-
There are several approaches to creating a venv. I recommend setting up the environment using PyCharm's built in wizard/tools.
-
Activate the virtual environment. You can do this in PyCharm by opening a terminal window inside PyCharm. There should be a terminal tab at the bottom of the PyCharm window.
-
In the terminal, type
pip install -r requirements.txt
This will install the necessary Python packages. -
You can now execute the application by using the
run
feature in PyCharm or directly from the terminal prompt line by typingpython main.py
-
You will see an initialization (logging) messages followed by the message
Uvicorn running on http://0.0.0.0:8012 (Press CTRL+C to quit)
- Click on
http://0.0.0.0:8012
link to open in the browser. You can also copy and past the link. You will see something of the form
Simple Execution |
- Accessing the URL
http://0.0.0.0:8012/docs
will navigate to the OpenAPI page/documentation for the application.
- Create a new GitHub project and clone the project.
- Change the name of the author in
README.md
- Copy the code from this example into the directory for the project.
- Follow the steps for:
- Creating a virtual environment for your version of the project.
pip
installingrequirements.txt
- Executing and accessing the application.
- In
main.py,
modify the linereturn {"message": f"Hello {name}"}
to return a message of the formreturn {"message": f"Awesome cloud developer dff9 says Hello {name}"}
Replace my uni with yours. - Rerun the application to test.
Note:
- The default behavior for virtual environment creation is to create the venv in the current folder/project.
- You can create the venv anywhere on the file system.
- You do not want to venv pushed to GitHub. So, if the venv is inside the project, remove the directory from the set of files that will be pushed. The easiest way is to add to a .gitignore file.
-
Commit and push your application to the GitHub repository.
-
You have completed the first part of the initial assignment.