request2postman


Namerequest2postman JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/Ander813
SummaryLib that generates postman collections out of requests
upload_time2023-01-12 23:41:23
maintainer
docs_urlNone
authorEgor Gondurov
requires_python
licenseMIT
keywords requests postman generate postman collections
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # request2postman
___
Small lib that allows you to automatically 
generate postman collections out of python requests lib
### Using requests hooks
```python
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
```python
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
```json
{
  "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
```python
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)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Ander813",
    "name": "request2postman",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "requests,postman,generate postman collections",
    "author": "Egor Gondurov",
    "author_email": "ander_the_wood@mail.ru",
    "download_url": "https://files.pythonhosted.org/packages/b8/ac/a433439cefb2c471c70610ee82162f3b8794c6fb513e732912498e8a02bd/request2postman-0.1.2.tar.gz",
    "platform": null,
    "description": "# request2postman\n___\nSmall lib that allows you to automatically \ngenerate postman collections out of python requests lib\n### Using requests hooks\n```python\nfrom request2postman import Collection, request_to_postman_hook\nfrom requests import Session\n\n\ncollection = Collection(\"some_name\")\nwith Session() as session:\n    session.hooks[\"response\"].append(request_to_postman_hook(collection))\n    session.get(\"https://httpbin.org/basic-auth/user/pass\")\n    session.post(\"https://httpbin.org/basic-auth/user/pass\", json={\"key\": \"value\"})\n\nwith open(\"collection.json\", \"w\") as file:\n    file.write(collection.json)\n```\n### Using Request object directly\n```python\nfrom request2postman import Collection\nimport requests\n\n\nresp1 = requests.get(\"https://httpbin.org/basic-auth/user/pass\")\nresp2 = requests.post(\"https://httpbin.org/basic-auth/user/pass\", json={\"key\": \"value\"})\n\ncollection = Collection(\"some_name\")\ncollection.add_request(resp1.request, name=\"request1\")\ncollection.add_request(resp2.request)\n\nwith open(\"collection.json\", \"w\") as file:\n    file.write(collection.json)\n```\n\nResult\n```json\n{\n  \"info\": {\n    \"_postman_id\": \"6fde81f7-6cb8-4cde-bf89-a2b476ed794f\",\n    \"name\": \"some_name\",\n    \"schema\": \"https://schema.getpostman.com/json/collection/v2.1.0/collection.json\"\n  },\n  \"event\": [],\n  \"variable\": [],\n  \"item\": [\n    {\n      \"id\": \"79731ba3-25e5-4149-a975-20c4e7929728\",\n      \"name\": \"request1\",\n      \"response\": [],\n      \"event\": [],\n      \"request\": {\n        \"url\": {\n          \"raw\": \"https://httpbin.org/basic-auth/user/pass\",\n          \"protocol\": \"https\",\n          \"path\": [\n            \"basic-auth\",\n            \"user\",\n            \"pass\"\n          ],\n          \"host\": [\n            \"httpbin\",\n            \"org\"\n          ],\n          \"query\": [],\n          \"variable\": []\n        },\n        \"header\": [],\n        \"method\": \"GET\"\n      }\n    },\n    {\n      \"id\": \"0a75dc4e-16ef-468e-a903-412832fd5749\",\n      \"name\": \"/basic-auth/user/pass\",\n      \"response\": [],\n      \"event\": [],\n      \"request\": {\n        \"url\": {\n          \"raw\": \"https://httpbin.org/basic-auth/user/pass\",\n          \"protocol\": \"https\",\n          \"path\": [\n            \"basic-auth\",\n            \"user\",\n            \"pass\"\n          ],\n          \"host\": [\n            \"httpbin\",\n            \"org\"\n          ],\n          \"query\": [],\n          \"variable\": []\n        },\n        \"header\": [\n          {\n            \"key\": \"Content-Length\",\n            \"value\": \"16\"\n          },\n          {\n            \"key\": \"Content-Type\",\n            \"value\": \"application/json\"\n          }\n        ],\n        \"method\": \"POST\",\n        \"body\": {\n          \"mode\": \"raw\",\n          \"raw\": \"{\\\"key\\\": \\\"value\\\"}\"\n        }\n      }\n    }\n  ]\n}\n```\n___\n#### You can skip some headers to avoid posting Authorization headers or any other private headers with others\n```python\nfrom request2postman import Collection\nimport requests\n\n\ncollection = Collection(\"some_name\", skip_headers=[\"Authorization\"])\nresp1 = requests.get(\"https://httpbin.org/basic-auth/user/pass\")\nresp2 = requests.post(\"https://httpbin.org/basic-auth/user/pass\", json={\"key\": \"value\"})\ncollection.add_request(resp1.request)\ncollection.add_request(resp2.request)\n\nwith open(\"collection.json\", \"w\") as file:\n    file.write(collection.json)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Lib that generates postman collections out of requests",
    "version": "0.1.2",
    "split_keywords": [
        "requests",
        "postman",
        "generate postman collections"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b8aca433439cefb2c471c70610ee82162f3b8794c6fb513e732912498e8a02bd",
                "md5": "3d6751da080cebfaeca92f6df60987f4",
                "sha256": "f528487627668e594dd7ff002fff9deb240d7fe2c3fc79e12eb30baa86771423"
            },
            "downloads": -1,
            "filename": "request2postman-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "3d6751da080cebfaeca92f6df60987f4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4691,
            "upload_time": "2023-01-12T23:41:23",
            "upload_time_iso_8601": "2023-01-12T23:41:23.166395Z",
            "url": "https://files.pythonhosted.org/packages/b8/ac/a433439cefb2c471c70610ee82162f3b8794c6fb513e732912498e8a02bd/request2postman-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-12 23:41:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "request2postman"
}
        
Elapsed time: 0.03127s