Install tls-client
masterInstall the library using pip:
pip install tls-clientrepository·master·Indexed 21 days ago
https://github.com/florianregaz/python-tls-clientAn advanced HTTP library that extends requests by integrating tls-client to mimic specific browser and device TLS fingerprints. It allows developers to bypass TLS fingerprinting protections using preset client_identifiers for Chrome, Firefox, Opera, Safari, iOS, iPadOS, and Android, or by configuring custom parameters such as ja3_string, h2_settings, and supported_signature_algorithms.
Install the library using pip:
pip install tls-clientWhen bundling the library into an executable using Pyinstaller or Pyarmor, you must manually include the binary dependencies. Use the --add-binary flag with the appropriate path for your platform:
--add-binary '{path_to_library}/tls_client/dependencies/tls-client-x86.so:tls_client/dependencies'--add-binary '{path_to_library}/tls_client/dependencies/tls-client-amd64.so:tls_client/dependencies'--add-binary '{path_to_library}/tls_client/dependencies/tls-client-x86.dylib:tls_client/dependencies'--add-binary '{path_to_library}/tls_client/dependencies/tls-client-arm64.dylib:tls_client/dependencies'--add-binary '{path_to_library}/tls_client/dependencies/tls-client-64.dll;tls_client/dependencies'For granular control over the TLS handshake, you can pass specific fingerprinting parameters to tls_client.Session. This allows you to manually define JA3 strings, HTTP/2 settings, supported signature algorithms, and more.
Key parameters include:
ja3_string: A custom JA3 fingerprint string.h2_settings: A dictionary of HTTP/2 settings (e.g., HEADER_TABLE_SIZE, MAX_CONCURRENT_STREAMS).h2_settings_order: A list defining the order of HTTP/2 settings.supported_signature_algorithms: A list of allowed signature algorithms.supported_versions: A list of supported TLS versions (e.g., "1.3", "1.2", or "GREASE").key_share_curves: A list of supported key share curves.cert_compression_algo: The certificate compression algorithm (e.g., "brotli").pseudo_header_order: The order of HTTP/2 pseudo-headers.header_order: The order of HTTP headers.connection_flow: A numeric value for connection flow control.import tls_client
session = tls_client.Session(
ja3_string="771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-17513,29-23-24,0",
h2_settings={
"HEADER_TABLE_SIZE": 65536,
"MAX_CONCURRENT_STREAMS": 1000,
"INITIAL_WINDOW_SIZE": 6291456,
"MAX_HEADER_LIST_SIZE": 262144
},
h2_settings_order=[
"HEADER_TABLE_SIZE",
"MAX_CONCURRENT_STREAMS",
"INITIAL_WINDOW_SIZE",
"MAX_HEADER_LIST_SIZE"
],
supported_signature_algorithms=[
"ECDSAWithP256AndSHA256",
"PSSWithSHA256",
"PKCS1WithSHA256",
"ECDSAWithP384AndSHA384",
"PSSWithSHA384",
"PKCS1WithSHA384",
"PSSWithSHA512",
"PKCS1WithSHA512",
],
supported_versions=["GREASE", "1.3", "1.2"],
key_share_curves=["GREASE", "X25519"],
cert_compression_algo="brotli",
pseudo_header_order=[
":method",
":authority",
":scheme",
":path"
],
connection_flow=15663105,
header_order=[
"accept",
"user-agent",
"accept-encoding",
"accept-language"
]
)
res = session.post(
"https://www.example.com/",
headers={
"key1": "value1",
},
json={
"key1": "key2"
}
)The tls_client.Session class allows you to mimic specific browser or device TLS fingerprints using the client_identifier parameter. This is useful for bypassing TLS fingerprinting. The syntax is inspired by the requests library.
Available identifiers include:
chrome_103, chrome_104, chrome_105, chrome_106, chrome_107, chrome_108, chrome109, Chrome110, chrome111, chrome112, chrome_116_PSK, chrome_116_PSK_PQ, chrome_117, chrome_120firefox_102, firefox_104, firefox108, Firefox110, firefox_117, firefox_120opera_89, opera_90safari_15_3, safari_15_6_1, safari_16_0safari_ios_15_5, safari_ios_15_6, safari_ios_16_0safari_ios_15_6okhttp4_android_7, okhttp4_android_8, okhttp4_android_9, okhttp4_android_10, okhttp4_android_11Note: More identifiers can be found in the project's settings.py.
import tls_client
session = tls_client.Session(
client_identifier="chrome112",
random_tls_extension_order=True
)
res = session.get(
"https://www.example.com/",
headers={
"key1": "value1",
},
proxy="http://user:password@host:port"
)