Coding Terminology Pt 2
Project Framework Environment
After finishing your project, you might want others to easily download and run your project. However, other users likely won’t have the necessary packages installed. To help them quickly set up the environment, most project frameworks provide a specific file listing all dependencies and an associated installation command (shown in the table below).
Framework/Language | Dependency File | Installation Command |
---|---|---|
NextJS (JavaScript) | package.json | npm install |
Python | requirements.txt | pip install -r requirements.txt |
Virtual Environment (Python)
A Python virtual environment is like a separate “sandbox” or isolated workspace on your computer where you can install Python packages without affecting other projects. This ensures that each project has its own specific set of dependencies (software packages).
Why is it important?
- Avoid conflicts: Different projects may require different versions of the same package.
- Easy sharing: Others can recreate your exact environment effortlessly.
- Organization: Helps keep projects tidy and manageable.
In Python, you can set up a virtual environment with the following commands:
Action | macOS/Linux Command | Windows Command |
---|---|---|
Create a virtual environment | python -m venv myenv | python -m venv myenv |
Activate the virtual environment | source myenv/bin/activate | myenv\Scripts\activate |
Install packages (e.g., numpy) | pip install numpy | pip install numpy |
Deactivate the virtual environment | deactivate | deactivate |
Delete the virtual environment (optional) | rm -rf myenv | rmdir /s /q myenv (PowerShell) |
APIs (Application Programming Interfaces)
Think of an API (Application Programming Interface) like a customer service counter at a restaurant. You (the customer) place an order (input), and after a short wait, the counter hands you your food (output). You don’t need to know what’s happening in the kitchen—how the chefs prepare the food, what ingredients they use, or the exact process. You just make a request and get a result.
Just like ordering at a counter, you don’t need to know how the API fetches that data—you just get the info you need!
API | Request Description | Example Request (Code) | Example Output |
---|---|---|---|
Google Maps API | Get driving directions from SF to Mountain View. | fetch('https://maps.googleapis.com/maps/api/directions/json?origin=SF&destination=MV&key=YOUR_API_KEY') | { "distance": "39 miles", "duration": "45 mins" } |
OpenAI API | Generate a summary of a book or topic. | openai.chat.completions.create({model:"gpt-3.5-turbo",messages:[{role:"user",content:"Summarize book."}]}) | "The Fountainhead explores individualism through architect Howard Roark..." |
Supabase API | Retrieve specific user information from database. | supabase.from('users').select('username,email').eq('id',123) | { "id":123, "username":"karena123", "email":"karena@example.com" } |
Stripe API | Create a payment intent to charge a customer. | stripe.paymentIntents.create({amount:2000,currency:"usd",customer:"cus_456"}) | { "id": "pi_1KuXyz...", "amount":2000, "currency":"usd", "status":"succeeded" } |
In your projects, you will likely be calling an API from your application. Therefore, it’s good to know at a high-level what an API is and how it works.
References
.ENV File
A .env file is like your secret vault. It stores environment variables, which include configuration settings like API keys and database credentials. This file helps keep sensitive information secure and makes it easier to manage settings across different environments (development, testing, production).
An example .env file might look like:
OPENAI_API_KEY=sk-proj-1234567890SUPABASE_URL=https://example.comSUPABASE_KEY=1234567890
Note, those are just example keys and you should not use them in your projects.
Version Control (like Github)
Version control systems, such as Git, help you track changes to your code and collaborate with others. Github is a popular platform that hosts Git repositories, making it easier to manage and share your projects. A deeper dive into how to use Github is covered in the next section on Github Basics section.