4

For working with data from a database inside of Python programmes, we generally use Object Relational Mappers, to translate database entries into python objects we can work with, with sqlAlchemy and Django Models probably being the most common and advanced ORMs.

Are there ORMs that do not connect to a database but to a third party (JSON) REST API instead? I would like to have a framework which lets me deal with Python objects to perform CRUD operations on the API. This should have all the well-established standard functionalities of an ORM, including Unit of Work and Lazy Loading. Actually, I would want my python code to be agnostic about whether the model is stored in a database or being fetched from a third party API.

It is hard for me to imagine that such a thing does not yet exist. But I am not able to find it. Maybe I am not knowing the right words to search for it?

5
  • Even I am facing the same problem and surprised there is not much discussion about this! Did you find any useful packages / resources on how to implement this ? Commented Apr 15, 2022 at 11:40
  • 1
    @gowthz In the end, I was avoiding a one-size-fits-all solution, very much in the spirit of KISS mentioned in the asnwer. Nowadays I usually implement a lightweight client for the API which is capable of the operations I actually need. Commented Apr 15, 2022 at 20:30
  • Can you please share any good resources to read up on it ? I am just getting started but clueless on where to start or what to look for. Commented Apr 16, 2022 at 2:39
  • 1
    I have asked the same question to myself. I was struggling to look for a good ORM reference implementation for Rest Api, especially to improve the pyairtable ORM implementation. I came to the conclusion, that an ORM does not make sense at all for me, as it violates the solid principle. I noticed that I spent way more time than doing it "normal" and it also looks like ORM is a code smell. I suggest to have a look at this video, it helped me a lot to understand the Solid principle. youtube.com/watch?v=pTB30aXS77U Commented Nov 21, 2022 at 8:10
  • @NicoHood Thanks a lot for sharing this. I was working on a Django app and wanted to integrate a REST API which involved performing CRUD operations on many different objects. I ended up using Pydantic package and it fit very well and had all the features that were required. Commented Nov 22, 2022 at 17:03

1 Answer 1

3

ORMs Frameworks are frameworks that connect to databases. From your description you are talking about a DAO pattern, not about a Framework. This is a common programming pattern in other languages such as Java.

The right words or searches would be:

  • Search for the DAO pattern, what to expect from it and how to code it.
  • Check a couple of links on examples of DAO patterns in python such as this one, or this other one
  • Analyze your specific problem. You might not need all the code other solutions offer you. And you might be better off coding yourself your own class adjusted to your needs.

Remember KISS and DRY.

PS: Different languages use different paradigms, it is a common error to try to extrapolate patterns and coding uses from one language to another. So something that is solved in e.g. Java in a way, might not be the best option for Python. Keep that in mind too.

Sign up to request clarification or add additional context in comments.

2 Comments

By our days, one may consider that a REST-API could be a database like any others, with some limitations ... just like SQLite for example. There's various usage where a django Webservice A needs to access entities held by another django webservice B. Such a wrapper would ease radically that kind of development.
I didn't know this site was still active. Use an LLM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.