Advanced HTTP Library
Python-TLS-Client
Python-TLS-Client is an advanced HTTP library based on requests and tls-client.Installation
pip install tls-client
Examples
The syntax is inspired by requests, so its very similar and there are only very few things that are different.Example 1 - Preset:
import tls_client
You can also use the following as client_identifier:
Chrome --> chrome103, chrome104, chrome105, chrome106, chrome107, chrome108, chrome109, Chrome110,
chrome111, chrome112, chrome116PSK, chrome116PSKPQ, chrome117, chrome_120
Firefox --> firefox102, firefox104, firefox108, Firefox110, firefox117, firefox120
Opera --> opera89, opera90
Safari --> safari153, safari1561, safari16_0
iOS --> safariios155, safariios156, safariios16_0
iPadOS --> safariios15_6
Android --> okhttp4android7, okhttp4android8, okhttp4android9, okhttp4android10, okhttp4android11,
okhttp4android12, okhttp4android13
#
more client identifiers can be found in settings.py
session = tls_client.Session( client_identifier="chrome112", randomtlsextension_order=True )
res = session.get( "https://www.example.com/", headers={ "key1": "value1", }, proxy="http://user:password@host:port" )
Example 2 - Custom:
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={ "HEADERTABLESIZE": 65536, "MAXCONCURRENTSTREAMS": 1000, "INITIALWINDOWSIZE": 6291456, "MAXHEADERLIST_SIZE": 262144 }, h2settingsorder=[ "HEADERTABLESIZE", "MAXCONCURRENTSTREAMS", "INITIALWINDOWSIZE", "MAXHEADERLIST_SIZE" ], supportedsignaturealgorithms=[ "ECDSAWithP256AndSHA256", "PSSWithSHA256", "PKCS1WithSHA256", "ECDSAWithP384AndSHA384", "PSSWithSHA384", "PKCS1WithSHA384", "PSSWithSHA512", "PKCS1WithSHA512", ], supported_versions=["GREASE", "1.3", "1.2"], keysharecurves=["GREASE", "X25519"], cert_compressi, pseudoheaderorder=[ ":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" } )
Pyinstaller / Pyarmor
If you want to pack the library with Pyinstaller or Pyarmor, make sure to add this to your command:Linux - Ubuntu / x86:
--add-binary '{pathtolibrary}/tlsclient/dependencies/tls-client-x86.so:tlsclient/dependencies'
Linux Alpine / AMD64:
--add-binary '{pathtolibrary}/tlsclient/dependencies/tls-client-amd64.so:tlsclient/dependencies'
MacOS M1 and older:
--add-binary '{pathtolibrary}/tlsclient/dependencies/tls-client-x86.dylib:tlsclient/dependencies'
MacOS M2:
--add-binary '{pathtolibrary}/tlsclient/dependencies/tls-client-arm64.dylib:tlsclient/dependencies'
Windows:
--add-binary '{pathtolibrary}/tlsclient/dependencies/tls-client-64.dll;tlsclient/dependencies'