requests library with timeouts from django app

I am pretty new to django, so please excuse me if this is a stupid question.

Django has loads of hooks to aid setting up libraries being used, which is great, but I’m struggling with finding a good way to integrate the requests library (

My situation:

I am making requests to another micro-service, from my django app, using requests.get(...), that works fine. I now want to add a default timeout to any requests, I found this blog that explains how and gives code on how to do it. My problem is the bit that integrates the adapter. The code there you need to create a session, then add the adapter to it, but that isn’t really the Django way, at least that is what I thought. I thought there might be a way to set this up in my file, so that any request I make in future, will have the default timeout, set in the adapter. I have not found anything and am thinking I need to have some wrapper function that our requests use, instead of using request.get(...) directly, just hoping there is a more django’y way of doing this.

Has anyone done this already and can point me towards some resource(s) to read.

Thanks in advance for any help.


<opinion>Are you really making that many different request.get calls in different locations in your project to make it worth the additional “cognitive load” to add this type of feature?

My first reaction is that it’s over-engineering a solution for a really simple issue. If I were looking at this, I’d be creating the simplest solution that works. The wrapper function is the choice I would make. </opinion>


Your right, I only have a couple of calls, so a little helper function is what I was going to do, if there wasn’t a more django’y way.

Thanks for you prompt response ken.

I won’t argue - there may well be a more Django-ish way of handling this. But I guess my point would be is that it wouldn’t matter to me if there was, for something this small.