Skip to main content

This library adds PKCS#12 support to the Python requests library.

It is a clean implementation: it uses neither monkey patching nor unencrypted temporary files. Instead, it is integrated into requests as recommended by its authors: creating a custom TransportAdapter, which provides a custom SSLContext.

This library is meant to be a transitional solution until this functionality is provided by requests directly. However, that will take some time. See the corresponding issue for more details.

Usage

For simple one-off requests you can use this library as a drop-in replacement for the requests library:

from requests_pkcs12 import get

r = get('https://example.com/test', pkcs12_filename='clientcert.p12', pkcs12_password='correcthorsebatterystaple')

If you are using requests sessions, use the Pkcs12Adapter:

from requests import Session
from requests_pkcs12 import Pkcs12Adapter

with Session() as s:
    s.mount('https://example.com', Pkcs12Adapter(pkcs12_filename='clientcert.p12', pkcs12_password='correcthorsebatterystaple'))
    r = s.get('https://example.com/test')

Installation

This library is available as PyPI package:

pip install requests-pkcs12

Alternatively, you can retrieve the latest development version via Git:

git clone https://github.com/m-click/requests_pkcs12

Arguments

The following keyword arguments are supported:

  • pkcs12_filename is a byte string or unicode string that contains the file name of the encrypted PKCS#12 certificate.

    • Either this argument or pkcs12_data must be provided.

  • pkcs12_data is a byte string that contains the encrypted PKCS#12 certificate data.

    • Either this argument or pkcs12_filename must be provided.

  • pkcs12_password is a byte string or unicode string that contains the password.

    • This argument must be provided whenever pkcs12_filename or pkcs12_data is provided.

  • ssl_protocol is a protocol version from the ssl library.

    • This argument is optional and defaults to ssl.PROTOCOL_TLS.

If you use these parameters, don’t use the built-in cert parameter of requests at the same time. However, do use the other parameters. In particular, do use the “verify” parameter to verify the server-side certificate.

Release files for requests-pkcs12 1.27

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for requests-pkcs12 1.27
File Size Uploaded
requests_pkcs12-1.27.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for requests-pkcs12 1.27
File Interpreter ABI Platform
requests_pkcs12-1.27-py3-none-any.whl Python 3 none any Details

Total release size: 11.5 kB

Release files / requests_pkcs12-1.27.tar.gz

Download URL requests_pkcs12-1.27.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
258b320bac8773b5c310a92382e3cb3b1fece1d5cc4fd4a6f93a70b009154ea5
BLAKE2b-256 checksum
How to use checksums
fa7765d569357b62f338bd5dced636eddfc0fdbdde8ddca68fa142db97d33ea6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / requests_pkcs12-1.27-py3-none-any.whl

Download URL requests_pkcs12-1.27-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d8c350ec050dbc806b097497a3f1ce8f9f93b439f30151ed0c6a1f4b27392fc3
BLAKE2b-256 checksum
How to use checksums
246c952e92ab1750ac4e85364403243b315269c7d68bc6551d13bfb8fc701b9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

1.27 This release

2 release files

1.26

2 release files

1.25

2 release files

1.24

2 release files

1.23

2 release files

1.22

2 release files

1.21

2 release files

1.20

2 release files

1.19

2 release files

1.18

2 release files

1.17

2 release files

1.16

2 release files

1.15

2 release files

1.14

2 release files

1.13

2 release files

1.12

2 release files

1.11

2 release files

1.10

2 release files

1.9

2 release files

1.8

2 release files

1.7

2 release files

1.6

2 release files

1.5

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page