Python OpenAI API Tutorial for Beginners

Python OpenAI API tutorial: VS Code run of a first Responses API call printing output_text

Calling the OpenAI API from Python takes about ten lines once the package and key are in place. Most beginner trouble comes from the setup around them. Quick answer: run pip install openai python-dotenv, put OPENAI_API_KEY in a .env file, then call client.responses.create() with a model and an input, and print response.output_text. In this tutorial, … Read more >>

How to Create GET Endpoints in FastAPI

FastAPI GET endpoint routes for a job board API listed in Swagger UI

Many guides still stop at one hello-world route. It runs, but a real API also has to return lists, single records and a proper 404. In this tutorial, I’ll build a FastAPI GET endpoint the fuller way: decorate a function with @app.get(), return your data, and FastAPI sends it as JSON. Everything below ran on … Read more >>

How to Check if a String Is Base64 Encoded in Python

Check if a string is Base64 encoded in Python: VS Code output of an is_base64() function

To check if a string is Base64 encoded in Python, decode it with base64.b64decode(text, validate=True) and catch the error. If it decodes, the string is valid Base64. Valid doesn’t always mean somebody encoded it, though. An ordinary word like database passes too, so I’ll also show you how to test what’s inside. In this tutorial, … Read more >>

How to Convert String to Boolean in Python (and Check if It’s a Bool)

Convert string to boolean in Python: VS Code output of a str_to_bool() function

As a Python developer, you’re often asked to turn text like “True” or “false” from a config file into a real Boolean. To convert a string to a boolean, compare it: text.strip().lower() == “true”. Don’t use bool(text) for this. bool(“False”) returns True. In this tutorial, I’ll show you how to convert string to boolean in … Read more >>

Check if a String Starts With a Substring in Python (startswith)

Check if a string starts with a substring in Python: VS Code output of startswith()

I always use startswith() to check if a string starts with a substring in Python, because I don’t have to count characters. It returns True or False. Here’s the shortest version. Save this as quick_check.py and run python quick_check.py: Output: In this tutorial, I’ll show you how to check if a string starts with a … Read more >>

How to Check if a String Is an Integer or Float in Python

Check if a string is an integer or float in Python: Command Prompt output of number_type()

By default, Python reads every value from a file or form as a string, so “12” and “24.99” both show up as str. To check if a string is an integer or a float, try int() first, then float(). The order matters, because float(“12”) works too. If you call it first, every integer looks like … Read more >>

How to Build an AI Chatbot in Python

Build an AI chatbot in Python: VS Code run of a help-desk bot that remembers the customer's name

If you need a Python help-desk bot that still knows the customer’s name three messages later, keep every message in a list and send that list to the AI model on each turn. That one habit separates an AI chatbot from a one-off API call. Most first attempts forget everything, because each API call starts … Read more >>

How to Run a FastAPI Application with Uvicorn

Run a FastAPI application with Uvicorn: Command Prompt showing uvicorn main:app serving a national parks API

If you’ve tried to start your API and got Could not import module “main”, the tool is fine and the target is wrong. You run FastAPI with Uvicorn by opening a terminal in the folder that holds main.py and typing uvicorn main:app. That one string trips people up because it looks like a file path, … Read more >>