Path: csiph.com!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'static': 0.03; 'api.': 0.04; 'classes.': 0.07; 'api': 0.09; '(without': 0.09; 'frameworks,': 0.09; 'here?': 0.09; 'subject:Writing': 0.09; 'subject:module': 0.09; 'thread': 0.10; 'python': 0.10; 'skip:f 30': 0.15; 'globals.': 0.16; 'interacting': 0.16; 'received:172.18.0': 0.16; 'subject:api': 0.16; 'to:name:python- list@python.org': 0.20; 'to:2**1': 0.21; 'tuples': 0.22; "python's": 0.23; 'thus': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'example': 0.26; 'rest': 0.26; 'module.': 0.27; 'skip:( 20': 0.28; 'container': 0.29; 'initialized': 0.29; 'queue': 0.29; 'workaround': 0.29; 'objects': 0.29; 'work.': 0.30; 'call.': 0.30; 'query': 0.30; 'option': 0.31; 'returned': 0.32; 'class': 0.33; 'problem': 0.33; 'foo': 0.33; 'traditional': 0.33; 'file': 0.34; 'handle': 0.34; 'skip:d 20': 0.34; 'that,': 0.34; 'remote': 0.35; 'skip:i 20': 0.36; 'possible': 0.36; 'modules': 0.36; 'urls': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'itself': 0.38; 'represent': 0.38; 'data': 0.39; 'build': 0.40; 'well.': 0.40; 'to:addr:python.org': 0.40; 'still': 0.40; 'some': 0.40; 'ever': 0.60; 'your': 0.60; 'provide': 0.61; 'per': 0.62; 'providing': 0.62; 'more': 0.63; 'safe': 0.63; 'dont': 0.64; 'past.': 0.66; 'services.': 0.72; 'facilities': 0.72; 'authentic': 0.84 X-Authority-Analysis: v=2.1 cv=av94c3tV c=1 sm=1 tr=0 a=g3mLq75WYuDrh3Lt0JSDww==:117 a=g3mLq75WYuDrh3Lt0JSDww==:17 a=QC7fh9NfAAAA:8 a=5pFAO2ZBLFIA:10 a=8nJEP1OIZ-IA:10 a=ff-B7xzCdYMA:10 a=ZRRpdE0JF9pLNxAeHIMA:9 a=wPNLvfGTeEIA:10 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.activenetwerx.com X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=RDNS_NONE autolearn=no autolearn_force=no version=3.4.0 From: "Joseph L. Casale" To: "Sven R. Kunze" , "python-list@python.org" Subject: Re: Writing a module to abstract a REST api Thread-Topic: Writing a module to abstract a REST api Thread-Index: AQHQ8VdKzAS7nkl7nU2AayZu81Yu155BmmuAgADNE1U= Date: Fri, 18 Sep 2015 15:28:28 +0000 References: <1b35c9c9b6864d7bb9bf11e0e3cb98ca@exch.activenetwerx.com>, <55FB2A8F.9050501@mail.de> In-Reply-To: <55FB2A8F.9050501@mail.de> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [72.29.233.193] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-CMAE-Envelope: MS4wfJd/BkQwYsPbrrk+zDSgclJGNt+w+HPQLIBMaBY9DCjn9c2MI2qlsk39c0SJt0ywhEkGp5+5AIrntnX3aVQKJ+yk9picsNQvql/N+TiEk+nxcfw+AmP+JsoxHcUvmEzNyc3bYcnlujzMgdtimTl4bd5rtGbBGOQv5aU0qcO3mKTjjqjg9gWkpNu7TtfwlpPSIg== X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 56 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1442590114 news.xs4all.nl 23840 [2001:888:2000:d::a6]:57868 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96825 > Well, I would be interested in seeing such a module as well.=0A= > =0A= > Most modules and frameworks, I know, providing REST and interacting with= =0A= > REST are more like traditional SOAP-like web services. You got your=0A= > functions which have a 1-to-1 correspondence with some resource URLs and= =0A= > that's it.=0A= > =0A= > Actually REST is far more flexible than that, thus I still would love to= =0A= > see an authentic REST module.=0A= =0A= So a design pattern I use often is to create Python objects to represent=0A= objects returned from what ever api I am abstracting. For example I=0A= might create named tuples for static data I dont intend to change or=0A= for an object I can both query for and create, I might build a class to=0A= represent it.=0A= =0A= The problem now comes from the following:=0A= =0A= # foo now contains a handle to the remote api.=0A= foo =3D InstanceOfApiWrapper()=0A= =0A= # queues is a container of Queue classes.=0A= queues =3D foo.get_queues()=0A= =0A= queue =3D queues[0]=0A= queue.delete()=0A= =0A= In this case its possible for foo (InstanceOfApiWrapper) to inject a refere= nce=0A= to itself so the delete() can actually make the call.=0A= =0A= # I want to create a queue from scratch...=0A= disparate_queue =3D Queue(x, y, z)=0A= # Now what happens? No handle to an api?=0A= disparate_queue.delete()=0A= =0A= An alternative is:=0A= foo.delete_queue(disparate_queue)=0A= =0A= That's not a pattern I prefer, what facilities in Python provide for a work= around=0A= here?=0A= =0A= One option is to put everything in one module and use globals. If the handl= e is=0A= initialized it'll just work.=0A= =0A= Problem with that is its not thread safe (without work) and I subscribe to= =0A= one object per file (bloody hard with Python's import/load procedure.=0A= =0A= This is a design pattern I have struggled with in the past.=0A= jlc=