Linode Metadata Python Client
raw JSON → 0.3.5 verified Fri May 01 auth: no python
A client to interact with the Linode Metadata service in Python. Provides methods to query instance metadata (like IP addresses, SSH keys, user data) and user-defined metadata. Current version 0.3.5, requires Python >=3.9.
pip install linode-metadata Common errors
error httpx.ConnectError: [Errno -2] Name or service not known ↓
cause The library tries to connect to the Linode Metadata endpoint (169.254.169.254) which only exists on Linode instances.
fix
Ensure you are running the code on a Linode instance, or wrap the call in a try-except for offline testing.
error KeyError: 'network' ↓
cause Accessing dictionary keys directly when get_network() returns an object instead of a dict in newer versions.
fix
Use attribute access instead of dictionary indexing, e.g., net.public_ipv4 instead of net['public_ipv4'].
error AttributeError: 'LinodeMetadata' object has no attribute 'get_metadata' ↓
cause The method get_metadata() was removed in version 0.3.0.
fix
Use the specific methods: get_network(), get_ssh_keys(), get_user_data(), etc.
Warnings
gotcha The client uses the Linode Metadata service which is only available from within a Linode instance. Running code outside of a Linode will cause connection errors. ↓
fix Only use this library on a Linode compute instance.
deprecated The 'get_metadata' method was deprecated in favor of specific methods like get_network(), get_ssh_keys(), get_user_data(). ↓
fix Migrate to the specific getter methods.
breaking Drop of support for Python 3.6 and 3.7. Requires Python >=3.9. ↓
fix Upgrade Python to 3.9 or later.
Imports
- LinodeMetadata wrong
import linode_metadatacorrectfrom linode_metadata import LinodeMetadata
Quickstart
from linode_metadata import LinodeMetadata
# Instantiate the client
client = LinodeMetadata()
# Get network information
network = client.get_network()
print(network)
# Get SSH keys
ssh_keys = client.get_ssh_keys()
print(ssh_keys)
# Get user data (if any)
user_data = client.get_user_data()
print(user_data)