Two libraries are found on Pypi, 'python-magic' and 'filemagic', which can be imported with same import statement:
https://pypi.org/project/python-magic/
https://pypi.org/project/filemagic/
import magic
I want to import both of these libraries in my django project?
I want to consume magic.from_buffer() method from python-magic lib & magic.id_buffer() method from libmagic.
I have pip installed both python-magic, libmagic, filemagic into my project. Also since I need to upload this project in custom server setup, making changes in to these packages in my venv won't help.
I tried importing magic using AS in import statements
from filemagic import magic as mm (code does not identify filemagic in this statement) from python-magic import magic as pm (code does not identify python-magic in this statement)
EDIT - For a clearer objective, I want to identify file type on content basis. I have two different types of file inputs, 1. user uploaded file, 2. user uploaded file in base64 encoded format.
I have already been using magic.Magic().id_buffer to read files of type 1.
I now want to add code to handle base64 encoded files as solved in this post How to know MIME-type of a file from base64 encoded data in python?
when run on server(other than my local dev env), I get 'magic' module has no attribute 'from_buffer' error.