Skip to content

Improve "import requests" time by delaying ssl context preload #6906

@gregory-shklover

Description

@gregory-shklover

Requests is not accepting feature requests at this time.

In requests/adapters.py there is initialization for _preloaded_ssl_context in global scope.
In corporate environment this operation consumes significant portion of the "import requests" time.

Wrapping this initialization into a function that is called where this context is actually needed would eliminate the overhead.

Estimates based on my machine:

original:

$ time python -c 'import requests'
real 0m0.918s
...

with a function wrapper:

$ time python -c 'import requests'
real 0m0.356s
...

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions