Smithy Core
Smithy-core is a Python library providing foundational SDK interfaces and transport-agnostic core components for implementing Smithy tooling and building service clients in Python. It is currently in a pre-alpha development stage (version 0.4.0) with all interfaces subject to change. The library is released as part of the broader Smithy Python ecosystem and receives updates frequently, as seen in its release history.
Common errors
-
ModuleNotFoundError: No module named 'generated_client'
cause This error occurs because 'generated_client' is a placeholder for a client that you need to generate from a Smithy model using the Smithy CLI and then install, or ensure its path is in your Python environment. You cannot directly import a client that hasn't been generated.fixYou must first define a Smithy model, configure `smithy-build.json` for Python client generation, run `smithy build` to generate the client, and then install the generated client package (e.g., `pip install ./path/to/generated-client`). After installation, you can import from the actual name of your generated client module. -
TypeError: argument of type 'NoneType' is not iterable
cause Given `smithy-core`'s low-level and pre-alpha nature, this generic `TypeError` could arise from unexpected `None` values where iterables are expected, often due to uninitialized or missing components within the underlying generated client's interaction with `smithy-core` interfaces, reflecting the instability of early development.fixDue to the pre-alpha status and evolving interfaces, detailed debugging of `smithy-core`-related `TypeError`s often requires examining the generated client code and the specific Smithy model definitions. Ensure all required configurations and inputs for your generated client operations are provided, and that your Smithy model is valid and complete. Consult the Smithy Python GitHub repository for the latest development status and known issues.
Warnings
- breaking Smithy-core is in a 'Pre-Alpha' development stage, and all of its interfaces are subject to change without prior notice. It is explicitly stated that this code generator and its clients are unstable and should not be used in production systems yet.
- gotcha The `smithy-core` package is a foundational component for Smithy's Python client generation and tooling, not typically for direct application-level consumption. Developers usually interact with code generated by Smithy, which then relies on `smithy-core` internally.
Install
-
pip install smithy-core
Imports
- SomeCoreType
from smithy_core.interfaces import SomeCoreType
Quickstart
# smithy-core is primarily a foundational library for code generation.
# End-users typically interact with clients generated from Smithy models,
# which then use smithy-core internally.
#
# To get started with a generated client, you would first define a Smithy model (e.g., main.smithy):
#
# # main.smithy
# $version: "2.0"
# namespace com.example
# use aws.protocols#restJson1
#
# service MyService {
# operations: [SayHello]
# }
#
# operation SayHello {
# input: SayHelloInput,
# output: SayHelloOutput
# }
#
# structure SayHelloInput {
# name: String
# }
#
# structure SayHelloOutput {
# message: String
# }
#
# Then, use the Smithy CLI to build the Python client:
#
# # Assuming 'smithy-build.json' is configured for Python client generation
# smithy build
#
# After generation, the client would be available in a build directory,
# and you would install and import from that generated client, not directly from smithy-core.
#
# Example of using a *hypothetical generated client* (not direct smithy-core usage):
# import asyncio
# from generated_client import MyServiceServiceClient
#
# async def main():
# client = MyServiceServiceClient()
# response = await client.say_hello(name='World')
# print(response.message)
#
# if __name__ == '__main__':
# asyncio.run(main())