Suche senden
Hochladen
Python client api
•
0 gefällt mir
•
426 views
D
dreampuf
Folgen
This slide cover the how to implement of an python client api and it's Description
Weniger lesen
Mehr lesen
Technologie
Design
Melden
Teilen
Melden
Teilen
1 von 26
Jetzt herunterladen
Downloaden Sie, um offline zu lesen
Empfohlen
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
Howard Lewis Ship
DPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark Workshop
Jeroen Keppens
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
Mongo db mug_2012-02-07
Mongo db mug_2012-02-07
Will Button
PHP Language Trivia
PHP Language Trivia
Nikita Popov
What's new in Liferay Mobile SDK 2.0 for Android
What's new in Liferay Mobile SDK 2.0 for Android
Silvio Gustavo de Oliveira Santos
(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit
Olaf Alders
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
Michael Pirnat
Empfohlen
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
Howard Lewis Ship
DPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark Workshop
Jeroen Keppens
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
Mongo db mug_2012-02-07
Mongo db mug_2012-02-07
Will Button
PHP Language Trivia
PHP Language Trivia
Nikita Popov
What's new in Liferay Mobile SDK 2.0 for Android
What's new in Liferay Mobile SDK 2.0 for Android
Silvio Gustavo de Oliveira Santos
(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit
Olaf Alders
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
Michael Pirnat
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
Mongoskin - Guilin
Mongoskin - Guilin
Jackson Tian
PHP 5.4
PHP 5.4
Federico Damián Lozada Mosto
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
Kris Wallsmith
Crazy things done on PHP
Crazy things done on PHP
Taras Kalapun
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
Nikita Popov
Modern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in Perl
Nova Patch
The state of your own hypertext preprocessor
The state of your own hypertext preprocessor
Alessandro Nadalin
Electrify your code with PHP Generators
Electrify your code with PHP Generators
Mark Baker
Testing Web Applications with GEB
Testing Web Applications with GEB
Howard Lewis Ship
Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)
MongoSF
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
Jeff Carouth
Command Bus To Awesome Town
Command Bus To Awesome Town
Ross Tuck
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
Ian Barber
Spring data iii
Spring data iii
명철 강
WordPress Cuztom Helper
WordPress Cuztom Helper
slicejack
deepjs - tools for better programming
deepjs - tools for better programming
nomocas
360|iDev
360|iDev
Aijaz Ansari
The introduction of data visualization
The introduction of data visualization
dreampuf
Refactoring
Refactoring
dreampuf
Communication with python_http_module
Communication with python_http_module
dreampuf
Python magicmethods
Python magicmethods
dreampuf
Weitere ähnliche Inhalte
Was ist angesagt?
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
Mongoskin - Guilin
Mongoskin - Guilin
Jackson Tian
PHP 5.4
PHP 5.4
Federico Damián Lozada Mosto
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
Kris Wallsmith
Crazy things done on PHP
Crazy things done on PHP
Taras Kalapun
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
Nikita Popov
Modern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in Perl
Nova Patch
The state of your own hypertext preprocessor
The state of your own hypertext preprocessor
Alessandro Nadalin
Electrify your code with PHP Generators
Electrify your code with PHP Generators
Mark Baker
Testing Web Applications with GEB
Testing Web Applications with GEB
Howard Lewis Ship
Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)
MongoSF
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
Jeff Carouth
Command Bus To Awesome Town
Command Bus To Awesome Town
Ross Tuck
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
Ian Barber
Spring data iii
Spring data iii
명철 강
WordPress Cuztom Helper
WordPress Cuztom Helper
slicejack
deepjs - tools for better programming
deepjs - tools for better programming
nomocas
360|iDev
360|iDev
Aijaz Ansari
Was ist angesagt?
(18)
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Mongoskin - Guilin
Mongoskin - Guilin
PHP 5.4
PHP 5.4
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
Crazy things done on PHP
Crazy things done on PHP
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
Modern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in Perl
The state of your own hypertext preprocessor
The state of your own hypertext preprocessor
Electrify your code with PHP Generators
Electrify your code with PHP Generators
Testing Web Applications with GEB
Testing Web Applications with GEB
Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
Command Bus To Awesome Town
Command Bus To Awesome Town
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
Spring data iii
Spring data iii
WordPress Cuztom Helper
WordPress Cuztom Helper
deepjs - tools for better programming
deepjs - tools for better programming
360|iDev
360|iDev
Andere mochten auch
The introduction of data visualization
The introduction of data visualization
dreampuf
Refactoring
Refactoring
dreampuf
Communication with python_http_module
Communication with python_http_module
dreampuf
Python magicmethods
Python magicmethods
dreampuf
Machine learning share No.1
Machine learning share No.1
dreampuf
Python profiling
Python profiling
dreampuf
A short introduction of D3js
A short introduction of D3js
dreampuf
The Outcome Economy
The Outcome Economy
Helge Tennø
Andere mochten auch
(8)
The introduction of data visualization
The introduction of data visualization
Refactoring
Refactoring
Communication with python_http_module
Communication with python_http_module
Python magicmethods
Python magicmethods
Machine learning share No.1
Machine learning share No.1
Python profiling
Python profiling
A short introduction of D3js
A short introduction of D3js
The Outcome Economy
The Outcome Economy
Ähnlich wie Python client api
Let's read code: the python-requests library
Let's read code: the python-requests library
Susan Tan
前端MVC 豆瓣说
前端MVC 豆瓣说
Ting Lv
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Tsuyoshi Yamamoto
Recent Changes to jQuery's Internals
Recent Changes to jQuery's Internals
jeresig
XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話
Takehito Tanabe
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用
Felinx Lee
Implicit parameters, when to use them (or not)!
Implicit parameters, when to use them (or not)!
Julien Truffaut
Blog Hacks 2011
Blog Hacks 2011
Yusuke Wada
What's new in Django 1.2?
What's new in Django 1.2?
Jacob Kaplan-Moss
Тестирование и Django
Тестирование и Django
MoscowDjango
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
Francois Zaninotto
Scalable web application architecture
Scalable web application architecture
postrational
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
Fabien Potencier
Objective-c Runtime
Objective-c Runtime
Pavel Albitsky
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
Norberto Leite
Mongo+java (1)
Mongo+java (1)
MongoDB
GraphQL Los Angeles Meetup Slides
GraphQL Los Angeles Meetup Slides
Grant Miller
Simplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with Morphia
MongoDB
Open Source Search: An Analysis
Open Source Search: An Analysis
Justin Finkelstein
Let's read code: python-requests library
Let's read code: python-requests library
Susan Tan
Ähnlich wie Python client api
(20)
Let's read code: the python-requests library
Let's read code: the python-requests library
前端MVC 豆瓣说
前端MVC 豆瓣说
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Recent Changes to jQuery's Internals
Recent Changes to jQuery's Internals
XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用
Implicit parameters, when to use them (or not)!
Implicit parameters, when to use them (or not)!
Blog Hacks 2011
Blog Hacks 2011
What's new in Django 1.2?
What's new in Django 1.2?
Тестирование и Django
Тестирование и Django
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
Scalable web application architecture
Scalable web application architecture
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
Objective-c Runtime
Objective-c Runtime
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
Mongo+java (1)
Mongo+java (1)
GraphQL Los Angeles Meetup Slides
GraphQL Los Angeles Meetup Slides
Simplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with Morphia
Open Source Search: An Analysis
Open Source Search: An Analysis
Let's read code: python-requests library
Let's read code: python-requests library
Kürzlich hochgeladen
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
Dropbox
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Deepika Singh
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Orbitshub
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Edi Saputra
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
Nanddeep Nachan
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
apidays
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
Architecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
Zilliz
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Andrey Devyatkin
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
apidays
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
MIND CTI
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
sammart93
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
WSO2
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
Sandro Moreira
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
apidays
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Juan lago vázquez
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
sudhanshuwaghmare1
Kürzlich hochgeladen
(20)
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Architecting Cloud Native Applications
Architecting Cloud Native Applications
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
Python client api
1.
茴香豆的茴有几种写法 记Python的⼀一个客户端实现
dreampuf Jul, 2012
2.
3.
本地调用
main printf scanf
4.
远程调用
Client Protocol Stream ServerA ServerB
5.
Esty-python
class MockAPI(API): api_url = 'http://host' api_version = 'v1' def etsy_home(self): return Test.scratch_dir def get_method_table(self, *args): return [{'name': 'testMethod', 'uri': '/test/{test_id}', 'http_method': 'GET', 'params': { 'limit': 'int', 'test_id': 'user_id_or_name', 'offset': 'int', 'fizz': 'enum(foo, bar, baz)', 'buzz': 'float', 'blah': 'unknown type', 'kind': 'string', }, 'type': 'int', 'description': 'test method.'}] def _get_url(self, url, http_method, content_type, body): return '{ "count": 1, "results": [3] }'
6.
Esty-python
class MockAPI(API): api_url = 'http://host' api_version = 'v1' def etsy_home(self): return Test.scratch_dir def get_method_table(self, *args): return [{'name': 'testMethod', 'uri': '/test/{test_id}', 'http_method': 'GET', 重用 不直观 'params': { 'limit': 'int', 不依赖URL 缺乏语法检查 'test_id': 'user_id_or_name', 'offset': 'int', 类型验证 不易调试 'fizz': 'enum(foo, bar, baz)', 'buzz': 'float', 'blah': 'unknown type', URL拓展 'kind': 'string', }, 'type': 'int', 'description': 'test method.'}] def _get_url(self, url, http_method, content_type, body): return '{ "count": 1, "results": [3] }'
7.
GuokrAPI v1
class GuokrAPI(API): HOST = "http://localhost/" METHODS = [{ "name": "get_tag", "url": "tags", "method": "GET", "description": "Get the tag instance list", }, { "name": "get_tags", "url": "tags/%(tagname)s", "method": "GET", "description": "Get a tag instance", }]
8.
GuokrAPI v1
class GuokrAPI(API): HOST = "http://localhost/" METHODS = [{ 不直观 "name": "get_tag", "url": "tags", 重用 "method": "GET", 缺乏语法检查 "description": "Get the tag instance list", 不依赖URL }, { 不易调试 "name": "get_tags", URLLIB3 "url": "tags/%(tagname)s", 类型验证 "method": "GET", URL拓展 "description": "Get a tag instance", }]
9.
GuokrAPI v2
tagging = guokr.type( import guokr 'tagging' import minerva.types as minerva ).fields({ 'id': 'int', tags = guokr.resources([ 'tag': 'string', minerva.tag 'taggable': 'taggable', ]) 'tag': 'string', 'user': 'ukey', taggings = guokr.resources([ 'date_create': 'datetime', minerva.tag, 'date_deleted': 'datetime', minerva.taggable, }).keys([ ]).namespace( 'id' 'taggings' ]).end() ) mercury.group.mixin(minerva.taggable) # POST on url /tags call = resources.tags.create().format('jsonp') # POST on url /taggings/tags/科学/group/654321 call = resources.taggings.update({ 'tag': '科学', 'taggable': group, 'user': 'afsrgx', })
10.
GuokrAPI v2
tagging = guokr.type( import guokr 'tagging' import minerva.types as minerva ).fields({ 'id': 'int', tags = guokr.resources([ 'tag': 'string', minerva.tag 'taggable': 'taggable', ]) 'tag': 'string', 'user': 'ukey', taggings = guokr.resources([ 'date_create': 'datetime', minerva.tag, 'date_deleted': 'datetime', minerva.taggable, }).keys([ ]).namespace( 'id' 'taggings' ]).end() ) mercury.group.mixin(minerva.taggable) 重用 # POST on url /tags URL拓展 call = resources.tags.create().format('jsonp') 类型验证 抽象繁多 # POST on url /taggings/tags/科学/group/654321 链式语法 call = resources.taggings.update({ 'tag': '科学', 清晰 'taggable': group, 'user': 'afsrgx', })
11.
GuokrAPI v2
12.
GuokrAPI v2
Pyt hon
13.
GuokrAPI v2
Py t hon ic
14.
GuokrAPI v3
TUPLE_TAGGINGABLE = ("article", "post", "blog", "group", "question") class GuokrAPI(API): HOST = "http://localhost:5000/" @GET("tags/%(tag)s") def get_tag(tag): pass @GET("tags/%(tag)s/feeds") def get_tag_feeds(tag, filter=str): pass @POST("tags/") def add_tag(tag, synonym=str, logo=str, description=str): pass @POST("tag/%(tag)s") def post_tag(tag, logo=str, description=str): pass class GuokrCMSAPI(GuokrAPI): @GET("cms/tags/filter:%(prefix)s") def get_tag_prefix(prefix): pass #Duplicate #@POST("cms/tags") #def add_tag(self, tag, synonym=None, logo=None, description=None): pass @POST("cms/tags/%(tag)s") def post_tag(tag, logon=str, synonyms=str): pass #synonyms VS synonym @POST("cms/tags/%(tag)s/lock")
15.
GuokrAPI v3
TUPLE_TAGGINGABLE = ("article", "post", "blog", "group", "question") class GuokrAPI(API): HOST = "http://localhost:5000/" @GET("tags/%(tag)s") 重用 def get_tag(tag): pass @GET("tags/%(tag)s/feeds") 类型验证 def get_tag_feeds(tag, filter=str): pass @POST("tags/") 清晰 def add_tag(tag, synonym=str, logo=str, description=str): pass @POST("tag/%(tag)s") 调试/直观 def post_tag(tag, logo=str, description=str): pass class GuokrCMSAPI(GuokrAPI): @GET("cms/tags/filter:%(prefix)s") def get_tag_prefix(prefix): pass #Duplicate #@POST("cms/tags") #def add_tag(self, tag, synonym=None, logo=None, description=None): pass @POST("cms/tags/%(tag)s") def post_tag(tag, logon=str, synonyms=str): pass #synonyms VS synonym @POST("cms/tags/%(tag)s/lock")
16.
结论 •统⼀一
随时注意前后接口⼀一致 •抽象 隐藏不必要的细节 •充要 只接受充分且必须的参数 •直观 对人友好,对机器友好(调试) •原生 Pythonic
17.
DATA ENTRY
18.
Data Entry v1
a = (1, 2, 3)
19.
Data Entry v2
a = {“a”:1, “b”:2, “c”:3)
20.
Data Entry v3 class
uDict(dict): def __getattr__(self, name): return self.__getitem__(name)
21.
Data Entry v4 class
uDict(dict): def __getattr__(self, name, default=None): try: return self.__getitem__(name) except KeyError: return default a = uDict(a=1, b=2, c=3) print a.b print a.g
22.
Data Entry v5
class Entry(object): def __init__(self, a, b, c): self.a = a self.b = b self.c = c
23.
Data Entry v6
from collections import namedtuple Entry = namedtuple("Entry", "a b c") a = Entry(a=1, b=2, c=3)
24.
Data Entry v7 class
Entry(namedtuple("Entry", "a b c")): def __new__(cls, a=None, b=None, c=None): return super(Entry, cls).__new__(cls, a, b, c)
25.
谢谢!
26.
REFERENCE •Etsy-python https://github.com/mcfunley/etsy-python •Lambda Picture http://www.flickr.com/photos/rofi/2097239111/
Jetzt herunterladen