Skip to content

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

Open

Description

@francescobianco

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.

Activity

  1. IlyasFardaouix commented on Mar 19, 2026

    @IlyasFardaouix

    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?

  2. francescobianco commented on Mar 24, 2026

    @francescobianco
    MemberAuthor

    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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions