A standard Python library that abstracts away differences among multiple cloud provider APIs
npx @tessl/cli install tessl/pypi-apache-libcloud@3.8.0Apache Libcloud is a comprehensive Python library that provides a unified interface for managing cloud computing resources across multiple cloud provider APIs. It abstracts away the differences between various cloud providers (AWS, Azure, Google Cloud, and many others) by offering standardized APIs for compute instances, storage services, DNS management, load balancers, containers, and backup services.
pip install apache-libcloudimport libcloud
from libcloud.base import get_driver, DriverTypeService-specific imports:
# Compute
from libcloud.compute.types import Provider as ComputeProvider
from libcloud.compute.providers import get_driver as get_compute_driver
# Storage
from libcloud.storage.types import Provider as StorageProvider
from libcloud.storage.providers import get_driver as get_storage_driver
# DNS
from libcloud.dns.types import Provider as DNSProvider
from libcloud.dns.providers import get_driver as get_dns_driver
# Load Balancer
from libcloud.loadbalancer.types import Provider as LoadBalancerProvider
from libcloud.loadbalancer.providers import get_driver as get_loadbalancer_driver
# Container
from libcloud.container.types import Provider as ContainerProvider
from libcloud.container.providers import get_driver as get_container_driver
# Backup
from libcloud.backup.types import Provider as BackupProvider
from libcloud.backup.providers import get_driver as get_backup_driverfrom libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
# Get a compute driver for EC2
cls = get_driver(Provider.EC2)
driver = cls('access_id', 'secret_key', region='us-east-1')
# List all nodes
nodes = driver.list_nodes()
for node in nodes:
print(f"Node: {node.name}, State: {node.state}")
# Create a new node
sizes = driver.list_sizes()
images = driver.list_images()
locations = driver.list_locations()
new_node = driver.create_node(
name='my-server',
size=sizes[0],
image=images[0],
location=locations[0]
)Libcloud uses a driver-based architecture where each cloud provider is implemented as a driver that inherits from service-specific base classes. The core components are:
get_driver() functions to instantiate provider-specific driversThe foundation of Libcloud's unified interface, providing driver factory functions and type definitions.
class DriverType:
BACKUP = BackupProvider
COMPUTE = ComputeProvider
CONTAINER = ContainerProvider
DNS = DnsProvider
LOADBALANCER = LoadBalancerProvider
STORAGE = StorageProvider
def get_driver(type: DriverType, provider: str) -> BaseDriverdef enable_debug(fo: TextIOWrapper) -> NoneManage virtual machines, instances, and compute resources across 60+ cloud providers including AWS EC2, Azure, Google Compute Engine, and more.
class NodeDriver(BaseDriver):
def list_nodes(self) -> List[Node]
def create_node(self, name: str, size: NodeSize, image: NodeImage, location: NodeLocation = None, **kwargs) -> Node
def destroy_node(self, node: Node) -> bool
def reboot_node(self, node: Node) -> bool
class Node:
id: str
name: str
state: NodeState
public_ips: List[str]
private_ips: List[str]
size: NodeSize
image: NodeImageObject storage and blob operations across 20+ storage providers including AWS S3, Azure Blob Storage, Google Cloud Storage, and more.
class StorageDriver(BaseDriver):
def list_containers(self) -> List[Container]
def create_container(self, container_name: str) -> Container
def upload_object(self, file_path: str, container: Container, object_name: str) -> Object
def download_object(self, obj: Object, destination_path: str) -> bool
class Container:
name: str
extra: Dict[str, Any]
class Object:
name: str
size: int
hash: str
container: ContainerDNS zone and record management across 15+ DNS providers including Route 53, CloudFlare, Google DNS, and more.
class DNSDriver(BaseDriver):
def list_zones(self) -> List[Zone]
def create_zone(self, domain: str) -> Zone
def create_record(self, name: str, zone: Zone, type: RecordType, data: str) -> Record
class Zone:
id: str
domain: str
type: str
ttl: int
class Record:
id: str
name: str
type: RecordType
data: str
zone: ZoneLoad balancer management across multiple cloud providers including AWS ELB/ALB, Azure Load Balancer, and more.
class Driver(BaseDriver):
def list_balancers(self) -> List[LoadBalancer]
def create_balancer(self, name: str, port: int, protocol: str, algorithm: Algorithm, members: List[Member]) -> LoadBalancer
class LoadBalancer:
id: str
name: str
state: State
ip: str
port: int
class Member:
id: str
ip: str
port: intContainer and cluster management for Kubernetes, AWS ECS, and other container platforms.
class ContainerDriver(BaseDriver):
def list_containers(self) -> List[Container]
def deploy_container(self, name: str, image: ContainerImage) -> Container
def list_clusters(self) -> List[ContainerCluster]
class Container:
id: str
name: str
image: ContainerImage
state: ContainerState
class ContainerCluster:
id: str
name: str
state: strBackup and snapshot management for cloud storage and compute resources.
class BackupDriver(BaseDriver):
def list_targets(self) -> List[BackupTarget]
def create_target_from_node(self, node: Node, name: str = None) -> BackupTarget
class BackupTarget:
id: str
name: str
size: int
type: BackupTargetTypefrom libcloud.common.types import LibcloudError, InvalidCredsError, MalformedResponseError, ProviderError
class LibcloudError(Exception):
"""Base exception class for all Libcloud errors"""
def __init__(self, value: str, driver: BaseDriver = None) -> None
value: str
driver: BaseDriver
class ProviderError(LibcloudError):
"""Exception raised when provider returns HTTP error response (4xx, 5xx)"""
def __init__(self, value: str, http_code: int, driver: BaseDriver = None) -> None
http_code: int
class InvalidCredsError(ProviderError):
"""Exception raised when invalid credentials are provided (HTTP 401)"""
def __init__(self, value: str = "Invalid credentials with the provider", driver: BaseDriver = None) -> None
class MalformedResponseError(LibcloudError):
"""Exception raised when the response cannot be parsed"""
def __init__(self, value: str, body: str = None, driver: BaseDriver = None) -> None
body: str
# Deprecated alias
InvalidCredsException = InvalidCredsError# Security settings
from libcloud.security import VERIFY_SSL_CERT, CA_CERTS_PATH
VERIFY_SSL_CERT: bool
CA_CERTS_PATH: str
# Networking utilities
from libcloud.utils.networking import is_private_subnet, is_public_subnet, is_valid_ip_address
def is_private_subnet(ip: str) -> bool
def is_public_subnet(ip: str) -> bool
def is_valid_ip_address(ip: str) -> bool
def join_ipv4_segments(segments: List[int]) -> str
def increment_ipv4_segments(segments: List[int]) -> List[int]
# Pricing information
from libcloud.pricing import get_pricing, get_size_price, get_image_price, set_pricing
def get_pricing(driver_type: str, driver_name: str) -> Dict[str, float]
def get_size_price(driver_type: str, driver_name: str, size_id: str) -> float
def get_image_price(driver_type: str, driver_name: str, image_id: str) -> float
def set_pricing(pricing_data: Dict) -> None
def clear_pricing_data() -> None
def download_pricing_file(file_url: str = None) -> str
# Debug functionality
from libcloud import enable_debug
def enable_debug(fo: TextIOWrapper) -> None