A Django + DRF package to generate Postman v2.1 collections with a single command
Project description
DRF Postman
Generate Postman Collections from your Django REST Framework APIs with a single command. This tool automatically introspects your DRF routes and generates a ready-to-import Postman Collection v2.1 JSON file.
Installation
pip install drf-postman
Add to your INSTALLED_APPS:
INSTALLED_APPS = [
# ...
'drf_postman'
]
Configure your REST framework settings:
REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
}
Quick Start
Generate a Postman collection:
python3 manage.py generatepostman
This creates postman_collection.json in your project root. Import into Postman and start testing!
Usage
Basic Command
python3 manage.py generatepostman
With Options
# Custom output path
python3 manage.py generatepostman --output my_api.json
# Custom collection name
python3 manage.py generatepostman --name "My Awesome API"
# Custom base URL
python3 manage.py generatepostman --base-url "https://api.example.com"
# All together
python3 manage.py generatepostman -o collections/api.json -n "My API v2" -b "https://staging.api.com"
Configuration
Customize defaults in your settings.py:
DRF_POSTMAN = {
'COLLECTION_NAME': 'My API',
'BASE_URL': 'https://api.example.com',
'OUTPUT_PATH': 'postman_collection.json',
}
What Gets Generated
Collection Structure
My API Collection
├── Accounts
│ ├── POST Login
│ └── POST Register
└── Todos
├── GET List Todos
├── POST Create Todo
├── GET Retrieve Todo
├── PUT Update Todo
└── DELETE Delete Todo
Request Features
- Method & URL: Correctly formatted with path parameters
- Headers: Content-Type and Authorization when needed
- Body: JSON examples generated from serializers
- Parameters: Path and query parameters with descriptions
- Variables: {{base_url}} environment variable included
Example Request Body
For a serializer like:
class TodoSerializer(serializers.ModelSerializer):
class Meta:
model = Todo
fields = ['id', 'title', 'description', 'completed']
read_only_fields = ['id']
Generates:
{
"title": "string",
"description": "string",
"completed": true
}
Note:
idis excluded because it's read-only.
Requirements
- Python >= 3.8
- Django >= 3.2
- Django REST Framework >= 3.12
- drf-spectacular >= 0.26.0
How It Works
- Uses
drf-spectacularto generate an OpenAPI 3.0 schema from your DRF routes - Converts the OpenAPI schema to Postman Collection v2.1 format
- Groups endpoints by tags (typically ViewSet names)
- Generates example request bodies from serializer schemas
- Includes authentication, parameters, and metadata
Limitations
- Requires
drf-spectacularfor schema generation
Example Project
Check out the example_project/ directory for a complete example with:
- JWT Authentication
- django-filter integration
- Multiple related models
Run it:
cd example_project
pip install -r requirements.txt
python3 manage.py migrate
python3 manage.py generatepostman
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Testing
Tests coming soon :)
License
MIT License - see LICENSE file for details.
Support
If you encounter any issues or have questions:
- Open an issue
- Check existing issues for solutions
⭐ Star this repo if you find it useful!
Project details
Release history Release notifications | RSS feed
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 drf_postman-0.1.0.tar.gz.
File metadata
- Download URL: drf_postman-0.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1455424491a881e73c034113ff0d6007263e0b21678b82bd50199a5a3caf75c0
|
|
| MD5 |
1dfeb6d7afd9db2cf80649efc88c3547
|
|
| BLAKE2b-256 |
fa0d049ac3555f4b0da0a3fe93377014c98c473f3af421e9c321a5974f357bf8
|
File details
Details for the file drf_postman-0.1.0-py3-none-any.whl.
File metadata
- Download URL: drf_postman-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90867aeee8f461f6c4f718c2cc172181eeecdfd05eaa94f51ad60ff3904261d4
|
|
| MD5 |
1b9b75d47b9193568cce9d4f13b3a5ed
|
|
| BLAKE2b-256 |
bd6f62a2cc4e37bb1629b61284e6e9b8420c6701678e095207878b2a727d158a
|