Skip to main content
This page shows you how to add the HiddenLayer SDK to a Python, Node.js, or Java project, install optional packages, and confirm that the installation works. Before you start, check the Prerequisites.

Set up a project

Install the Python SDK into a virtual environment. A virtual environment is an isolated Python installation for one project. Use one because:
  • The SDK’s dependencies, such as httpx and pydantic, do not conflict with other projects.
  • You can pin exact versions per project and reproduce them on other machines.
  • You do not need administrator rights to install packages.
Create and activate a virtual environment in your project folder:
When the environment is active, your shell prompt usually starts with (.venv). Inside an active environment, python and pip refer to the environment’s interpreter on every operating system.
Activate the environment in every new terminal session before you run your code. To leave the environment, run deactivate.
Older pip versions can fail to resolve recent packages. Upgrade pip inside the environment:

Install the SDK

The PyPI package name is hiddenlayer-sdk, but you import it in Python as hiddenlayer.
Running python -m pip instead of pip guarantees that the package is installed for the same interpreter that runs your code.

Install optional packages

Install these only if you use the related feature.

Asynchronous HTTP backend

By default, AsyncHiddenLayer sends requests with httpx. To send them with aiohttp instead, install the aiohttp extra:
Keep the quotes. Some shells, such as zsh (the default on macOS), treat square brackets as a filename pattern and fail with no matches found.With the extra installed, AsyncHiddenLayer uses aiohttp automatically. You do not need to change your code. If your program then prints aiohttp’s Unclosed connector warning when it exits, close the client’s connections as shown in Authentication and configuration.

Cloud and Hugging Face model scanning helpers

Some model scanning helpers download models with third-party libraries. The SDK does not install them, so install the ones for the scans you run:
If a package is missing when you call the helper, the SDK raises an ImportError, for example Python package boto3 is not installed.

Loading credentials from a .env file

The SDKs read environment variables but do not load .env files themselves.
To load a .env file during local development, install python-dotenv:
See Authentication and configuration for usage.

Verify the installation

Print the installed SDK version:
The output is a version number, for example:
You can also check package details with pip:
Installation does not contact HiddenLayer or check your credentials. To confirm that you can reach the API, complete the Quickstart.

Pin versions

Pin the SDK version so that every developer and every deployment uses the same code.
Add a line to your requirements.txt file:
requirements.txt
Or allow compatible minor and patch updates within the same major version:
requirements.txt
Install from the file:
The SDKs follow semantic versioning, but beta APIs are excluded from the versioning guarantees. An exact pin is the safest choice for production. See Version compatibility and upgrades.

Upgrade or uninstall

Upgrade to the latest release:
Uninstall the SDK:
Before upgrading, review the changelog in the SDK’s GitHub repository (Python, TypeScript, Java). When you move to a new major version, follow the upgrade notes in Version compatibility and upgrades.

Common installation errors

Python cannot find the SDK in the interpreter that runs your code. Usually this means the virtual environment is not active, or the SDK was installed into a different environment.To fix it:
  1. Activate the project’s virtual environment (see Set up a project).
  2. Run python -m pip show hiddenlayer-sdk. If nothing is shown, install the SDK again with python -m pip install hiddenlayer-sdk.
  3. In an IDE such as VS Code or PyCharm, select the .venv interpreter for the project.
Also confirm that you import hiddenlayer, not hiddenlayer_sdk.
On machines with several Python installations, the pip command can belong to a different interpreter than python. Always install with python -m pip ... so that pip runs under the same interpreter as your code.To see which interpreter you are using, run:
The path should point inside your .venv folder.
Your environment runs Python 3.9. Versions 4 and later require Python 3.10 or later, so pip installs 3.10.0, the last release that supports Python 3.9. The examples in this guide do not work with 3.10.0. Create the virtual environment with Python 3.10 or later and install again.
zsh interprets the square brackets as a filename pattern. Put the package specifier in quotes:
pip cannot reach PyPI, or your package mirror does not carry the SDK. Upgrade pip and confirm that your network or package mirror allows access to PyPI.
For other problems, see Troubleshooting.

Next step

Authentication and configuration

Provide your client ID and client secret, and choose your region.