Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python RESTful client like Guzzle from PHP

What Python library provides RESTful client interface like:

client = Client(
    base_url="http://example.com/api/1/", auth=("user", "password"),
    cookie=cookielib.FileCookieJar('cookie-file'))
result = client.get('group', params={"groupname": "some_group", "expand": "users"})
result.json()
like image 343
vladkens Avatar asked Feb 12 '15 13:02

vladkens


People also ask

Is Guzzle better than cURL?

Guzzle can be used with any HTTP handler like cURL, socket, PHP's stream wrapper. Guzzle by default uses cURL as Http handler. Why use Guzzle Instead of cURL in PHP? It provides easy user interface.

What is GuzzleHTTP PHP?

Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services. Simple interface for building query strings, POST requests, streaming large uploads, streaming large downloads, using HTTP cookies, uploading JSON data, etc...

Does PHP Guzzle use cURL?

Does Guzzle require cURL? ¶ No. Guzzle can use any HTTP handler to send requests.

What is Guzzle HTTP client laravel?

Guzzle is a PHP HTTP client that makes sending HTTP requests with data and headers easy. It also makes integrating with web services simple. It offers a simple yet powerful interface for sending POST requests, streaming massive uploads and downloads, using HTTP cookies, and uploading JSON data, among other things.


1 Answers

Not exactly like that, but you likely want requests

edit: since you want to ommit your base URL, try something like this:

base_url = "http://example.com/"
def requests_get(url, *args, **kwargs):
    return requests.get(base_url + url,*args,**kwargs)

An alternative solution is to subclass requests.Session as shown in this answer.

like image 126
L3viathan Avatar answered Oct 27 '22 23:10

L3viathan