Secure LLM API wrapper with user authentication and request validation
Project description
ChatIdeyalabs PyPI Publishing Guide
🚀 Publishing to PyPI
This guide explains how to securely publish the ChatIdeyalabs package to PyPI while keeping sensitive information hidden.
📋 Prerequisites
- PyPI Account: Create account at pypi.org
- PyPI API Token: Generate API token in PyPI account settings
- Environment Setup: Configure environment variables for security
🔐 Security Setup
Environment Variables (Required)
Create a .env file for local development (DO NOT commit this):
# .env file (for local development only)
CHATIDEYALABS_LLM_BASE_URL=https://your-llm-endpoint.com
CHATIDEYALABS_LLM_API_KEY=your-llm-api-key-here
CHATIDEYALABS_MONGODB_URL=mongodb+srv://username:password@cluster.mongodb.net/database
CHATIDEYALABS_MONGODB_DATABASE=your_database
CHATIDEYALABS_MONGODB_COLLECTION=apiKeys
CHATIDEYALABS_ENABLE_LOGGING=true
CHATIDEYALABS_LOG_SENSITIVE=false
Add .env to .gitignore
echo ".env" >> .gitignore
echo "*.env" >> .gitignore
echo "__pycache__/" >> .gitignore
echo "*.pyc" >> .gitignore
echo "dist/" >> .gitignore
echo "build/" >> .gitignore
echo "*.egg-info/" >> .gitignore
📦 Publishing Workflow
Step 1: Install Publishing Tools
pip install build twine
Step 2: Update Version
Edit setup.py:
setup(
name="chat-ideyalabs",
version="0.2.0", # Increment version
# ... rest of setup
)
Step 3: Clean Previous Builds
rm -rf dist/ build/ *.egg-info/
Step 4: Build the Package
python -m build
This creates:
dist/chat_ideyalabs-0.2.0.tar.gzdist/chat_ideyalabs-0.2.0-py3-none-any.whl
Step 5: Test Upload (Optional)
# Upload to TestPyPI first
python -m twine upload --repository testpypi dist/*
# Test installation from TestPyPI
pip install --index-url https://test.pypi.org/simple/ chat-ideyalabs
Step 6: Upload to PyPI
python -m twine upload dist/*
Enter your PyPI API token when prompted.
👥 User Installation & Setup
For Package Users
Installation:
pip install chat-ideyalabs
Environment Setup (Required for Users):
Users need to set environment variables:
# Required: LLM configuration (set by admin)
export CHATIDEYALABS_LLM_BASE_URL=https://your-llm-endpoint.com
export CHATIDEYALABS_LLM_API_KEY=your-llm-api-key-here
# Required: MongoDB configuration for API key validation
export CHATIDEYALABS_MONGODB_URL=mongodb+srv://username:password@cluster.mongodb.net/database
# Optional: Logging configuration
export CHATIDEYALABS_ENABLE_LOGGING=false
export CHATIDEYALABS_LOG_SENSITIVE=false
Usage:
from chat_ideyalabs import ChatIdeyalabs
# User provides their API key
chat = ChatIdeyalabs(api_key="user-api-key-from-admin")
response = chat.invoke("Hello, world!")
print(response.content)
🔧 Administrator Setup
Server Environment Variables
Set these on your API server:
# Production environment
export CHATIDEYALABS_LLM_BASE_URL=https://your-llm-endpoint.com
export CHATIDEYALABS_LLM_API_KEY=your-llm-api-key-here
export CHATIDEYALABS_MONGODB_URL=mongodb+srv://username:password@cluster.mongodb.net/database
export CHATIDEYALABS_MONGODB_DATABASE=your_database
export CHATIDEYALABS_MONGODB_COLLECTION=apiKeys
export CHATIDEYALABS_ENABLE_LOGGING=true
export CHATIDEYALABS_LOG_SENSITIVE=false
Docker Deployment Example
# Dockerfile
FROM python:3.10-slim
ENV CHATIDEYALABS_LLM_BASE_URL=https://your-llm-endpoint.com
ENV CHATIDEYALABS_LLM_API_KEY=your-llm-api-key-here
ENV CHATIDEYALABS_MONGODB_URL=mongodb+srv://username:password@cluster.mongodb.net/database
COPY . /app
WORKDIR /app
RUN pip install -e .
CMD ["uvicorn", "chat_ideyalabs.api.main:app", "--host", "0.0.0.0", "--port", "8000"]
📋 User Documentation Template
Create this for your users:
ChatIdeyalabs Package Usage Guide
Installation:
pip install chat-ideyalabs
Environment Setup:
# Set the MongoDB connection (provided by admin)
export CHATIDEYALABS_MONGODB_URL=mongodb+srv://username:password@cluster.mongodb.net/database
export CHATIDEYALABS_LLM_BASE_URL=https://your-llm-endpoint.com
export CHATIDEYALABS_LLM_API_KEY=your-llm-api-key-here
Get API Key: Contact your administrator to get an API key.
Usage:
from chat_ideyalabs import ChatIdeyalabs
# Initialize with your API key
chat = ChatIdeyalabs(
api_key="your-api-key-here",
response_format={"type": "json_object"},
temperature=0.7
)
# Basic usage
response = chat.invoke("What is AI?")
print(response.content)
# Async usage
response = await chat.ainvoke("Explain machine learning")
print(response.content)
# Streaming
async for chunk in chat.astream("Write a poem"):
print(chunk, end="", flush=True)
🔒 Security Benefits
✅ Sensitive data hidden - All secrets in environment variables
✅ No hardcoded credentials - Package safely distributed
✅ User authentication - Each user needs valid API key
✅ Configurable logging - Can disable/mask sensitive data
✅ Easy deployment - Environment-based configuration
🚨 Important Notes
- Never commit
.envfiles to version control - Always test on TestPyPI first before publishing to PyPI
- Users need environment setup - provide clear instructions
- API keys expire - implement key rotation if needed
- Monitor usage - track package downloads and API usage
📈 Version Management
- Patch: Bug fixes (0.1.0 → 0.1.1)
- Minor: New features (0.1.0 → 0.2.0)
- Major: Breaking changes (0.1.0 → 1.0.0)
🆘 Troubleshooting
Publishing Issues
- Check PyPI API token
- Verify package name availability
- Ensure version number is incremented
User Issues
- Verify environment variables are set
- Check API key validity
- Confirm validation endpoint is accessible
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chat_ideyalabs-0.1.5.tar.gz.
File metadata
- Download URL: chat_ideyalabs-0.1.5.tar.gz
- Upload date:
- Size: 24.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5545e0d171879a3523f8ccc72a8fec9f3de82bfca686c2339a42eed1a96e1b4
|
|
| MD5 |
3873aa9613f9be550e2ff9a41df7a376
|
|
| BLAKE2b-256 |
72c27525cfd2d7f20bc6dc4fd4da15ae5eba6379ff0b57ae4419b10e6011a60e
|
File details
Details for the file chat_ideyalabs-0.1.5-py3-none-any.whl.
File metadata
- Download URL: chat_ideyalabs-0.1.5-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
032a259920fbf0d3b561d780b62604274494a9734c1157338f81aea6592a1723
|
|
| MD5 |
603737651cae043cf0e2a6f553c16bfb
|
|
| BLAKE2b-256 |
c2a6ff116761438189d381eb0db76ade13d7b3a324526158e38818757ed6a5da
|