Image resizer api. Based on aiohttp/redis/multiprocessing. Resize work running on different processes, work status stored in redis, resized images - on localhost or Amazon S3. Written for fun.
Python version required: 3.7+
-
Recomended use venv or virtualenv for better isolation.
Venv setup example:
python3 -m venv myenv
source myenv/bin/activate -
Install requirements:
pip3 install -r requirements.txt(alternatively try addsudobefore command) -
You need redis. Add to your environ
REDIS_HOST(default-localhost),REDIS_PORT(default-6379),REDIS_PASS(default-SetPass).\ And you can set expiration time for redis:REDIS_TIMEOUT(default-stored indefinitely or until resized image is deleted). -
If it need - add to environ path to files dir
TEMP_FILES_PATH(default - project root) -
By default resized images stored forever. If you want you can set
FILES_CLEARfor delete resized image after sending to client. -
By default files stored on localhost. If you want user Amazon S3 you need set env
STORAGE_TYPEtoawsand additional ENV vars:AWS_BUCKET- name of your bucket.AWS_FOLDER- folder for resized images.AWS_ACCESS_KEYAWS_SECRET_ACCESSAWS_REGION- your aws region (for exampleeu-central-1)AWS_CLEAR- delete resized images from AWS after sending to client (default-False)AWS_SSL- use or not SSL for connections to AWS (default-False)
-
For debug set something to
DEBUGenv.
python3 main.py
Then you can use this handlers for work
-
/api/v1/image-POSTrequest withmultipartfile(first filed must be filename and second field - file) And you need add some query params :
1.-s --scalescale to resize image.
2.-ws --widthwidth of out image.
3.-hs --heightheight of out image.
Attention!scalewithwidth/heightare incompatible!
Response example:{ "id": "300c4865-6e04", "status": "ok" } -
/api/v1/image/<id>/check-GETrequest with id from above example.
You can see status of resize work. -
/api/v1/image/<id>-GETrequest with id from above example.
Load resized image.
Install test requirements pip3 install -r test_requirements.txt and run python3 -m pytest
Some refactor, add errors handling for AWS connections.