Skip to main content

Django Portmaster

Django Portmaster is a network port allocation and management microservice. With Portmaster, you can assign port ranges to different services and register ports to different instances of those service. This way you can prevent assigning the same port twice, thus preventing assignement collision.

Installation

  1. Install using PIP.

pip install django-portmaster
  1. Add app to your Django project’s settings file and include offer cleanup middleware.

INSTALLED_APPS = [
    [..]
    'django_portmaster'
]

MIDDLEWARE = [
    [..]
    'django_portmaster.middleware.CleanOldOffersMiddleware'
]
  1. Include Portmaster’s URLs into your Django project’s urls file.

from django_portmaster.urls import portmaster_urlpatterns
urlpatterns += portmaster_urlpatterns
  1. Optionally, you can override the time offers are kept before they are deleted. Add the following code to you settings.py file.

# Default value is 30 minutes
PM_DELETE_OFFERS_AFTER_MINUTES = 10

API

  • Define port range by creating a service.

POST /v1/services

{
   "name": "django",
   "description": "Django service",
   "start": 5000,
   "end": 10000
}
  • Request a port from the range by providing a service instance name.

POST /v1/services/django/offers

{
    "name": "web-01"
}

Response

{
    "service": "django",
    "name": "web-01",
    "port": 5000,
    "secret": "6f8ffc86-d98a-49ba-848a-a7cbaaea9360",
    "created": "2017-09-08T14:16:39.277408Z"
}
  • Port will not be allocated immediately. Instead it will be reserved until the client accepts the port by posting to the dedicated URL using the provided secret code:

POST /v1/services/django/offers/6f8ffc86-d98a-49ba-848a-a7cbaaea9360/accept

Response

{
    "service": "django",
    "name": "web-01",
    "port": 5000,
    "created": "2017-09-08T14:18:04.094357Z"
}
  • Alternatively, you can reject the offer. Offers that are not accepted are automatically deleted by Portmaster middleware after they reach threshold set by PM_DELETE_OFFERS_AFTER_MINUTES setting (default value is 30 minutes).

POST /v1/services/django/offers/6f8ffc86-d98a-49ba-848a-a7cbaaea9360/reject
  • You can list all port alocations for a particular service.

GET /v1/services/django/ports
  • Find one by port number

GET /v1/services/django/ports/5000
  • Or find one by service instance name

GET /v1/services/django/ports/web-01

Safe guards

Portmaster includes multiple error checks and corner case handlers, so:

  • Service name needs to be unique

  • Port ranges can not overlap

  • Port range can not overlap with privileged ports (<1024) or IANA defined ephemeral port range (>49152)

  • Port can be assigned only once at any given time

  • Service instance name needs to be unique

Metadata

Release files for django-portmaster 0.0.1

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-portmaster 0.0.1
File Size Uploaded Provenance Actions
django-portmaster-0.0.1.tar.gz 9.3 kB Without provenance Details for django-portmaster-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-portmaster 0.0.1
File Interpreter ABI Platform Actions
django_portmaster-0.0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details for django_portmaster-0.0.1-py2.py3-none-any.whl

Total release size: 25.3 kB

Release files / django-portmaster-0.0.1.tar.gz

Download URL django-portmaster-0.0.1.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
262645afb6ad75a4044e0392fe66a2007aaa3225d601d7080c7eebd37568da72
BLAKE2b-256 checksum
How to use checksums
4932d140aea7df08b94fea634d94c41683b07ce96f2c4843c4397073e3a381d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_portmaster-0.0.1-py2.py3-none-any.whl

Download URL django_portmaster-0.0.1-py2.py3-none-any.whl
Size 16.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
840fb9471e08c6466bfd41863f0f8872e60b5e48252c6a867b4998cf8ba24991
BLAKE2b-256 checksum
How to use checksums
20fc0ddd264f241ce83cb3b671854a299e3a45394eeb8c3e3feb46496be3553d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-portmaster 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

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