Tuesday, August 23, 2016

Curlify Your Python Requests Objects

I love things that are simple and useful. Egor's Curlify Python module is one of these gems I saw this morning.

I already have a Python script that demonstrate A10 Network's AXAPI using the Requests package:


With this package, I changed exactly one line of code wherever I wanted to give an curl example of the same operation.

For example, after importing the curlify file, instead of printing out r.content in line 23, I just print out curlify.to_curl(r.reqeust) and boom, I have a curl command I can pass to people! How cool is that?

7 import requests, json, curlify
 17 # Acquire athorization token
 18 auth_headers = {'content-type': 'application/json'}
 19 auth_payload = {"credentials": {"username": "admin", "password": "a10"}}
 20 auth_endpoint = '/axapi/v3/auth'
 21 url = base_url + auth_endpoint
 22 r = requests.post(url, data=json.dumps(auth_payload), headers=auth_headers, verify=Fa    lse)
 23 print(curlify.to_curl(r.request))

Of course, you get the most out of it if you use Requests already (who isnt?) and you can just write it in Requests. When somebody else wants a simpler operation, say using just curl, that you can just easily dish it out to them in less than 5 minutes.

This is my final output from the same Python file above:

The only different from the plain output is I added a '-k' to the curl operation because I have a self-signed certificate on the A10 Thunder TPS.

Nice tool, nice output, no sweat. My type of thing. :)


  1. This comment has been removed by the author.

  2. python: very good information. we need learn from real time examples and for this we choose good training institute, we refer Apponix Technologies which offers free demo classes!!

  3. Any developer or IT architect would have an advantage in presentation Python in their resume since this would exhibit them an edge more than the other people who are just known with sure basic programming dialects, for example, HTML and CSS. machine learning certification

  4. With this package, I changed exactly one line of code wherever I wanted to give an curl example of the same operation. C_THR86_1905 exam question

  5. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    3D Scanning Services
    3D Laser Scanning Targets

  6. Betway: NJ Casino, Hotel, Restaurant | JM Hub
    Come out and play in 의정부 출장마사지 New Jersey's premiere New Jersey casino and hotel! 경산 출장안마 We 광양 출장마사지 have a 과천 출장샵 variety of exciting games, top dining options, 광양 출장마사지 and great promotions.