Skip to main content

Verify certificates using native system trust stores

Reason this release was yanked:

Doesn't work for CPython 3.13, upgrade to 0.9.1

Project description

Truststore

PyPI CI

Truststore is a library which exposes native system certificate stores (ie "trust stores") through an ssl.SSLContext-like API. This means that Python applications no longer need to rely on certifi as a root certificate store. Native system certificate stores have many helpful features compared to a static certificate bundle like certifi:

  • Automatically update certificates as new CAs are created and removed
  • Fetch missing intermediate certificates
  • Check certificates against certificate revocation lists (CRLs) to avoid monster-in-the-middle (MITM) attacks
  • Managed per-system rather than per-application by a operations/IT team
  • PyPI is no longer a CA distribution channel 🥳

Right now truststore is a stand-alone library that can be installed globally in your application to immediately take advantage of the benefits in Python 3.10+. Truststore has also been integrated into pip as an opt-in method for verifying HTTPS certificates with truststore instead of certifi.

Long-term the hope is to make truststore the default way to verify HTTPS certificates in pip and to add this functionality into Python itself. Wish us luck!

Installation

Truststore is installed from PyPI with pip:

$ python -m pip install truststore

Truststore requires Python 3.10 or later and supports the following platforms:

User Guide

Warning PLEASE READ: inject_into_ssl() must not be used by libraries or packages as it will cause issues on import time when integrated with other libraries. Libraries and packages should instead use truststore.SSLContext directly which is detailed below.

The inject_into_ssl() function is intended only for use in applications and scripts.

You can inject truststore into the standard library ssl module so the functionality is used by every library by default. To do so use the truststore.inject_into_ssl() function:

import truststore
truststore.inject_into_ssl()

# Automatically works with urllib3, requests, aiohttp, and more:
import urllib3
http = urllib3.PoolManager()
resp = http.request("GET", "https://example.com")

import aiohttp
http = aiohttp.ClientSession()
resp = await http.request("GET", "https://example.com")

import requests
resp = requests.get("https://example.com")

If you'd like finer-grained control or you're developing a library or package you can create your own truststore.SSLContext instance and use it anywhere you'd use an ssl.SSLContext:

import ssl
import truststore

ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)

import urllib3
http = urllib3.PoolManager(ssl_context=ctx)
resp = http.request("GET", "https://example.com")

You can read more in the user guide in the documentation.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

truststore-0.9.0.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

truststore-0.9.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file truststore-0.9.0.tar.gz.

File metadata

  • Download URL: truststore-0.9.0.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.9

File hashes

Hashes for truststore-0.9.0.tar.gz
Algorithm Hash digest
SHA256 8876ce1ece1187f523d1ac0c975aa91cf2320c6cd7f20c3a35a7811f49ec2e37
MD5 0514941f828cdeab9bea0e1dd7a72af3
BLAKE2b-256 4628e7a810115227b7c4953d9db9f1312441e708dc31d1fa6975f5a19d6bed62

See more details on using hashes here.

File details

Details for the file truststore-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: truststore-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.9

File hashes

Hashes for truststore-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 87ec7718ae0c0c9f100a040b86a8a3c93e258fb03e31bd3a8cc45948de2a3805
MD5 b294272cb3a0d33a53f6f4bfd5e479b6
BLAKE2b-256 5751778c9a9535a39b14949ca1901e2417da2e97b46302f2708fdd53bcc9c61b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page