From python-list Tue May 14 09:47:33 2019 From: Dotan Cohen Date: Tue, 14 May 2019 09:47:33 +0000 To: python-list Subject: Re: Most "pythonic" syntax to use for an API client library Message-Id: X-MARC-Message: https://marc.info/?l=python-list&m=155782733111564 I highly recommend going with the last approach. With the last approach you can pass around objects in proper OOP fashion. This will be familiar to most contributors to your project and most devs that you hire. foo = api.customers(1) if bar==baz: foo.update(Name='Leroy') else: foo.delete() On Mon, Apr 29, 2019 at 4:43 AM Jonathan Leroy - Inikup via Python-list wrote: > > Hi all, > > I'm writing a client library for a REST API. The API endpoints looks like this: > /customers > /customers/1 > /customers/1/update > /customers/1/delete > > Which of the following syntax do you expect an API client library to > use, and why? > > 1/ > api.customers_list() > api.customers_info(1) > api.customers_update(1, name='Bob') > api.customers_delete(1) > > 2/ > api.customers.list() > api.customers.info(1) > api.customers.update(1, name='Bob') > api.customers.delete(1) > > 3/ > api.customers.list() > api.customers(1).info() > api.customers(1).update(name='Bob') > api.customers(1).delete() > > ...any other? > > #3 seems to be more "pretty" to me, but I did not find any "official" > recommendation online. > > Thanks. > > -- > Jonathan. > -- > https://mail.python.org/mailman/listinfo/python-list -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- https://mail.python.org/mailman/listinfo/python-list