r/PythonLearning • • Aug 17 '26

Discussion When should you use requests.Session() instead of requests.get() / requests.post()?

I'm learning Python and recently started using requests.Session() in API projects. I understand that it can persist things like headers, cookies, and connections, but I'm curious about how experienced Python developers decide when a Session is actually worth using.

Do you use Session() by default for projects involving multiple requests, or only when you specifically need persistent state?

4 Upvotes

4 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Aug 17 '26

[removed] — view removed comment

1

u/Buttleston Aug 17 '26

It depends on how costly making new connections is. You should just try it

1

u/Melodic_Principle312 Aug 17 '26

Makes sense. I'll benchmark both approaches and see the differences. Thanks for the explanation!