openapi-python-sdk icon indicating copy to clipboard operation
openapi-python-sdk copied to clipboard

No way to inject custom requests.Session (Django application)

Open francescobianco opened this issue 8 months ago • 2 comments

No way to inject custom requests.Session (Django application)

Description
In Django projects, it's common to reuse a configured requests.Session, but the SDK does not allow it.

Code snippet

import requests
from openapi_sdk import Client

session = requests.Session()
session.headers.update({"User-Agent": "my-app"})

client = Client("token")
response = client.request("GET", base_url, "/advance", params={})

Issue
Cannot pass custom session for connection pooling and retries.

francescobianco avatar Mar 18 '26 14:03 francescobianco

I think the issue is due to the fact that the Client class in openapi_python_sdk is using the requests library's default session internally, and doesn't provide a way to inject a custom session. This is because the Client class is using the requests.Session object to manage connection pooling and retries. To fix this, you could try creating a custom requests.Session object and passing it to the Client constructor, like so: client = Client(token=token, session=session). However, I'd like to confirm whether the Client class is designed to accept a custom session object. Can you clarify if the Client class is intended to be extensible in this way?

IlyasFardaouix avatar Mar 19 '26 04:03 IlyasFardaouix

That’s a great observation, thanks @IlyasFardaouix for the detailed breakdown.

We’re also experimenting with Django on our side, so this kind of feedback is super valuable. The Client isn’t fully designed yet with that level of extensibility in mind, but it’s definitely something we’re considering as we evolve the API.

Also — since you’re quite active on this — if you’d like to put together a small demo showing how to use the library within a Django setup, we’d be happy to review it and potentially publish it officially on our GitHub channels.

Let us know if that sounds interesting 👍

francescobianco avatar Mar 24 '26 10:03 francescobianco