1%
OnePercentDev
LearnRoadmapsCommunityPodcastConsult
Log inJoin OnePercentDev
1%
OnePercentDev

Build. Debug. Ship. AI-ready.
Disciplined daily learning for the AI era.

Navigation

  • Learn
  • Roadmaps
  • Community
  • Podcast
  • Consult

Platform

  • Python for AI
  • Create Account
  • Dashboard

Stay Updated

Get notified about new courses and content drops.

© 2026 OnePercentDev. All rights reserved.

Python for AI
Part 30
Lesson 30
21:25

Pip and PyPI: ChatGPT ಗೆ PYTHON ಅಲ್ಲಿ CALL ಮಾಡೋದು ಹೇಗೆ? | Python in Kannada | Part-30

Subscribe on YouTube

Up Next

30 / 58
  • 37:40

    Stop Using requirements.txt! (Master Poetry & UV) 🚀 | Python in Kannada | Part-31

    Part 31

  • 13:15

    Publish Your Own Package to PyPI! 🚀| Python in Kannada | Part-32

    Part 32

View all 58 lessons
View on GitHub

Part 30 — Third-Party Packages & APIs (The Power of pip)

In Part 29, you learned how to import built-in modules (like math or datetime) and how to import your own local files (utils.py).

But the true power of Python isn't just what comes installed on your computer. It is the millions of lines of code written by other developers around the world that you can download and use for free.

What if you want to connect your Python script to ChatGPT? You don't write that complex connection code yourself. You download a library that OpenAI already wrote for you.


1. Module vs Package vs Library

Before we download anything, let's clear up the terminology. Developers often use these words interchangeably, but they have specific meanings:

TermWhat it isReal-World AnalogyExample
ModuleA single .py file containing code.A single tool (e.g., a hammer).my_module.py in our example project
PackageA folder containing multiple modules (usually with an __init__.py file).A toolbox.my_package/ in our example project
LibraryA massive collection of packages published on the internet for others to solve specific problems.An entire hardware store.requests, pandas, openai

Note: When you pip install openai, you are downloading a package from PyPI. People call it a "library" because it is large and solves a specific problem. Both words refer to the same thing — the difference is just how people talk about it. In our project, my_package/ is a local package you wrote. requests is a package someone else wrote and published to PyPI, so people also call it a library.


2. PyPI and pip

Remember Part 4? When we explored how Python is built, we briefly mentioned a tool called **pip** — "Pip Installs Packages." Back then, we just showed you it exists. Now you'll actually use it.

If you want to download a library (like openai), where does it come from?

It comes from PyPI (The Python Package Index) — https://pypi.org. PyPI is the official global database where Python developers upload their open-source libraries. There are over 500,000 packages on PyPI right now.

pip is the tool that connects your terminal to PyPI. It comes pre-installed with Python (as we saw in Part 4), so you don't need to install it separately.

Installing a Library

Open your terminal (Command Prompt / PowerShell / Terminal) and type:

pip install openai

What is happening? pip goes to PyPI.org, finds the library named openai, downloads the code, and installs it onto your computer.


3. Real-World Example: Talking to ChatGPT with Python

Now that you have the openai library installed, you can use it exactly like the built-in modules we used in Part 29.

To do this, you need an API Key from OpenAI. (An API Key is a secret password that proves you are authorized to use their servers).

WARNING: Never hardcode your API key directly in your Python files, and never push it to GitHub! Instead, we store it in a .env file and load it using a library called python-dotenv.

Step 1: Install the libraries

pip install openai python-dotenv

Step 2: Add your key to .env

Open the .env file in the project and paste your key:

OPENAI_API_KEY=sk-your-actual-key-here

Step 3: The Code (chat.py)

import os
from dotenv import load_dotenv
from openai import OpenAI

# Load the API key from the .env file (not hardcoded!)
load_dotenv()
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

question = input("Ask ChatGPT anything: ")

print("\nSending message to OpenAI...")

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "user", "content": question}
    ]
)

print("\nChatGPT says:")
print(response.choices[0].message.content)

Step 4: Run it

python chat.py

Example Session:

Ask ChatGPT anything: Explain Python in 10 words or less.

Sending message to OpenAI...

ChatGPT says:
A versatile, readable programming language popular for web and data.

Why is this a big deal? You typed a question, your script sent it to an AI supercomputer in the cloud, and printed the response. The openai library handled all the networking behind the scenes. The python-dotenv library kept your secret key safe. And the input() function — which you learned back in Part 5 — made it interactive. Everything connects.


4. Hands-On Project: Module vs Package vs Library

We have built a small project inside example_project/ that demonstrates all three levels side by side. Here is the structure:

