jsii is an open-source framework developed by AWS that enables code in any language (such as Python, Java, C#, and Go) to naturally interact with JavaScript classes authored in TypeScript. It is a core technology behind the AWS Cloud Development Kit (CDK), allowing polyglot libraries to be delivered from a single TypeScript codebase. The project is actively maintained by AWS, with frequent updates to the compiler, pacmak (bindings generator), and runtime libraries.
pip install jsiiVerified import paths — ran on the pinned version, not inferred.
The `jsii` library itself provides the runtime for generated modules. Python developers primarily interact with packages that have been *generated* by jsii (e.g., AWS CDK constructs). These generated packages depend on `jsii`. The example above illustrates how you would typically use a class from such a generated library.
Ensure your Python environment is version 3.8 or higher. For best compatibility, use Python 3.11+.
Upgrade your Node.js installation to version 18 or higher. For best compatibility, use Node.js 20+.
Use the `@jsii.implements(IJsiiInterface)` decorator to explicitly declare interface implementation. For example: `import jsii; @jsii.implements(IJsiiInterface) class MyNewClass():`
Define properties using `@property` and `@<property_name>.setter` decorators.
Where possible, instantiate the `jsii` struct class explicitly instead of relying on implicit `dict` conversion. Consult the specific `jsii`-generated library's documentation for correct struct usage.
Consider the performance implications for your specific use case. If high-performance is critical, native implementations might be more suitable.
Ensure the `jsii`-generated Python package is correctly installed using pip (e.g., `pip install <package-name>`) and that the Python environment running the script has access to it.
Ensure the `jsii`-generated library is installed using `pip install <your-library-name>` or similar package management commands. Verify that the library's installation directory is included in your `PYTHONPATH` or that you are running your script within the activated virtual environment where the library is installed.
Ensure all `aws-cdk-lib` packages (or specific CDK modules) and their dependencies are correctly installed and compatible. Run `npm install` in your TypeScript project and `pip install -r requirements.txt` (or equivalent) in your Python project. Consider upgrading to the latest stable versions of AWS CDK and `jsii` related packages.
Upgrade your `aws-cdk` and `jsii` packages to compatible versions. Often, updating `pip install aws-cdk-lib jsii` (or `npm update` for the TypeScript source) resolves this. Ensure all CDK-related packages in your `requirements.txt` (for Python) or `package.json` (for TypeScript) are consistent.
Update your `jsii` and `cattrs` packages to their latest versions to ensure compatibility with your Python environment. For example, `pip install --upgrade jsii cattrs`. If the issue persists, ensure your Python version is officially supported by the specific `jsii` and CDK versions you are using.
Verify that your `package.json` file has a correct `main` and `types` field pointing to the actual main TypeScript file (e.g., `src/index.ts` or `lib/index.d.ts`). Ensure the file exists at the specified path. Check your `tsconfig.json` for proper `rootDir` and `outDir` settings.