Doze

Easy URL creation
Download

Doze Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Eric Moritz
  • Publisher web site:
  • http://themoritzfamily.com

Doze Tags


Doze Description

Doze is a URL building module inspired by slumber.This project attempts to take what is awesome about slumber while enabling more flexibility.UsageWe will demonstrate how to fetch data from the twitter API:import requestsfrom doze import urltwitter = url("http://api.twitter.com/1/")user_lookup = twitter.users("lookup.json")# generates "http://api.twitter.com/1/lookup.json?screen_name=ericmoritz"response = requests.get(str(user_lookup(screen_name="ericmoritz")))if response.status_code == 200: data = response.jsonelse: data = NoneWhile this code is a bit more verbose it give us much more flexibility and control over the fetching and serialization of the data.For instance if we wanted to add a object_hook to the json.loads:if response.status_code == 200: data = json.loads(response.content, object_hook=custom_object_hook)else: data = NoneYou can also reuse user_lookup to compose multiple requests:import requestsfrom doze import urltwitter = url("http://api.twitter.com/1/")user_lookup = twitter.users("lookup.json")# Fetch the user_lookup data for each screen nameusers = []for screen_name in : url = str(user_lookup(screen_name=screen_name)) response = requests.get(url) if response.status_code == 200: users.append(json.loads(response.content))If you find the dotted notation awkward you can pass the path items as arguments and the url params as kwargs:from doze import urlendpoint = url("http://example.com/v1")# dotted waydef sections(section_id): # http://example.com/v1/sections/{section_id}?page=2 url = str(endpoint.sections(section_id, page=2)) return requests.get(url).json# "functional way"def sections(section_id): # http://example.com/v1/sections/{section_id}?page=2 url = str(endpoint("sections", section_id, page=2)) return requests.get(url).jsonProduct's homepage


Doze Related Software