Skip to main content

Lib that generates postman collections out of requests

Project description

request2postman


Small lib that allows you to automatically generate postman collections out of python requests lib

Using requests hooks

from request2postman import Collection, request_to_postman_hook
from requests import Session


collection = Collection("some_name")
with Session() as session:
    session.hooks["response"].append(request_to_postman_hook(collection))
    session.get("https://httpbin.org/basic-auth/user/pass")
    session.post("https://httpbin.org/basic-auth/user/pass", json={"key": "value"})

with open("collection.json", "w") as file:
    file.write(collection.json)

Using Request object directly

from request2postman import Collection
import requests


resp1 = requests.get("https://httpbin.org/basic-auth/user/pass")
resp2 = requests.post("https://httpbin.org/basic-auth/user/pass", json={"key": "value"})

collection = Collection("some_name")
collection.add_request(resp1.request, name="request1")
collection.add_request(resp2.request)

with open("collection.json", "w") as file:
    file.write(collection.json)

Result

{
  "info": {
    "_postman_id": "6fde81f7-6cb8-4cde-bf89-a2b476ed794f",
    "name": "some_name",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "event": [],
  "variable": [],
  "item": [
    {
      "id": "79731ba3-25e5-4149-a975-20c4e7929728",
      "name": "request1",
      "response": [],
      "event": [],
      "request": {
        "url": {
          "raw": "https://httpbin.org/basic-auth/user/pass",
          "protocol": "https",
          "path": [
            "basic-auth",
            "user",
            "pass"
          ],
          "host": [
            "httpbin",
            "org"
          ],
          "query": [],
          "variable": []
        },
        "header": [],
        "method": "GET"
      }
    },
    {
      "id": "0a75dc4e-16ef-468e-a903-412832fd5749",
      "name": "/basic-auth/user/pass",
      "response": [],
      "event": [],
      "request": {
        "url": {
          "raw": "https://httpbin.org/basic-auth/user/pass",
          "protocol": "https",
          "path": [
            "basic-auth",
            "user",
            "pass"
          ],
          "host": [
            "httpbin",
            "org"
          ],
          "query": [],
          "variable": []
        },
        "header": [
          {
            "key": "Content-Length",
            "value": "16"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "method": "POST",
        "body": {
          "mode": "raw",
          "raw": "{\"key\": \"value\"}"
        }
      }
    }
  ]
}

You can skip some headers to avoid posting Authorization headers or any other private headers with others

from request2postman import Collection
import requests


collection = Collection("some_name", skip_headers=["Authorization"])
resp1 = requests.get("https://httpbin.org/basic-auth/user/pass")
resp2 = requests.post("https://httpbin.org/basic-auth/user/pass", json={"key": "value"})
collection.add_request(resp1.request)
collection.add_request(resp2.request)

with open("collection.json", "w") as file:
    file.write(collection.json)

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

request2postman-0.1.2.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file request2postman-0.1.2.tar.gz.

File metadata

  • Download URL: request2postman-0.1.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for request2postman-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f528487627668e594dd7ff002fff9deb240d7fe2c3fc79e12eb30baa86771423
MD5 3d6751da080cebfaeca92f6df60987f4
BLAKE2b-256 b8aca433439cefb2c471c70610ee82162f3b8794c6fb513e732912498e8a02bd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page