Complete workflow
Start to finish setup
Setting up a new project can feel like a lot. Let's walk through a complete, beginner-friendly setup from start to finish.
New project checklist
Before you start coding, have a clear idea of what your project will do. This helps you choose the right tools and keep focused.
- What problem does this project solve?
- What will it be called?
- What are the main features?
Step 1: Open terminal
The terminal (or command line) is where you'll issue commands to your computer. It might seem scary at first, but it's very powerful.
- On macOS, search for "Terminal".
- On Windows, search for "CMD" or "PowerShell" (PowerShell is generally preferred).
Step 2: Navigate to your projects folder
It's a good practice to keep all your code projects organized in one main folder. This makes them easy to find.
Use the cd command to 'change directory'. For example, if you have a folder called Projects in your home directory:
cd ProjectsProjects folder, create one now! You can use mkdir Projects.Step 3: Create the project
Now, let's make a new folder for your specific project. Give it a descriptive name, like my_first_app.
mkdir my_first_app
cd my_first_appAfter creating it, make sure you cd into your new project folder.
Step 4: Open in VS Code
VS Code is a popular code editor. You can open your new project folder directly from the terminal.
code .The . means "the current directory".
code . doesn't work, make sure you've installed the "Shell Command" in VS Code. Open VS Code, press Ctrl+Shift+P (or Cmd+Shift+P), type "shell command", and select "Install 'code' command in PATH".Step 5: Add packages
Most Python projects rely on external code packages. We use a virtual environment to keep these packages separate for each project.
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activateYou'll see (.venv) appear in your terminal prompt, showing the virtual environment is active. Now, let's install a common package, requests.
pip install requestsStep 6: Test your setup
Let's quickly check if everything is working. Create a new file called main.py in your project folder.
# main.py
import requests
def fetch_data(url):
response = requests.get(url)
response.raise_for_status() # Raise an exception for bad status codes
return response.json()
if __name__ == "__main__":
data = fetch_data("https://jsonplaceholder.typicode.com/todos/1")
print(f"Fetched data: {data['title']}")Run this file from your terminal while inside your project folder:
python main.pyYou should see a message confirming data was fetched.
Step 7: Set up environment variables
Sensitive information, like API keys, should never be directly in your code. Use environment variables instead.
Create a file named .env in your project's root. Add a variable like this:
# .env
API_KEY="your_secret_key_here"Install the python-dotenv package to load these variables:
pip install python-dotenvThen, in your Python code, you can access them:
# main.py (continued)
from dotenv import load_dotenv
import os
load_dotenv()
my_api_key = os.getenv("API_KEY")
print(f"My API Key: {my_api_key}")Step 8: Initialize Git
Git is a version control system. It tracks changes to your code, so you can always go back to a previous version.
git initCreate a .gitignore file to tell Git which files to ignore. You don't want to track your .venv folder or .env file.
# .gitignore
.venv/
.env
__pycache__/Now, add your files and make your first commit.
git add .
git commit -m "Initial project setup"Step 9: Create GitHub repository
GitHub is a platform to store your Git repositories online. This makes it easy to collaborate and back up your code.
- Go to GitHub.com and log in.
- Click the '+' icon in the top right and select "New repository".
- Give it the same name as your local project (e.g.,
my_first_app). - Choose "Public" or "Private" and click "Create repository".
GitHub will give you commands to link your local repository. It usually looks like this:
git remote add origin https://github.com/your_username/your_project_name.git
git branch -M main
git push -u origin mainyour_username and your_project_name with your actual GitHub username and project name.The daily workflow
Once your project is set up, your daily routine will be much simpler.
- Open your terminal.
cdinto your project folder.source .venv/bin/activate(or.\.venv\Scripts\activateon Windows).code .to open VS Code.- Work on your code.
- Regularly
git add .,git commit -m "Your meaningful message", andgit pushto save your changes to GitHub.
Quick reference
- Create project folder:
mkdir project_name && cd project_name - Create virtual environment:
python -m venv .venv - Activate virtual environment:
source .venv/bin/activate(or.\.venv\Scripts\activateon Windows) - Install packages:
pip install package_name - Open in VS Code:
code . - Initialize Git:
git init - Add all files to Git:
git add . - Commit changes:
git commit -m "Message" - Push to GitHub:
git push
Pro tips
- Use clear, descriptive commit messages for Git.
- Commit small, related changes frequently.
- Always activate your virtual environment before installing packages or running code.
- Keep your
.gitignoreup-to-date to avoid committing unnecessary files.
Commands summary
cd your_projects_folder
mkdir your_new_project
cd your_new_project
code .
python -m venv .venv
source .venv/bin/activate
pip install requests python-dotenv
# Create main.py and .env files
git init
# Create .gitignore file
git add .
git commit -m "Initial project setup"
# Create GitHub repo, then:
git remote add origin https://github.com/your_username/your_project.git
git branch -M main
git push -u origin mainWhat's next
Now that you have your project set up, you're ready to start building! Explore different Python libraries, learn more about API interactions, or dive deeper into web development.
The next step is to start writing more code, testing your ideas, and getting comfortable with this workflow.