This topic describes how to use the Alibaba Cloud SDK for Python to call the CreateVpc API of Virtual Private Cloud (VPC) to create a VPC.

VPC is a private network that you can create in Alibaba Cloud. Two logical isolation layers exist between different VPCs. You can create and manage cloud service instances in the VPC that you have created, such as Elastic Compute Service (ECS), Server Load Balancer (SLB), and ApsaraDB for RDS.

Sample code

import json
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkvpc.request.v20160428 import CreateVpcRequest
from aliyunsdkvpc.request.v20160428 import DescribeVpcAttributeRequest
# Create an AcsClient object.
client = AcsClient(
   "<your-access-key-id>",
   "<your-access-key-secret>",
   "<your-region-id>"
);
# Create a VPC.
request = CreateVpcRequest.CreateVpcRequest()
response = client.do_action_with_exception(request)
vpc_id = json.loads(response)['VpcId']
print "VPC ID is", vpc_id
# Obtain and print the attributes of the VPC.
request = DescribeVpcAttributeRequest.DescribeVpcAttributeRequest()
request.set_VpcId(vpc_id)
response = client.do_action_with_exception(request)
print response