Skip to main content

Django Cloud Provider Regions

django-cloud-provider-zones on pypi

Examples

For reference, and for use outside of Django, region_data/normalized_azs.json and region_data/normalized_regions.json contain all generated region and az names.

All regions and AZs have unique a short_name and short_name_with_provider

example AZ names:

  { "provider": "aws",
    "original_az_name": "ap-northeast-2b",
    "original_region_name": "ap-northeast-2",
    "short_name": "apne2zb",
    "short_name_with_provider": "awsapne2zb",
    "az": "b" },
  { "provider": "azu",
    "original_az_name": "eastus2-az3",
    "original_region_name": "eastus2",
    "short_name": "use2z3",
    "short_name_with_provider": "azuuse2z3",
    "az": "3" },
  { "provider": "azu",
    "original_az_name": "francecentral-az1",
    "original_region_name": "francecentral",
    "short_name": "frcz1",
    "short_name_with_provider": "azufrcz1",
    "az": "1" },
  { "provider": "gcp",
    "original_az_name": "northamerica-northeast2-c",
    "original_region_name": "northamerica-northeast2",
    "short_name": "nane2zc",
    "short_name_with_provider": "gcpnane2zc",
    "az": "c" },
  { "provider": "gcp",
    "original_az_name": "southamerica-east1-a",
    "original_region_name": "southamerica-east1",
    "short_name": "sae1za",
    "short_name_with_provider": "gcpsae1za",
    "az": "a" },

Why

This Django app provides a static list of region and availability zones for AWS (Amazon Web Services) and GCP (Google Cloud Platform) cloud providers.

The purpose of this app is to provide Cloud Provider Region/AZ lists easily available to Django apps. It provides stable, shortened, versions of names for provisioning naming conventions.

The Regions/AZ list is currrent as of March 2024.

Features

  • Quick and easy access to cloud Region and AZs from other Django apps
  • Provides shortened versions of Region and AZ names for use by provisioning tools
  • DB primary key fields are stable, will not change as new Regions/AZs are added

Installation

pip install django-cloud-provider-zones

Add to project's settings.py INSTALLED_APPS:

'rest_framework',
'django_cloud_provider_zones',

Optionally, include the DRF REST urls in your project's urls.py:

from django.contrib import admin
from django.urls import path, include
import django_cloud_provider_zones

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/cloudzones/', include('django_cloud_provider_zones.urls')),
]

Import model data

./manage.py loaddata django_cloud_provider_zones-CloudProvider django_cloud_provider_zones-CloudRegion django_cloud_provider_zones-CloudAvailabilityZone

If exposed via the Django admin, it is recommended that these App's models are "read only" so grant only View permissions.

Models

model diagram

This app provides the following models:

  • CloudProvider: Cloud provider names - currently AWS or GCP
  • CloudRegion: Cloud regions
  • CloudAvailabilityZone: Availability zones within a region

Each region and AZ provides, as properties, short name versions with dashes removed. For example, AWS us-east-1 has names

short_name: use1
short_name_with_provider: awsuse1
## CloudProvider ##
>>> CloudProvider.objects.values().first()
{'provider': 'aws'}

## CloudRegion ##
>>> CloudRegion.objects.values().first()
{'cardinality': 'northeast',
 'created': datetime.date(2024, 3, 27),
 'geographic_region': 'ap',
 'id': 11,
 'number': '1',
 'original_region_name': 'ap-northeast-1',
 'provider_id': 'aws'}

>>> CloudRegion.objects.first().short_name
'apne1'
>>> CloudRegion.objects.first().short_name_with_provider
'awsapne1'

## CloudAvailabilityZone ##
>>> CloudAvailabilityZone.objects.values().first()
{'az': 'a', 'created': datetime.date(2024, 3, 27), 'id': 27, 'region_id': 11}

>>> CloudAvailabilityZone.objects.first().short_name
'apne1a'
>>> CloudAvailabilityZone.objects.first().short_name_with_provider
'awsapne1a'

Regions and AZs use Django "natural keys" which allows filtering by the Provider's region name

## Region natural key ##
>>> CloudRegion.objects.first().natural_key()
('aws', 'ap-northeast-1')
>>> CloudRegion.objects.get_by_natural_key("aws", "us-east-1")
<CloudRegion: aws-us-east-1>

## AZ natural key ##
>>> CloudAvailabilityZone.objects.first().natural_key()
('a', ('aws', 'ap-northeast-1'))
>>> CloudAvailabilityZone.objects.get_by_natural_key('a', ('aws', 'ap-northeast-1'))
<CloudAvailabilityZone: aws-ap-northeast-1a>

Exported JSON files

All generated names are exported to these files for reference

tasks/django_management_commands.py django_serialize_azs > region_data/normalized_azs.json
tasks/django_management_commands.py django_serialize_regions  > region_data/normalized_regions.json

API Endpoints

Basic REST Get endpoints available see urls.py

Updating model data

To add a new provider, activate the poetry virtualenv with poetry shell && poetry install

Fetch raw json from the provider's API or cli tool, save it to region_data/PROVIDER_unprocessed.json see AWS and GCP examples. Create tasks/format_json_PROVIDER which creates properly formatted json files

region_data/PROVIDER_provider.json
region_data/PROVIDER_region.json
region_data/PROVIDER_az.json

see AWS and GCP examples.

Add new provider CLOUD_PROVIDERS in tasks/update_db_from_json.py then run

tasks/django_management_commands.py django_makemigrations
tasks/django_management_commands.py django_migrate
tasks/django_management_commands.py django_update_fixture_from_json

Once that looks good add a couple simple tests to src/django_cloud_provider_zones/tests.py then

tasks/django_management_commands.py django_test

Bump version, commit and push as needed.

poetry version patch && poetry build && poetry publish

Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Thanks to the Django community and Django Software Foundation for Django
  • Thanks to the maintainers of all dependencies on this project
  • Thanks to Real Python for their Installable Django App article# django-cloud-provider-regions

Metadata

Release files for django-cloud-provider-zones 0.1.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-cloud-provider-zones 0.1.14
File Size Uploaded
django_cloud_provider_zones-0.1.14.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-cloud-provider-zones 0.1.14
File Interpreter ABI Platform
django_cloud_provider_zones-0.1.14-py3-none-any.whl Python 3 none any Details

Total release size: 28.9 kB

Release files / django_cloud_provider_zones-0.1.14.tar.gz

Download URL django_cloud_provider_zones-0.1.14.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
87c02bf361da8ee39746be52094d9fefc13be9d551bf240313ce825e960f5218
BLAKE2b-256 checksum
How to use checksums
5dbe22202882343acabba9b84fa9e7dfbcca8b48f08e72b8174e023d77364020
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.2 Darwin/25.4.0

Release files / django_cloud_provider_zones-0.1.14-py3-none-any.whl

Download URL django_cloud_provider_zones-0.1.14-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f04d1c9183542f9c5b667ce93529bea03f1e0c56d039bce9308a559c396779c
BLAKE2b-256 checksum
How to use checksums
565032ac6ecbe27691eeef73df064555d24fe1f14e845f01b8fb35bb2daf5a46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.2 Darwin/25.4.0

Release history Release notifications | RSS feed

This release

0.1.14 This release

2 release files

0.1.13

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page