miLibris / flask-rest-jsonapi

Flask extension to build REST APIs around JSONAPI 1.0 specification.
http://flask-rest-jsonapi.readthedocs.io
MIT License
597 stars 153 forks source link

Can backends requirements be optional? #7

Closed riklaunim closed 7 years ago

riklaunim commented 7 years ago

Installing flask-rest-jsonapi will also install pymongo even if I don't use MongoDB. The problem is that pymongo conflicts with other bson implementations which hit me in one project.

Is pymongo a must have for flask-rest-jsonapi to work (without using mongo)?

jgoclawski commented 7 years ago

Yeah, it could be probably achieved by using "extras_require" - https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies

akira-dev commented 7 years ago

Yes, you're right, this project will be more flexible thanks to that. I'm looking for the recommended way to make conditional import of the my data layer mongo module. I also have to implement a clean warning if you want to use the mongo data layer without extra requirements. If you allready know the best way to do this, please give me a link, it will be faster to me to include this feature.

I have recently implemented the feature to manage relationship with rest according to this specification: http://jsonapi.org/format/#fetching-relationships and http://jsonapi.org/format/#crud-updating-relationships so i will release a new version on pypi with those new feature next week or in the beginning of next year.

Thanks

riklaunim commented 7 years ago

I see MongoDataLayer in two init files so if like it wasn't imported anywhere then it would work - someone importing MongoDataLayer in their code would get the import exception if not having mongodb (or you can try/except/raise custom exception on the import in the data layer file - AFAIK that's what Django does with some things like PIL/Pillow for ImageField)

akira-dev commented 7 years ago

ok thx i will follow your advice

akira-dev commented 7 years ago

New release is available on pypi

philof commented 7 years ago

This is still an issue if you import SqlalchemyDataLayer.

    from flask_rest_jsonapi import Api, ResourceList, SqlalchemyDataLayer
  File "/builds/0deb0f6d/0/.tox/py35/lib/python3.5/site-packages/flask_rest_jsonapi/__init__.py", line 5, in <module>
    from flask_rest_jsonapi.data_layers import SqlalchemyDataLayer
  File "/builds/0deb0f6d/0/.tox/py35/lib/python3.5/site-packages/flask_rest_jsonapi/data_layers/__init__.py", line 4, in <module>
    from flask_rest_jsonapi.data_layers.mongo import MongoDataLayer
  File "/builds/0deb0f6d/0/.tox/py35/lib/python3.5/site-packages/flask_rest_jsonapi/data_layers/mongo.py", line 6, in <module>
    from pymongo import ASCENDING, DESCENDING
ImportError: No module named 'pymongo'

SqlalchemyDataLayer calls the data_layers/init.py module, which has the pymongo requirement from the mongo.MongoDataLayer file.

kramarz commented 7 years ago

I've made PR to fix what @philof mentioned: #9