Python Flask

From Wildsong
Revision as of 20:24, 29 November 2022 by Brian Wilson (talk | contribs) (Created page with "I have been noodling around with Flask for a few years now. I decided I should start collecting information in one place. Older pages include Flask Login and a few others, search for Flask. Mostly references to projects. == Flask-restx == Flask-restx is the descendant of flask-restful which is a module to help you write APIs and microservices. === Getting flask-restx to load === I decided to try it and found I could not install it. Here are some notes on what I...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

I have been noodling around with Flask for a few years now.

I decided I should start collecting information in one place.

Older pages include Flask Login and a few others, search for Flask. Mostly references to projects.

Flask-restx

Flask-restx is the descendant of flask-restful which is a module to help you write APIs and microservices.

Getting flask-restx to load

I decided to try it and found I could not install it. Here are some notes on what I did to get flask-restx working for me. The problem: it would install pytz as a dependency and that triggered some weird shim thing that would install and then apparently disable pytz.

There is an issue in flask-restx github repo suggesting it was easy to remove pytz. So I forked it and changed these files. Turns out this part was easy. See my fork at github; look at the pytz_remove branch

modified:   examples/zoo_app/requirements.txt

 modified:   flask_restx/inputs.py

modified:   requirements/install.pip
modified:   tests/test_inputs.py

Mostly this means changing pytz.utc or pytz.UTC to timezone.utc

In inputs.py, there is some code that sets timezone on naive times to UTC using pytz "localize" but it appears to do nothing special since it's

setting the timezone to utc and input is assumed to be in utc already. The astimezone(utc) method called in there does the same time for naive times.


Then I needed to install the fixed version, I have never done this before. To test the changes I did this

conda create --name=tz pythyon autopep8 jupyter flask

Normally a conda install would find the dependencies, but this is not a normal situation. I installed them explicitly then installed the package without deps, as was recommmended.

conda install aniso8601 jsonschema
pip install --no-build-isolation --no-deps -e .

Now I can run my tests in a jupyter notebook. There is a thing called "conda develop" that is supposed to help here but search and you will find dismal commentary on how bad it is; that's where I found the suggestion to use the "pip" command. I am hoping the maintainers of flask-restx pick up on the changed so that I don't have to learn more about developing Python modules for redistribution.