Official Python SDK for MizbanCloud CDN and Cloud APIs
Project description
MizbanCloud Python SDK
Official Python SDK for interacting with MizbanCloud CDN and Cloud APIs.
Requirements
- Python 3.8 or higher
Installation
pip
pip install mizbancloud-sdk
From source
git clone https://github.com/mizbancloud/python-sdk.git
cd python-sdk
pip install -e .
Quick Start
from mizbancloud import MizbanCloudClient, MizbanCloudConfig
# Create client instance
client = MizbanCloudClient(MizbanCloudConfig(
base_url="https://auth.mizbancloud.com"
))
# Set API token
client.set_token("your-api-token")
# List CDN domains
domains = client.cdn.list_domains()
# List cloud servers
servers = client.cloud.list_servers()
# Don't forget to close when done
client.close()
Using Context Manager
from mizbancloud import MizbanCloudClient
with MizbanCloudClient() as client:
client.set_token("your-api-token")
domains = client.cdn.list_domains()
Configuration
from mizbancloud import MizbanCloudClient, MizbanCloudConfig
config = MizbanCloudConfig(
base_url="https://auth.mizbancloud.com", # API base URL
timeout=30, # Request timeout in seconds
language="en", # Response language: "en" or "fa"
headers={"X-Custom-Header": "value"}, # Additional headers
)
client = MizbanCloudClient(config)
Modules
Auth Module
Token management and wallet operations.
# Set API token
client.auth.set_api_token("your-token")
# Get current token
token = client.auth.get_api_token()
# Clear token
client.auth.clear_api_token()
# Get wallet balance
wallet = client.auth.get_wallet()
CDN Module
Complete CDN management: domains, DNS, SSL, cache, security, WAF, page rules, and more.
Domains
# List all domains
domains = client.cdn.list_domains()
# Get domain details
domain = client.cdn.get_domain(domain_id)
# Add a new domain
result = client.cdn.add_domain({"domain": "example.com"})
# Delete domain (requires SMS confirmation)
client.cdn.send_delete_confirm_code(domain_id)
client.cdn.delete_domain(domain_id, confirm_code)
# Get domain usage/analytics
usage = client.cdn.get_usage(domain_id)
DNS Records
# List DNS records
records = client.cdn.list_dns_records(domain_id)
# Add DNS record
record = client.cdn.add_dns_record(domain_id, {
"type": "A",
"name": "www",
"value": "1.2.3.4",
"ttl": 3600,
"proxied": True
})
# Update DNS record
client.cdn.update_dns_record(domain_id, record_id, {"value": "5.6.7.8"})
# Delete DNS record
client.cdn.delete_dns_record(domain_id, record_id)
# Enable DNSSEC
client.cdn.set_dnssec(domain_id, True)
SSL/HTTPS
# List SSL certificates
certs = client.cdn.list_ssl(domain_id)
# Request free SSL (Let's Encrypt)
client.cdn.request_free_ssl(domain_id)
# Add custom SSL certificate
client.cdn.add_custom_ssl(domain_id, {
"certificate": "-----BEGIN CERTIFICATE-----...",
"private_key": "-----BEGIN PRIVATE KEY-----..."
})
# Configure HSTS
client.cdn.set_hsts(domain_id, {
"enabled": True,
"max_age": 31536000,
"include_subdomains": True
})
# Enable HTTPS redirect
client.cdn.set_https_redirect(domain_id, True)
Cache
# Get cache settings
settings = client.cdn.get_cache_settings(domain_id)
# Set cache mode
client.cdn.set_cache_mode(domain_id, "aggressive")
# Set cache TTL
client.cdn.set_cache_ttl(domain_id, 86400)
# Enable developer mode (bypass cache)
client.cdn.set_developer_mode(domain_id, True)
# Purge all cache
client.cdn.purge_cache(domain_id, {"purge_all": True})
DDoS Protection
# Get DDoS settings
settings = client.cdn.get_ddos_settings(domain_id)
# Set DDoS settings
client.cdn.set_ddos_settings(domain_id, {"mode": "high"})
Firewall & WAF
# Get firewall configs
configs = client.cdn.get_firewall_configs(domain_id)
# Get WAF settings
waf = client.cdn.get_waf_settings(domain_id)
# Set WAF settings
client.cdn.set_waf_settings(domain_id, {
"enabled": True,
"mode": "block"
})
Cloud Module
Complete IaaS management: servers, firewall, networks, volumes, snapshots, SSH keys.
Servers
# List all servers
servers = client.cloud.list_servers()
# Get server details
server = client.cloud.get_server(server_id)
# Create a new server
new_server = client.cloud.create_server({
"name": "my-server",
"datacenter_id": 1,
"os_id": 1,
"cpu": 2,
"ram": 4096,
"disk": 50
})
# Rename server
client.cloud.rename_server(server_id, "new-name")
# Delete server
client.cloud.delete_server(server_id)
Power Management
# Power on
client.cloud.power_on(server_id)
# Power off (hard)
client.cloud.power_off(server_id)
# Reboot (hard)
client.cloud.reboot(server_id)
# Restart (soft/graceful)
client.cloud.restart(server_id)
Security Groups (Firewall)
# List security groups
groups = client.cloud.list_security_groups()
# Create security group
group = client.cloud.create_security_group({"name": "web-servers"})
# Add security rule
client.cloud.add_security_rule({
"security_group_id": group_id,
"direction": "ingress",
"protocol": "tcp",
"port_range_min": 80,
"port_range_max": 80,
"remote_ip_prefix": "0.0.0.0/0"
})
Volumes
# List volumes
volumes = client.cloud.list_volumes()
# Create volume
volume = client.cloud.create_volume({
"name": "data-volume",
"size": 100,
"datacenter_id": 1
})
# Attach volume to server
client.cloud.attach_volume({
"volume_id": volume_id,
"server_id": server_id
})
SSH Keys
# List SSH keys
keys = client.cloud.list_ssh_keys()
# Create SSH key
key = client.cloud.create_ssh_key({
"name": "my-key",
"public_key": "ssh-rsa AAAA..."
})
# Generate random SSH key pair
key_pair = client.cloud.generate_random_ssh_key()
Statics Module
Static catalog data for server creation.
# List available datacenters
datacenters = client.statics.list_datacenters()
# List available operating systems
os_list = client.statics.list_operating_systems()
# Get cache time options
cache_times = client.statics.get_cache_times()
Error Handling
from mizbancloud import MizbanCloudClient, MizbanCloudException
try:
with MizbanCloudClient() as client:
client.set_token("your-token")
domains = client.cdn.list_domains()
except MizbanCloudException as e:
print(f"Error: {e.message}")
print(f"Status Code: {e.status_code}")
# Get validation errors
if e.fields:
for field, error in e.fields.items():
print(f" {field}: {error}")
Language Support
# Set language for API responses
client.set_language("fa") # Persian
client.set_language("en") # English (default)
# Get current language
lang = client.get_language()
Authentication Status
# Check if authenticated
if client.is_authenticated():
print("Token is set")
# Get current token
token = client.get_token()
Development
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run tests with coverage
pytest --cov=mizbancloud
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mizbancloud_sdk-1.0.0.tar.gz.
File metadata
- Download URL: mizbancloud_sdk-1.0.0.tar.gz
- Upload date:
- Size: 23.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a933c1890c276a7afc04787b0c578bbf19851e3ad41236185a10cde3fabab7bc
|
|
| MD5 |
61cde1598c354ebcfde2701eeb8bcfbc
|
|
| BLAKE2b-256 |
059d3bde64a745894c63a655b90d1bc0688de1c72821dfe64b59a22184c254ca
|
Provenance
The following attestation bundles were made for mizbancloud_sdk-1.0.0.tar.gz:
Publisher:
publish.yml on mizbancloud/Python-SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mizbancloud_sdk-1.0.0.tar.gz -
Subject digest:
a933c1890c276a7afc04787b0c578bbf19851e3ad41236185a10cde3fabab7bc - Sigstore transparency entry: 782204199
- Sigstore integration time:
-
Permalink:
mizbancloud/Python-SDK@afd47d8b59e05ee947634e0395aa4b0f1596b529 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/mizbancloud
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@afd47d8b59e05ee947634e0395aa4b0f1596b529 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mizbancloud_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mizbancloud_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c210ca2c900aff09a248d789905c28e7f1f39671c2d2e8bd6d3ea822cb537ea3
|
|
| MD5 |
352a3fbce28cb80d94b395f9378baf3f
|
|
| BLAKE2b-256 |
93b383434adf09b55a7aff0e68be636c0aa45dcf0af9ae754dfc065933bbd073
|
Provenance
The following attestation bundles were made for mizbancloud_sdk-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on mizbancloud/Python-SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mizbancloud_sdk-1.0.0-py3-none-any.whl -
Subject digest:
c210ca2c900aff09a248d789905c28e7f1f39671c2d2e8bd6d3ea822cb537ea3 - Sigstore transparency entry: 782204201
- Sigstore integration time:
-
Permalink:
mizbancloud/Python-SDK@afd47d8b59e05ee947634e0395aa4b0f1596b529 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/mizbancloud
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@afd47d8b59e05ee947634e0395aa4b0f1596b529 -
Trigger Event:
release
-
Statement type: