A modern FastAPI-based wrapper for the Pastebin API, providing clean, type-safe endpoints for authentication, paste creation, and paste management.
- Type-safe API: Built with Pydantic models for request/response validation
- Modern Python: Uses Python 3.14+ with modern syntax (union types, etc.)
- Dependency Injection: FastAPI's IoC container for clean architecture
- Custom Exception Handling: Domain-specific exceptions with centralized error handling
- Async Support: Fully asynchronous using aiohttp
- Syntax Highlighting: Support for 200+ programming languages via PasteFormat enum
.
├── config.py # Environment-based configuration using Pydantic Settings
├── exceptions.py # Custom domain exceptions
├── main.py # FastAPI application with exception handlers
├── models/ # Pydantic models
│ ├── api_response.py # Generic type-safe response wrapper
│ ├── login/ # Authentication models
│ └── paste/ # Paste-related models
├── routers/ # FastAPI routers
│ ├── auth.py # Authentication endpoints
│ └── paste.py # Paste management endpoints
└── services/ # Business logic layer
├── pastebin_service.py # Pastebin API integration
└── xml_service.py # XML parsing utilities
- Python 3.14+
- Dependencies managed via
uv
- Clone the repository:
git clone <repository-url>
cd PasteBinApi- Create a
.envfile with your Pastebin credentials:
PASTEBIN_BASE_URL=https://pastebin.com/api
DEV_API_KEY=your_developer_api_key
USER_NAME=your_username
USER_PASSWORD=your_password- Install dependencies:
uv syncStart the development server:
uv run uvicorn main:app --reloadThe API will be available at http://localhost:8000
Build and run with Docker:
# Build the Docker image
docker build -t pastebin-api .
# Run the container
docker run -d \
--name pastebin-api \
-p 8000:8000 \
-e PASTEBIN_BASE_URL=https://pastebin.com/api \
-e DEV_API_KEY=your_dev_api_key \
-e USER_NAME=your_username \
-e USER_PASSWORD=your_password \
pastebin-api
# Or use environment file
docker run -d \
--name pastebin-api \
-p 8000:8000 \
--env-file .env \
pastebin-apiUsing Docker Compose (create docker-compose.yml):
version: '3.8'
services:
api:
build: .
ports:
- "8000:8000"
environment:
- PASTEBIN_BASE_URL=${PASTEBIN_BASE_URL}
- DEV_API_KEY=${DEV_API_KEY}
- USER_NAME=${USER_NAME}
- USER_PASSWORD=${USER_PASSWORD}
restart: unless-stoppedThen run:
docker-compose up -dOnce the server is running, visit:
- Interactive API docs (Swagger): http://localhost:8000/docs
- Alternative API docs (ReDoc): http://localhost:8000/redoc
Authenticate with Pastebin and receive a user session key.
Request:
{
"api_user_name": "your_username",
"api_user_password": "your_password"
}Response:
{
"data": {
"api_user_key": "session_key_here"
}
}Create a new paste on Pastebin.
Request:
{
"api_paste_code": "print('Hello, World!')",
"api_paste_name": "My Python Script",
"api_paste_format": "python",
"api_paste_private": 0,
"api_paste_expire_date": "10M",
"api_user_key": "session_key_from_login"
}Response:
{
"data": {
"paste_url": "https://pastebin.com/abc123"
}
}List all pastes for an authenticated user.
Request:
{
"api_user_key": "session_key_from_login",
"api_results_limit": 50
}Response:
{
"data": {
"pastes": [
{
"key": "abc123",
"date": "2026-03-10T12:00:00",
"title": "My Python Script",
"size": 1024,
"expire_date": 0,
"private": 0,
"format_long": "Python",
"format_short": "python",
"url": "https://pastebin.com/abc123",
"hits": 42
}
]
}
}- Routers - Define API endpoints and handle HTTP concerns
- Services - Contain business logic and external API integration
- Models - Provide type-safe contracts for requests/responses
- Configuration - Centralized environment-based settings
Settingsinjected into services viaget_settings()PastebinServiceinjected into routers viaget_pastebin_service()
- Domain exceptions raised in service layer
- Custom exception handlers in
main.pytranslate to HTTP responses - Consistent error response format across all endpoints
All configuration is managed through environment variables in .env:
| Variable | Description |
|---|---|
PASTEBIN_BASE_URL |
Base URL for Pastebin API |
DEV_API_KEY |
Your Pastebin developer API key |
USER_NAME |
Test username (optional) |
USER_PASSWORD |
Test password (optional) |
uv run pytest- Use
snake_casefor files and variables - Use
PascalCasefor class names - Modern Python syntax:
str | Noneinstead ofOptional[str] - Explicit
default=in Pydantic Field()
HTTP request examples are available in test_main.http for manual API testing with tools like VS Code REST Client or JetBrains HTTP Client.
This project uses GitHub Actions for continuous integration and deployment:
- Runs on every push and pull request to
mainanddevelopbranches - Tests against Python 3.14
- Generates test coverage reports
- Uploads coverage to Codecov
- Runs on pushes to
mainbranch and on version tags - Runs tests before building
- Builds multi-platform Docker images (amd64, arm64)
- Publishes to Docker Hub:
noobynet/pastebinapi - Automatically tags with:
latest(main branch)- Semantic version tags (from git tags)
- Branch names
- Git SHA
To enable Docker publishing, add these secrets to your repository:
DOCKERHUB_USERNAME: Your Docker Hub usernameDOCKERHUB_TOKEN: Your Docker Hub access token
Docker images are available at: noobynet/pastebinapi
Pull the latest image:
docker pull noobynet/pastebinapi:latest[Add your license here]
[Add contribution guidelines here]