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 addsudo
before 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_CLEAR
for delete resized image after sending to client. -
By default files stored on localhost. If you want user Amazon S3 you need set env
STORAGE_TYPE
toaws
and additional ENV vars:AWS_BUCKET
- name of your bucket.AWS_FOLDER
- folder for resized images.AWS_ACCESS_KEY
AWS_SECRET_ACCESS
AWS_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
DEBUG
env.
python3 main.py
Then you can use this handlers for work
-
/api/v1/image
-POST
request withmultipart
file(first filed must be filename and second field - file) And you need add some query params :
1.-s --scale
scale to resize image.
2.-ws --width
width of out image.
3.-hs --height
height of out image.
Attention!scale
withwidth/height
are incompatible!
Response example:{ "id": "300c4865-6e04", "status": "ok" }
-
/api/v1/image/<id>/check
-GET
request with id from above example.
You can see status of resize work. -
/api/v1/image/<id>
-GET
request 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.