Metadata-Version: 2.5
Name: routeman
Version: 0.1.0
Summary: Generate Postman collections from Django, Django REST framework, Flask and FastAPI projects - no OpenAPI or documentation library needed.
Project-URL: Homepage, https://swastik.ai
Project-URL: Documentation, https://pypi.org/project/routeman/
Author-email: Swastik Tech Solutions Pvt Ltd <contact@swastik.ai>
Maintainer-email: Swastik Tech Solutions Pvt Ltd <contact@swastik.ai>
License-Expression: MIT
License-File: LICENSE
Keywords: api,api-testing,cli,django,django-rest-framework,fastapi,flask,openapi,postman,postman-collection
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Framework :: Django
Classifier: Framework :: FastAPI
Classifier: Framework :: Flask
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Documentation
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.9
Requires-Dist: tomli>=1.1; python_version < '3.11'
Description-Content-Type: text/markdown

# routeman

**Generate a complete Postman collection from your Django, Django REST framework, Flask or FastAPI project with one command. You don't need OpenAPI, drf-spectacular, flasgger or any other documentation library.**

```bash
pip install routeman
cd your-project
routeman generate
```

```
✓ django: 24 requests (11 GET, 9 POST, 2 PUT, 1 PATCH, 1 DELETE), 1 websocket(s)
✓ auth: bearer (login: POST /api/v1/auth/token/)
✓ wrote postman/your-project-api.postman_collection.json
✓ wrote postman/your-project-api.local.postman_environment.json
  done in 0.26s - import the files in Postman (File → Import)
```

routeman loads your application the same way your server does and reads its real routes. You get every endpoint with its methods, path variables, query parameters and request bodies filled with working example values, plus authentication and a login request that saves the token for you. Import the two files into Postman and start sending requests.

