# FastAPI Postman Exporter
A Python package to export FastAPI applications to Postman collections using the OpenAPI specification.
## Features
- 🚀 Export any FastAPI app to a Postman collection
- 🔧 CLI interface for easy integration
- 📦 Simple Python API for programmatic use
- 🎯 Automatic OpenAPI spec generation
- ✅ Validation and error handling
## Prerequisites
Before using this package, you need to install the `openapi2postmanv2` CLI tool:
### Install Node.js and npm
1. Download and install Node.js from [nodejs.org](https://nodejs.org/)
2. Verify installation:
```bash
node --version
npm --version
```
### Install openapi2postmanv2
```bash
npm install -g openapi2postmanv2
```
Verify the installation:
```bash
openapi2postmanv2 --version
```
## Installation
### From PyPI (recommended)
```bash
pip install fastapi-postman-exporter
```
### From source
```bash
git clone https://github.com/Akshya107/fastapi-postman-exporter.git
cd fastapi-postman-exporter
pip install -e .
```
## Usage
### CLI Usage
The package provides a command-line interface for easy export:
```bash
# Basic usage
fastapi-postman-exporter export --app-path main.py --app-name app --output collection.json
# With custom app name
fastapi-postman-exporter export --app-path api/main.py --app-name api_app --output postman_collection.json
# With verbose output
fastapi-postman-exporter export --app-path main.py --app-name app --output collection.json --verbose
```
#### CLI Options
- `--app-path` / `-p`: Path to your FastAPI app file (e.g., `main.py`)
- `--app-name` / `-n`: Name of the FastAPI app object in the file (default: `app`)
- `--output` / `-o`: Path where the Postman collection JSON will be saved
- `--verbose` / `-v`: Enable verbose output
#### Check CLI Tool Installation
```bash
fastapi-postman-exporter check
```
### Python API Usage
You can also use the package programmatically:
```python
from fastapi import FastAPI
from fastapi_postman_exporter import generate_postman_from_app
# Your FastAPI app
app = FastAPI(title="My API", version="1.0.0")
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int):
return {"item_id": item_id}
# Export to Postman collection
generate_postman_from_app(app, "my_api_collection.json")
```
## Example FastAPI App
Here's a simple example of a FastAPI app that can be exported:
```python
# main.py
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI(
title="Sample API",
description="A sample API for demonstration",
version="1.0.0"
)
class Item(BaseModel):
name: str
price: float
is_offer: bool = None
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
return {"item_id": item_id, "q": q}
@app.post("/items/")
def create_item(item: Item):
return item
@app.put("/items/{item_id}")
def update_item(item_id: int, item: Item):
return {"item_id": item_id, **item.dict()}
```
Export this app:
```bash
fastapi-postman-exporter export --app-path main.py --app-name app --output sample_api_collection.json
```
## Project Structure
```
fastapi_postman_exporter/
├── __init__.py # Package initialization
├── exporter.py # Core export functionality
├── cli.py # CLI interface
└── main.py # CLI entry point
```
## Development
### Setup Development Environment
```bash
git clone https://github.com/Akshya107/fastapi-postman-exporter.git
cd fastapi-postman-exporter
pip install -e ".[dev]"
```
### Run Tests
```bash
pytest
```
### Code Formatting
```bash
black fastapi_postman_exporter/
isort fastapi_postman_exporter/
```
### Type Checking
```bash
mypy fastapi_postman_exporter/
```
## How It Works
1. **OpenAPI Generation**: Uses FastAPI's built-in `openapi()` method to generate the OpenAPI specification
2. **Temporary File**: Writes the OpenAPI spec to a temporary JSON file
3. **Conversion**: Uses the `openapi2postmanv2` CLI tool to convert the OpenAPI spec to a Postman collection
4. **Cleanup**: Removes the temporary file and outputs the Postman collection
## Error Handling
The package provides helpful error messages for common issues:
- **CLI tool not installed**: Clear instructions to install `openapi2postmanv2`
- **App loading errors**: Detailed error messages for file not found, invalid app name, etc.
- **Conversion errors**: Captures and displays subprocess errors from the conversion tool
## Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Run the test suite
6. Submit a pull request
## License
This project is licensed under the MIT License - see the LICENSE file for details.
## Support
If you encounter any issues or have questions:
1. Check the [Issues](https://github.com/Akshya107/fastapi-postman-exporter/issues) page
2. Create a new issue with detailed information about your problem
3. Include your FastAPI app code and the exact error message
## Changelog
### 0.1.0
- Initial release
- CLI interface with export and check commands
- Python API for programmatic use
- Support for dynamic FastAPI app loading
- Comprehensive error handling
Raw data
{
"_id": null,
"home_page": null,
"name": "fastapi-postman-exporter",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "api, export, fastapi, openapi, postman",
"author": "FastAPI Postman Exporter Contributors",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/7a/98/6d73d6d23278371f642683a1554681bd470e13d78712e6ce6ff40d402418/fastapi_postman_exporter-0.1.1.tar.gz",
"platform": null,
"description": "# FastAPI Postman Exporter\n\nA Python package to export FastAPI applications to Postman collections using the OpenAPI specification.\n\n## Features\n\n- \ud83d\ude80 Export any FastAPI app to a Postman collection\n- \ud83d\udd27 CLI interface for easy integration\n- \ud83d\udce6 Simple Python API for programmatic use\n- \ud83c\udfaf Automatic OpenAPI spec generation\n- \u2705 Validation and error handling\n\n## Prerequisites\n\nBefore using this package, you need to install the `openapi2postmanv2` CLI tool:\n\n### Install Node.js and npm\n\n1. Download and install Node.js from [nodejs.org](https://nodejs.org/)\n2. Verify installation:\n ```bash\n node --version\n npm --version\n ```\n\n### Install openapi2postmanv2\n\n```bash\nnpm install -g openapi2postmanv2\n```\n\nVerify the installation:\n```bash\nopenapi2postmanv2 --version\n```\n\n## Installation\n\n### From PyPI (recommended)\n\n```bash\npip install fastapi-postman-exporter\n```\n\n### From source\n\n```bash\ngit clone https://github.com/Akshya107/fastapi-postman-exporter.git\ncd fastapi-postman-exporter\npip install -e .\n```\n\n## Usage\n\n### CLI Usage\n\nThe package provides a command-line interface for easy export:\n\n```bash\n# Basic usage\nfastapi-postman-exporter export --app-path main.py --app-name app --output collection.json\n\n# With custom app name\nfastapi-postman-exporter export --app-path api/main.py --app-name api_app --output postman_collection.json\n\n# With verbose output\nfastapi-postman-exporter export --app-path main.py --app-name app --output collection.json --verbose\n```\n\n#### CLI Options\n\n- `--app-path` / `-p`: Path to your FastAPI app file (e.g., `main.py`)\n- `--app-name` / `-n`: Name of the FastAPI app object in the file (default: `app`)\n- `--output` / `-o`: Path where the Postman collection JSON will be saved\n- `--verbose` / `-v`: Enable verbose output\n\n#### Check CLI Tool Installation\n\n```bash\nfastapi-postman-exporter check\n```\n\n### Python API Usage\n\nYou can also use the package programmatically:\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_postman_exporter import generate_postman_from_app\n\n# Your FastAPI app\napp = FastAPI(title=\"My API\", version=\"1.0.0\")\n\n@app.get(\"/\")\ndef read_root():\n return {\"Hello\": \"World\"}\n\n@app.get(\"/items/{item_id}\")\ndef read_item(item_id: int):\n return {\"item_id\": item_id}\n\n# Export to Postman collection\ngenerate_postman_from_app(app, \"my_api_collection.json\")\n```\n\n## Example FastAPI App\n\nHere's a simple example of a FastAPI app that can be exported:\n\n```python\n# main.py\nfrom fastapi import FastAPI\nfrom pydantic import BaseModel\n\napp = FastAPI(\n title=\"Sample API\",\n description=\"A sample API for demonstration\",\n version=\"1.0.0\"\n)\n\nclass Item(BaseModel):\n name: str\n price: float\n is_offer: bool = None\n\n@app.get(\"/\")\ndef read_root():\n return {\"Hello\": \"World\"}\n\n@app.get(\"/items/{item_id}\")\ndef read_item(item_id: int, q: str = None):\n return {\"item_id\": item_id, \"q\": q}\n\n@app.post(\"/items/\")\ndef create_item(item: Item):\n return item\n\n@app.put(\"/items/{item_id}\")\ndef update_item(item_id: int, item: Item):\n return {\"item_id\": item_id, **item.dict()}\n```\n\nExport this app:\n```bash\nfastapi-postman-exporter export --app-path main.py --app-name app --output sample_api_collection.json\n```\n\n## Project Structure\n\n```\nfastapi_postman_exporter/\n\u251c\u2500\u2500 __init__.py # Package initialization\n\u251c\u2500\u2500 exporter.py # Core export functionality\n\u251c\u2500\u2500 cli.py # CLI interface\n\u2514\u2500\u2500 main.py # CLI entry point\n```\n\n## Development\n\n### Setup Development Environment\n\n```bash\ngit clone https://github.com/Akshya107/fastapi-postman-exporter.git\ncd fastapi-postman-exporter\npip install -e \".[dev]\"\n```\n\n### Run Tests\n\n```bash\npytest\n```\n\n### Code Formatting\n\n```bash\nblack fastapi_postman_exporter/\nisort fastapi_postman_exporter/\n```\n\n### Type Checking\n\n```bash\nmypy fastapi_postman_exporter/\n```\n\n## How It Works\n\n1. **OpenAPI Generation**: Uses FastAPI's built-in `openapi()` method to generate the OpenAPI specification\n2. **Temporary File**: Writes the OpenAPI spec to a temporary JSON file\n3. **Conversion**: Uses the `openapi2postmanv2` CLI tool to convert the OpenAPI spec to a Postman collection\n4. **Cleanup**: Removes the temporary file and outputs the Postman collection\n\n## Error Handling\n\nThe package provides helpful error messages for common issues:\n\n- **CLI tool not installed**: Clear instructions to install `openapi2postmanv2`\n- **App loading errors**: Detailed error messages for file not found, invalid app name, etc.\n- **Conversion errors**: Captures and displays subprocess errors from the conversion tool\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests for new functionality\n5. Run the test suite\n6. Submit a pull request\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## Support\n\nIf you encounter any issues or have questions:\n\n1. Check the [Issues](https://github.com/Akshya107/fastapi-postman-exporter/issues) page\n2. Create a new issue with detailed information about your problem\n3. Include your FastAPI app code and the exact error message\n\n## Changelog\n\n### 0.1.0\n- Initial release\n- CLI interface with export and check commands\n- Python API for programmatic use\n- Support for dynamic FastAPI app loading\n- Comprehensive error handling ",
"bugtrack_url": null,
"license": "MIT",
"summary": "Export FastAPI applications to Postman collections",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/Akshya107/fastapi-postman-exporter",
"Issues": "https://github.com/Akshya107/fastapi-postman-exporter/issues",
"Repository": "https://github.com/Akshya107/fastapi-postman-exporter"
},
"split_keywords": [
"api",
" export",
" fastapi",
" openapi",
" postman"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "d7e2249ffedb5116c1d197993448972398f7f11274a15e33aec2473a8dfc2e87",
"md5": "25ec73cff81ad15117a4c320e212aeba",
"sha256": "cc310b9c530c8915d2e854ae189383d1ff82acd18fa18ab837405a1ca89dca4c"
},
"downloads": -1,
"filename": "fastapi_postman_exporter-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "25ec73cff81ad15117a4c320e212aeba",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 6626,
"upload_time": "2025-07-19T19:38:35",
"upload_time_iso_8601": "2025-07-19T19:38:35.162149Z",
"url": "https://files.pythonhosted.org/packages/d7/e2/249ffedb5116c1d197993448972398f7f11274a15e33aec2473a8dfc2e87/fastapi_postman_exporter-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "7a986d73d6d23278371f642683a1554681bd470e13d78712e6ce6ff40d402418",
"md5": "8c0771d5f765b9b64772610013c01e19",
"sha256": "a7ea955700b1508a652c67262f16f62692d15f8b111de3afde904b744935eb9f"
},
"downloads": -1,
"filename": "fastapi_postman_exporter-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "8c0771d5f765b9b64772610013c01e19",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9136,
"upload_time": "2025-07-19T19:38:36",
"upload_time_iso_8601": "2025-07-19T19:38:36.437186Z",
"url": "https://files.pythonhosted.org/packages/7a/98/6d73d6d23278371f642683a1554681bd470e13d78712e6ce6ff40d402418/fastapi_postman_exporter-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-19 19:38:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Akshya107",
"github_project": "fastapi-postman-exporter",
"github_not_found": true,
"lcname": "fastapi-postman-exporter"
}