A simple Python package for calling OpenAI's API without using Pydantic or the OpenAI SDK. Perfect for environments where Pydantic is unavailable or you want minimal dependencies.
- ✅ Simple, single-function API:
ask_ai_question(input_text, question_asked) - ✅ Zero Pydantic dependency - uses direct HTTP requests
- ✅ No OpenAI SDK required - bypasses all SDK dependencies
- ✅ Support for all OpenAI chat models (GPT-4, GPT-4o, GPT-3.5, etc.)
- ✅ Customizable parameters (temperature, max_tokens, model)
- ✅ Type hints for better IDE support
- ✅ Comprehensive error handling
- ✅ Only requires
requestslibrary
Install from PyPI:
pip install openai-without-pydanticThat's it! Only requests is installed - no Pydantic, no OpenAI SDK!
The package needs your OpenAI API key to make requests. Set it as an environment variable:
Linux/macOS (bash/zsh):
export OPENAI_API_KEY='your-api-key-here'Windows (Command Prompt):
set OPENAI_API_KEY=your-api-key-hereWindows (PowerShell):
$env:OPENAI_API_KEY='your-api-key-here'Or use a .env file (recommended for development):
# Create a .env file in your project directory
OPENAI_API_KEY=your-api-key-hereThen load it in your Python code:
from dotenv import load_dotenv
load_dotenv() # This loads the .env fileNote: Install
python-dotenvfor.envfile support:pip install python-dotenv
from openai_wrapper import ask_ai_question
input_text = """
Python is a high-level programming language created by Guido van Rossum
and first released in 1991.
"""
question = "Who created Python?"
response = ask_ai_question(
input_text=input_text,
question_asked=question
)
print(response) # Output: Python was created by Guido van Rossum.from openai_wrapper import ask_ai_question
# Use custom parameters
response = ask_ai_question(
input_text="Your context here...",
question_asked="Your question here...",
model="gpt-4o", # Specify model
temperature=0.3, # Lower for more factual responses
max_tokens=200, # Limit response length
api_key="your-key-here" # Or use environment variable
)- input_text (str, required): The context/text to use for answering the question
- question_asked (str, required): The question to ask about the input_text
- api_key (str, optional): OpenAI API key (defaults to OPENAI_API_KEY env var)
- model (str, optional): The OpenAI model to use (default: "gpt-4o-mini")
- temperature (float, optional): Sampling temperature 0-2 (default: 0.7)
- max_tokens (int, optional): Maximum tokens in response (default: None)
Check out the examples/ directory for various usage examples:
# Basic usage
python examples/basic_usage.py
# Advanced features
python examples/advanced_usage.py
# Batch processing
python examples/batch_processing.pyOr use the convenience scripts (automatically activates virtual environment):
./run_examples.sh # Interactive menu
./run_basic.sh # Run basic example
./run_advanced.sh # Run advanced example
./run_batch.sh # Run batch exampleSee examples/README.md for detailed information about each example, or SCRIPTS.md for more about the convenience scripts.
.
├── openai_wrapper/ # Main package
│ ├── __init__.py # Package initialization
│ ├── client.py # Core implementation
│ └── py.typed # Type hint marker
├── examples/ # Usage examples
│ ├── basic_usage.py # Simple examples
│ ├── advanced_usage.py # Advanced features
│ ├── batch_processing.py # Batch operations
│ └── README.md # Examples documentation
├── tests/ # Unit tests
│ ├── __init__.py
│ └── test_client.py # Test suite
├── .github/workflows/ # CI/CD pipelines
│ ├── test.yml # Automated testing
│ └── publish.yml # PyPI publishing
├── run_examples.sh # Interactive example runner
├── run_basic.sh # Quick run basic example
├── run_advanced.sh # Quick run advanced example
├── run_batch.sh # Quick run batch example
├── run_tests.sh # Quick run tests
├── CHANGELOG.md # Version history
├── CONTRIBUTING.md # Contribution guidelines
├── SECURITY.md # Security policy
├── PUBLISHING.md # Publishing guide
├── SCRIPTS.md # Convenience scripts docs
├── LICENSE # MIT License
├── README.md # This file
├── pyproject.toml # Modern Python packaging
├── setup.py # Package setup
└── requirements.txt # Dependencies
The package includes comprehensive error handling:
try:
response = ask_ai_question(input_text="...", question_asked="...")
except ValueError as e:
print(f"Configuration error: {e}")
except Exception as e:
print(f"API error: {e}")This package is specifically designed for environments where Pydantic is not available.
The Problem: The official OpenAI Python SDK (openai package) has a hard dependency on pydantic and pydantic-core, which may be unavailable in some environments.
Our Solution: We bypass the OpenAI SDK entirely and call the OpenAI API directly using HTTP requests via the requests library. This eliminates all Pydantic dependencies while maintaining full functionality.
requests>=2.25.0- For making HTTP requests to OpenAI API- That's it! No Pydantic, no OpenAI SDK, no hidden dependencies.
Run the test suite:
pytest tests/ -vWith coverage:
pytest tests/ --cov=openai_wrapper --cov-report=term-missingSee CONTRIBUTING.md for development setup.
Contributions are welcome! Please see CONTRIBUTING.md for:
- Development setup
- Coding standards
- How to submit pull requests
- Running tests
For security concerns, please see SECURITY.md for:
- Reporting vulnerabilities
- Security best practices
- API key safety guidelines
To publish this package to PyPI, see PUBLISHING.md for step-by-step instructions.
Got questions? Check out the FAQ.md for answers to common questions!
See CHANGELOG.md for version history and release notes.
MIT License - see LICENSE for details.
This project follows a Code of Conduct to ensure a welcoming environment. See CODE_OF_CONDUCT.md.