{"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":"en","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."}],"env_vars":null,"last_verified":"2026-04-06T00:00:00.000Z","next_check":"2026-07-05T00:00:00.000Z"}