{"id":1221,"library":"awscrt","title":"AWS Common Runtime (awscrt)","description":"awscrt provides Python 3 bindings for the AWS Common Runtime, a collection of modular C libraries designed for high-performance and a minimal footprint in AWS applications. It offers foundational capabilities like I/O, TLS, and common AWS protocols (e.g., MQTT, HTTP, S3). The library is actively maintained, with version 0.32.0 released on March 26, 2026, and typically follows a frequent release cadence for minor updates and bug fixes.","status":"active","version":"0.32.0","language":"python","source_language":"en","source_url":"https://github.com/awslabs/aws-crt-python","tags":["aws","cloud","runtime","iot","mqtt","s3","http","tls","performance"],"install":[{"cmd":"pip install awscrt","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Core I/O primitives like EventLoopGroup, HostResolver, and SocketOptions.","symbol":"io","correct":"from awscrt import io"},{"note":"MQTT client functionalities for connecting to AWS IoT Core.","symbol":"mqtt","correct":"from awscrt import mqtt"},{"note":"AWS client-side authentication including credential providers and signing.","symbol":"auth","correct":"from awscrt import auth"},{"note":"HTTP client and related functionalities, used for WebSocket connections and proxies.","symbol":"http","correct":"from awscrt import http"},{"note":"mqtt_connection_builder is part of the 'awsiot' package, which builds upon awscrt, not directly from awscrt itself.","wrong":"from awscrt import mqtt_connection_builder","symbol":"mqtt_connection_builder","correct":"from awsiot import mqtt_connection_builder"}],"quickstart":{"code":"import os\nimport time as t\nfrom awscrt import io, mqtt, auth, http\nfrom awsiot import mqtt_connection_builder\n\n# Replace with your AWS IoT Core endpoint, client ID, and certificate paths\nENDPOINT = os.environ.get(\"AWS_IOT_ENDPOINT\", \"YOUR_AWS_IOT_ENDPOINT\")\nCLIENT_ID = \"testDevice\"\nPATH_TO_CERTIFICATE = os.environ.get(\"AWS_IOT_CERT_PATH\", \"certificates/certificate.pem.crt\")\nPATH_TO_PRIVATE_KEY = os.environ.get(\"AWS_IOT_PRIVATE_KEY_PATH\", \"certificates/private.pem.key\")\nPATH_TO_AMAZON_ROOT_CA_1 = os.environ.get(\"AWS_IOT_ROOT_CA_PATH\", \"certificates/root-CA.pem\")\nTOPIC = \"test/topic\"\nMESSAGE = \"Hello from awscrt Python!\"\n\n# Spin up resources\nevent_loop_group = io.EventLoopGroup(1)\nhost_resolver = io.DefaultHostResolver(event_loop_group)\nclient_bootstrap = io.ClientBootstrap(event_loop_group, host_resolver)\n\nmqtt_connection = mqtt_connection_builder.mtls_from_path(\n    endpoint=ENDPOINT,\n    cert_filepath=PATH_TO_CERTIFICATE,\n    pri_key_filepath=PATH_TO_PRIVATE_KEY,\n    ca_filepath=PATH_TO_AMAZON_ROOT_CA_1,\n    client_bootstrap=client_bootstrap,\n    client_id=CLIENT_ID,\n    clean_session=False,\n    keep_alive_secs=30\n)\n\nprint(f\"Connecting to {ENDPOINT} with client ID '{CLIENT_ID}'...\")\nconnect_future = mqtt_connection.connect()\nconnect_future.result()\nprint(\"Connected!\")\n\nprint(f\"Publishing message to topic '{TOPIC}': {MESSAGE}\")\nmqtt_connection.publish(topic=TOPIC, payload=MESSAGE, qos=mqtt.QoS.AT_LEAST_ONCE).result()\nprint(\"Published!\")\n\n# Disconnect\ndisconnect_future = mqtt_connection.disconnect()\ndisconnect_future.result()\nprint(\"Disconnected!\")\n","lang":"python","description":"This quickstart demonstrates how to establish an MQTT connection to AWS IoT Core and publish a message using `awscrt`. It sets up basic I/O resources, builds an mTLS connection, connects, publishes a message, and then disconnects. Environment variables are used for sensitive credentials and endpoint configuration."},"warnings":[{"fix":"When using `multiprocessing`, set the start method to 'spawn' or 'forkserver' (e.g., `multiprocessing.set_start_method('spawn')`). If `fork` must be used, ensure all CRT resources are released and all CRT threads are joined before forking (e.g., via `awscrt.common.join_all_native_threads()`).","message":"`os.fork()` is unsafe when used with `awscrt` due to its use of background threads. In a forked child process, background threads vanish, potentially leading to hangs or crashes when the child attempts to communicate with them. This impacts the default behavior of Python's `multiprocessing` module on POSIX systems (except macOS) in Python versions 3.13 and earlier.","severity":"breaking","affected_versions":"All versions of awscrt"},{"fix":"Be aware of this platform-specific behavior. If you need to use a different private key, you may need to manage certificates in the Keychain or use distinct certificates. awscrt logs an 'info' level message when a key from the Keychain is used instead of a provided one.","message":"On macOS, once a private key is used with a certificate, that certificate-key pair is imported into the Mac Keychain. All subsequent uses of that certificate will use the stored private key from the Keychain and ignore any private key passed in programmatically. This can lead to unexpected behavior if you intend to use different private keys for the same certificate.","severity":"gotcha","affected_versions":"Versions 0.6.2 and later (and similar versions in other AWS CRT language bindings like Java, Node.js)"},{"fix":"If you require the system's `libcrypto`, set `AWS_CRT_BUILD_USE_SYSTEM_LIBCRYPTO=1` and use `pip install --no-binary :all: awscrt`. Otherwise, rely on the default build process which bundles its own `libcrypto` for simpler installation.","message":"When building `awscrt` from source on Unix systems, `s2n-tls` is used, which depends on `libcrypto` (from OpenSSL). By default, `awscrt` includes its own statically compiled copy of `libcrypto` from AWS-LC. If you explicitly need `awscrt` to use a `libcrypto` included on your system, you must set the `AWS_CRT_BUILD_USE_SYSTEM_LIBCRYPTO=1` environment variable during installation and use `--no-binary :all:`, which can complicate the build process.","severity":"gotcha","affected_versions":"All versions when building from source on Unix."},{"fix":"Ensure the `awsiot` library is installed in your Python environment. You can typically install it using pip: `pip install awsiot`.","message":"The `awsiot` library, which is frequently used alongside `awscrt` for higher-level AWS IoT application development, was not found during module import. This indicates that `awsiot` is likely not installed in the Python environment where the script is being executed.","severity":"gotcha","affected_versions":"All versions where `awscrt` is used in conjunction with `awsiot` and `awsiot` is not installed."},{"fix":"To resolve `ModuleNotFoundError` on Alpine Linux, ensure `awscrt` can be correctly installed. This may involve: (1) Verifying if `awscrt` provides `musl`-compatible wheels for your Python version. (2) Installing necessary build tools and development headers (e.g., `build-base`, `openssl-dev`) to allow `awscrt` to compile from source. (3) Consider using a `glibc`-based distribution (e.g., Debian, Ubuntu) if persistent installation issues occur on Alpine.","message":"`awscrt` (and libraries depending on it, like `awsiot`) may fail to install or lead to `ModuleNotFoundError` when used on Alpine Linux (which utilizes `musl` libc). This is due to potential incompatibility with `glibc`-compiled pre-built wheels or complexities in building `awscrt` from source in a `musl`-based environment, especially for newer Python versions where specific `musl` wheels might not be readily available.","severity":"breaking","affected_versions":"All versions of `awscrt` when installed on Alpine Linux, particularly with newer Python versions."}],"env_vars":null,"search_vec":"'0.32.0':55 '2026':60 '26':59 '3':8 'activ':51 'applic':32 'aw':1,12,31,42,74 'awscrt':4,5 'bind':9 'bug':72 'c':19 'cadenc':67 'capabl':36 'cloud':75 'collect':16 'common':2,13,41 'design':21 'e.g':44 'fix':73 'follow':63 'footprint':29 'foundat':35 'frequent':65 'high':24 'high-perform':23 'http':46,80 'i/o':38 'iot':77 'librari':20,49 'like':37 'maintain':52 'march':58 'minim':28 'minor':69 'modular':18 'mqtt':45,78 'offer':34 'perform':25,82 'protocol':43 'provid':6 'python':7 'releas':56,66 'runtim':3,14,76 's3':47,79 'tls':39,81 'typic':62 'updat':70 'version':54","created_at":"2026-04-06T16:55:14.007367+00:00","updated_at":"2026-04-15T21:57:02.604740+00:00","problems":[{"fix":"Ensure 'awscrt' is installed correctly using 'python3 -m pip install awscrt'. If the issue persists, verify that the installation matches your system's architecture and Python version.","cause":"The '_awscrt' module, a native extension, is missing, often due to installation issues or platform incompatibility.","error":"ModuleNotFoundError: No module named '_awscrt'"},{"fix":"Install the 'awscrt' package using 'python3 -m pip install awscrt'. If already installed, check for version compatibility between 'awscrt' and 'botocore'.","cause":"The 'awscrt' module is not found within 'botocore.compat', possibly due to a missing or incorrect installation.","error":"ImportError: cannot import name 'awscrt' from 'botocore.compat'"},{"fix":"Install 'awscrt' using 'python3 -m pip install awscrt'. Ensure that the installation is in the correct environment and accessible to your application.","cause":"The 'awscrt' module is not installed or not accessible in the current Python environment.","error":"ImportError: No module named 'awscrt'"},{"fix":"Install the 'cryptography' module using 'python3 -m pip install cryptography'. If it's already installed, ensure it's in the correct environment and accessible.","cause":"The 'cryptography' module is missing, which is a dependency for 'awscrt'.","error":"ImportError: No module named 'cryptography'"},{"fix":"Ensure `awscrt` is correctly installed in the active Python environment using `python3 -m pip install awscrt`. For deployment environments like AWS Lambda, ensure all dependencies (including native C components) are packaged correctly, or consider using a Lambda layer built for the target architecture.","cause":"The `awscrt` Python package or its underlying C extension (`_awscrt`) could not be found, often due to an incomplete installation, multiple Python environments, or missing build-time dependencies in the deployment environment.","error":"ModuleNotFoundError: No module named 'awscrt'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.36.2","cli_name":"","cli_version":null,"type":"library","homepage":"https://docs.aws.amazon.com/sdkref/latest/guide/common-runtime.html","github":"https://github.com/awslabs/aws-crt-python","docs":"https://awslabs.github.io/aws-crt-python","changelog":null,"pypi":"https://pypi.org/project/awscrt/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["aws","http-networking","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}