High Level Usage#
If you want to cover on the common usage cases, you can use our high level implementations that already take care of the recommended protocol usage and rate limits.
Analyzing a host#
import asyncio
from ssllabs import Ssllabs
async def analyze():
ssllabs = Ssllabs()
return await ssllabs.analyze(host="ssllabs.com")
asyncio.run(analyze())
This will give you a Host object as dataclass. This call runs quite long as it takes time to run all tests. You probably know that from using the webinterface.
If you don’t need a fresh result on every run, you can allow using SSL Labs’ cache. This will speed up the tests if there are cached results. The maximum cache validity can be set in full hour steps.
import asyncio
from ssllabs import Ssllabs
async def analyze():
ssllabs = Ssllabs()
return await ssllabs.analyze(host="ssllabs.com", from_cache=True, max_age=1)
asyncio.run(analyze())
Last but not least you can specify if you want to publish your results on the SSL Labs website and to proceed with the analysis even if the certificate doesn’t match the hostname.
import asyncio
from ssllabs import Ssllabs
async def analyze():
ssllabs = Ssllabs()
return await ssllabs.analyze(host="ssllabs.com", publish=True, ignore_mismatch=True)
asyncio.run(analyze())
By default, results are not published, the assessment will not continue if the certificate doesn’t match the hostname and the cache is not used.
Check availability of the SSL Labs servers#
import asyncio
from ssllabs import Ssllabs
async def availability():
ssllabs = Ssllabs()
return await ssllabs.availability()
asyncio.run(availability())
This will give you True if the servers are up and running, otherwise False. It will also report False if you exceeded your rate limits.
Retrieve API information#
import asyncio
from ssllabs import Ssllabs
async def info():
ssllabs = Ssllabs()
return await ssllabs.info()
asyncio.run(info())
This will give you an Info object as dataclass.
Retrieve root certificates#
import asyncio
from ssllabs import Ssllabs, TrustStore
async def root_certs():
ssllabs = Ssllabs()
return await ssllabs.root_certs(trust_store=TrustStore.MOZILLA)
asyncio.run(root_certs())
This will give you a string containing the latest root certificates used for trust validation. By default it used the certificates provided by Mozilla. You can choose a differently store by changing trust_store to one of the supported trust stores.
Supported trust stores are:
MOZILLA
MACOS
ANDROID
JAVA
WINDOWS
Retrieve known status codes#
import asyncio
from ssllabs import Ssllabs
async def status_codes():
ssllabs = Ssllabs()
return await ssllabs.status_codes()
asyncio.run(status_codes())
This will give you a StatusCodes object as dataclass.