Made by [Swastik Tech Solutions Pvt Ltd](https://swastik.ai).

---

## What you get

| | |
|---|---|
| **Every route** | Every URL the framework would serve, including nested `include()`s, routers, blueprints and mounted routers. Admin and static files are left out. |
| **Folders** | One folder per Django app, Flask blueprint or FastAPI tag, with sub-folders per resource. |
| **Request bodies** | JSON, `x-www-form-urlencoded` or `multipart/form-data` (file uploads become Postman file pickers), with example values that pass validation: they respect choices, min/max, lengths, regex patterns and field names (`email` gets `user@example.com`). |
| **Path variables** | `{{product_id}}`, `{{user_id}}`… stored in the environment and named after the resource, typed from the model (UUID or integer). |
| **Query parameters** | Pagination, search, ordering, filters, plus anything your code reads from `request.GET`, `query_params` or `args`. Optional ones are added but switched off. |
| **Authentication** | Detected automatically: Bearer/JWT, `Token` (DRF authtoken, Knox), Basic, API key, or session. Public endpoints are set to *No Auth*. |
| **Login script** | The login or token request saves `access_token` / `refresh_token` from its response. Refresh endpoints send the refresh token. |
| **Environments** | One environment file per server (local, staging, production…). |
| **Smoke test** | Every request checks that the response is not a 5xx, so the Collection Runner or Newman can smoke-test the whole API. |
| **Docs** | Each request's description shows the view's docstring and a table of fields (type, required, allowed values). WebSocket routes (Django Channels, FastAPI) are listed in the collection description. |

## How it reads your project (no schema needed)

| Framework | Routes from | Bodies and parameters from |
|---|---|---|
| **Django REST framework** | the URLconf (routers, viewsets, `@action`, APIViews, `@api_view`) | serializers (nested, `many=True`, relations, choices, files, read-only fields skipped), the serializers a view builds itself (`Serializer(data=request.data)`), pagination, `SearchFilter`, `OrderingFilter`, django-filter `filterset_fields`/`filterset_class`, `permission_classes`, `authentication_classes` |
| **Django** | the URLconf (`path`, `re_path`, `include`, class-based and function views) | `form_class` and `ModelForm`s, `require_http_methods`, `request.method` checks, and the view code: `request.POST`, `request.GET`, `request.FILES`, `json.loads(request.body)` |
| **Flask** | `app.url_map` (blueprints, `MethodView`, Flask-RESTful resources) | the view code (`request.json`, `get_json()`, `form`, `args`, `files`), marshmallow schemas, flask-smorest `@arguments`, Pydantic models, `@jwt_required`, `@login_required`, Flask-HTTPAuth |
| **FastAPI** | FastAPI's built-in OpenAPI document, plus routes with `include_in_schema=False` | Pydantic models, `Query`/`Form`/`File`/`Header`, `Depends()` security (OAuth2, HTTP Bearer, API key) |

When a view declares no serializer, form or schema, routeman reads the view's source code to find the fields it uses, for example `request.data.get('email')`, `data['name']`, `int(request.data.get('age', 0))` or `request.args.get('page', type=int)`. Those requests are marked so you know the list was inferred.

## Commands

```bash
routeman generate                 # write postman/<name>.postman_collection.json + environments
routeman generate --stdout        # print the collection instead
routeman routes                   # list what routeman found (method, path, auth, body fields)
routeman init                     # save the project details in routeman.toml (asks a few questions)
routeman --version
```

Useful options (all optional; routeman detects everything it can):

| Option | Meaning |
|---|---|
| `-C, --project DIR` | project folder (default: current folder) |
| `-f, --framework` | `django`, `flask` or `fastapi` |
| `-a, --app` | Django settings module (`mysite.settings`) or Flask/FastAPI app: `main:app`, `myapp:create_app()` |
| `-n, --name` | collection name |
| `-o, --output DIR` | output folder (default `postman`) |
| `-b, --base-url URL` | base URL of the `local` environment |
| `-e, --env NAME=URL` | add an environment, e.g. `-e production=https://api.example.com` (repeatable) |
| `-x, --exclude REGEX` | leave out paths, e.g. `-x '^/internal/'` (repeatable) |
| `--auth TYPE` | force `none`, `bearer`, `token`, `basic`, `apikey` or `session` |
| `--login PATH` | the POST route whose response contains the token |
| `--env-file FILE` | environment variables your settings need (default: `.env` if present) |

## Configuration file

`routeman init` writes `routeman.toml`. You can also put the same table under `[tool.routeman]` in `pyproject.toml`:

```toml
[routeman]
name = "Shop API"
framework = "django"
app = "shop.settings"          # Flask/FastAPI: "main:app" or "factory:create_app()"
output = "postman"
exclude = ["^/internal/"]

[routeman.environments]
local = "http://localhost:8000"
production = "https://api.example.com"

[routeman.auth]
type = "auto"                  # auto | none | bearer | token | basic | apikey | session
login = "/api/token/"          # optional: detected automatically
# prefix = "JWT"               # Authorization: JWT <token>
# header = "X-API-Key"         # header for apikey auth
```

Command-line options override the file.

## Requirements

* Python 3.9 or newer, with **no dependencies** besides `tomli` on Python < 3.11.
* Run routeman from the virtualenv your project runs in, because it imports your app to read the routes. Importing is read-only: routeman never touches your database or sends requests.
* If your settings need environment variables, keep them in `.env` (loaded automatically) or pass `--env-file`.

Tested with Django 3.2 to 6, Django REST framework 3.12+, Flask 2.0 to 3.x, FastAPI 0.95+ with Pydantic v1 and v2.

## Tips

* Run **Login** first in Postman. The token is stored and sent with every other request.
* Set the `{{…_id}}` variables in the environment from list responses, or edit the request.
* Django form views (session/CSRF): send any GET first so Postman receives the `csrftoken` cookie. The collection copies it into the `X-CSRFToken` header for you.
* Regenerate whenever your API changes. Collection and request ids are stable, so importing again replaces the previous version.

## License

MIT © [Swastik Tech Solutions Pvt Ltd](https://swastik.ai)
