This repository contains a simple Python script for making API calls with bearer token authentication. The token is read from a local file for security.
-
Run the setup script:
python setup.py
-
Edit configuration files:
- Edit
token.txt
with your actual bearer token - Edit
.env
with your API base URL
- Edit
-
Activate virtual environment:
# On Linux/macOS source venv/bin/activate # On Windows venv\Scripts\activate
-
Run the API client:
python api_client.py
If you prefer to set up manually:
-
Create virtual environment:
python -m venv venv source venv/bin/activate # Linux/macOS # or venv\Scripts\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
-
Create configuration files:
cp .env.example .env cp token.txt.example token.txt
-
Edit the files with your actual values
The APIClient
class supports GET, POST, PUT, and DELETE requests:
from api_client import APIClient
# Initialize client
client = APIClient(token_file="token.txt", base_url="https://api.example.com")
# Make requests
response = client.get("/api/users")
response = client.post("/api/users", json_data={"name": "John"})
response = client.put("/api/users/1", json_data={"name": "Jane"})
response = client.delete("/api/users/1")
Run the test suite to verify everything works:
python test_api_client.py
api_client.py
- Main API client scriptsetup.py
- Automated setup scripttest_api_client.py
- Test suiterequirements.txt
- Python dependencies.env.example
- Environment variables templatetoken.txt.example
- Token file template