In your code example it looks like FastAPI is making 1 HTTP request vs. your library is making 3 HTTP requests? Or are there some missing lines? Or am I missing something?
Also are you referring to https://github.com/pyopenapi/pyopenapi ? And if so what would be the reasoning to pull something like this into the standard library rather than leaving it as a third part library? Damian (he / him) On Sat, Aug 7, 2021 at 12:40 AM Vaideeswaran Ganesan <vaid...@gmail.com> wrote: > I looked at the fastapi code. > > I actually want to avoid get, post, put, 2xx, 4xx codes in the client > portions of the code. (I don't think it's pythonic). And Fastapi seems to > have them exactly the same. > Look at how the code looks when you are using FastAPI and with my OpenAPI > Native Bindings - below: > > =============== [Code using FastAPI] > def test_create_item(): response = client.post( "/items/", headers={ > "X-Token": "coneofsilence"}, json={"id": "foobar", "title": "Foo Bar", > "description": "The Foo Barters"}, ) assert response.status_code == 200 > assert response.json() == { "id": "foobar", "title": "Foo Bar", > "description": "The Foo Barters", > }. > > =============== [Code using pyopenapi - my proposal] > def test_create_item(): > client = client('host', creds).connect('/') > try: assert client.items.id == "foobar" > assert client.items.title == "Foo Bar" > assert client.items.description == "The Foo Barters" > except AttributeError: > print("Items does not exist!") > > > On Fri, Aug 6, 2021 at 10:13 PM Gustavo Carneiro <gjcarne...@gmail.com> > wrote: > >> You may want to take a look at FastAPI[1], it already does more or less >> what you ask for. >> >> There is no need for it to be part of the Python core, it's fine as it is >> as a package. >> >> [1] https://fastapi.tiangolo.com/ >> >> On Fri, 6 Aug 2021 at 17:39, Vaideeswaran Ganesan <vaid...@gmail.com> >> wrote: >> >>> OpenAPI (https://spec.openapis.org/oas/latest.html) is an emerging >>> standard for defining RESTful interfaces. >>> OpenAPI is supported by swagger - which provides tools to convert an >>> OpenAPI spec into python code (for both backend as well as client). >>> >>> The proposition I have is to make OpenAPI native to python. >>> Essentially, this involves some of the following: >>> 1. OpenAPI provides definitions of objects, arrays, structures, >>> primitive types, collections etc. >>> 2. OpenAPI supports object creation (HTTPS POST), object modification >>> (PUT), object deletion (DELETE) and object retrieval (GET). >>> 3. OpenAPI also supports operations for collections (add to collection, >>> remove from collection and modify collection) >>> 4. OpenAPI also supports methods and allows parameters to be passed to >>> these APIs. >>> >>> The Native Python implementation would load in OpenAPI specification and >>> provide native Python experience as follows: >>> 1. Primitive types are mapped to python primitive types >>> 2. Objects and structures are treated as classes or dicts wrapped. The >>> field names in the Spec are accessible. >>> 3. Arrays and Collections are mapped to python lists. >>> 4. URLs are converted into object structure. >>> 5. Python inspection methods (__getattr__, __setattr__, __new__, >>> __del__ and others) of this model is changed to manipulate the fetched >>> objects dynamically >>> >>> Parts of this implementations are found in various places : sushy >>> (OpenStack) etc. >>> However, having a more organized approach would make life easier. >>> >>> Swagger has a tool that can generate the code. But this means that >>> every time a specification changes you need to ship a new python library. >>> The methodology presented not require any addition python libraries - >>> the tool can download from the REST end point. >>> >>> By making OpenAPI native to python, we would avoid cumbersome handling >>> of request codes etc. and make it as you we are accessing native objects. >>> I can provide more details and a reference implementation I am working >>> on. >>> >>> Wanted to know if this is worthy to be submitted as PEP! >>> _______________________________________________ >>> Python-ideas mailing list -- python-ideas@python.org >>> To unsubscribe send an email to python-ideas-le...@python.org >>> https://mail.python.org/mailman3/lists/python-ideas.python.org/ >>> Message archived at >>> https://mail.python.org/archives/list/python-ideas@python.org/message/5DBYKAEXM2Z3UQZGORXMBQTBN22RQPLT/ >>> Code of Conduct: http://python.org/psf/codeofconduct/ >>> >> >> >> -- >> Gustavo J. A. M. Carneiro >> Gambit Research >> "The universe is always one step beyond logic." -- Frank Herbert >> > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/NVNZB2Y35HF6QRCI75USKZENI3HXNF3R/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/Q5S4T4BCQOPK6SPRH2OYNE3CYI6EM5JX/ Code of Conduct: http://python.org/psf/codeofconduct/