pydo.load_balancers.create()
Generated on 8 Dec 2025
from pydo version
v0.21.0
Description
To create a new load balancer instance, send a POST request to
/v2/load_balancers.
You can specify the Droplets that will sit behind the load balancer using one of two methods:
- Set
droplet_idsto a list of specific Droplet IDs. - Set
tagto the name of a tag. All Droplets with this tag applied will be assigned to the load balancer. Additional Droplets will be automatically assigned as they are tagged.
These methods are mutually exclusive.
Request Sample
import os
from pydo import Client
client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
req = {
"name": "example-lb-01",
"region": "nyc3",
"forwarding_rules": [
{
"entry_protocol": "http",
"entry_port": 80,
"target_protocol": "http",
"target_port": 80
},
{
"entry_protocol": "https",
"entry_port": 443,
"target_protocol": "https",
"target_port": 443,
"tls_passthrough": True
}
],
"droplet_ids": [
3164444,
3164445
],
"project_id": "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30",
"http_idle_timeout_seconds": 60,
"firewall": {
"deny": [
"cidr:1.2.0.0/16",
"ip:2.3.4.5"
],
"allow": [
"ip:1.2.3.4",
"cidr:2.3.4.0/24"
]
}
}
resp = client.load_balancers.create(body=req)More Information
See the API spec for this endpoint to view additional detail on responses, headers, parameters, and more.