example_project/
├── main.py                  ← Entry point: imports from all three
├── chat.py                  ← ChatGPT example from Section 3
├── my_module.py             ← MODULE: a single .py file
├── my_package/              ← PACKAGE: a folder with __init__.py
│   ├── __init__.py          ← Exposes functions from text_utils.py
│   └── text_utils.py        ← Functions that live inside the package
├── requirements.txt         ← Lists the third-party library we need
├── .env                     ← Secret keys go here (never push to GitHub)
└── .gitignore               ← Tells Git to ignore venv/, .env, __pycache__/

Notice the .env and .gitignore files. Every real project has these:

  • **.env** — stores secret keys (like the OpenAI API key from Section 3). You never hardcode secrets in your Python files and never push .env to GitHub.
  • **.gitignore** — tells Git which files to skip. We have already added venv/, .env, and __pycache__/ to it. You will learn what venv/ is in Part 31 — for now, just know the project is ready for it.

How Each One Gets Imported

All three use the same import syntax. The only difference is where the code lives:

# MODULE — from a single .py file in the same folder
from my_module import print_separator, format_currency, greet

# PACKAGE — from a folder with __init__.py
from my_package import clean_text, count_words, reverse_words

# LIBRARY — from code downloaded via pip (lives in site-packages)
import requests

Running the Project

Before running, you need to install the third-party library:

pip install requests

Then run from inside the example_project/ folder:

cd example_project
python main.py

The output will show all three in action — your module printing formatted text, your package processing strings, and the requests library fetching live data from the internet.

Why This Matters

This is exactly how real projects work. A Django web app has:

  • Modules — settings.py, urls.py (single files)
  • Packages — users/, products/ (folders with __init__.py)
  • Libraries — django, celery, redis (installed via pip)

The project you just ran uses the same pattern. The scale is different, the structure is identical.

Note: We deliberately included a requirements.txt in this project. In Part 31, you will use this exact project to learn virtual environments — creating an isolated environment and installing from requirements.txt so the project runs cleanly anywhere.


The Cliffhanger: The "Works on My Machine" Problem

You just ran pip install openai. It worked perfectly!

But ask yourself: Where did pip actually install that code on your laptop?

By default, it installs it into your "Global" system Python folder. Imagine you build this AI app today, and it requires openai version 1.0. Next year, you build a different app, and you run pip install openai again, but this time it installs version 2.0 and overwrites version 1.0.

Suddenly, your old app breaks!

If you just keep pip install-ing libraries globally, eventually, libraries will conflict, and your projects will start crashing unpredictably. This is known in the industry as "Dependency Hell."


DJANGO, FASTAPI ಎಲ್ಲಾ PROJECT ಇದರ ಮೇಲೆ ನಿಂತಿದೆ! | Modules & Imports | Python in Kannada | Part-29Stop Using requirements.txt! (Master Poetry & UV) 🚀 | Python in Kannada | Part-31

Up Next

30 / 58
  • 37:40

    Stop Using requirements.txt! (Master Poetry & UV) 🚀 | Python in Kannada | Part-31

    Part 31

  • 13:15

    Publish Your Own Package to PyPI! 🚀| Python in Kannada | Part-32

    Part 32

View all 58 lessons

GitHub Notes

View Part 30 notes on GitHub
GitHub Notes
View Part 30 notes on GitHub
PrevNext
19:35
19:35

Stop Your Code From Crashing! (Error Handling) 🚀 | Python in Kannada | Part-33

Part 33

Stop Your Code From Crashing! (Error Handling) 🚀 | Python in Kannada | Part-33

Part 33

  • 19:19

    Write Unbreakable Code (Custom Exceptions & EAFP) 🚀 | Python in Kannada | Part-34

    Part 34

  • 19:19

    Write Unbreakable Code (Custom Exceptions & EAFP) 🚀 | Python in Kannada | Part-34

    Part 34

  • 47:21

    Every Python Error Explained & Fixed! (Hands-On) | Python in Kannada | Part-35

    Part 35

  • 47:21

    Every Python Error Explained & Fixed! (Hands-On) | Python in Kannada | Part-35

    Part 35

  • 32:20

    File Handling: The Secret to Building AI Projects! | Python in Kannada | Part-36

    Part 36

  • 32:20

    File Handling: The Secret to Building AI Projects! | Python in Kannada | Part-36

    Part 36

  • 15:11

    Read & Write Files (Hands-On Practical) | Python in Kannada | Part-37.1

    Part 37.1

  • 15:11

    Read & Write Files (Hands-On Practical) | Python in Kannada | Part-37.1

    Part 37.1

  • 34:38

    99% Developers Fail This Python Interview Question! (Hidden Bug Revealed)| Part-37.2

    Part 37.2

  • 34:38

    99% Developers Fail This Python Interview Question! (Hidden Bug Revealed)| Part-37.2

    Part 37.2