The easiest path is to implement the script as a Django management
command. Supposing your Django application name is “foo”, there should
be a directory:
in your project source tree. Make the script as the file:
in there. Then you can run the script as:
manage.py your-script-name whatever-arguments...
You’ll need to provide a class in the script called “Command”
subclassing “BaseCommand”, with a “handle” method (your main function).
from django.core.management import BaseCommand
help = "help or usage message here"
def handle(self, *argv, **options):
... do your thing ...
Documentation here: Writing custom django-admin commands | Django documentation | Django
Argument parsing follows the argparse library approach via an
Cameron Simpson email@example.com