Giter Site home page Giter Site logo

uplink's Introduction

Uplink

Python HTTP Made Expressive. Inspired by Retrofit.

PyPI Version Build Status Coverage Status Documentation Status

A Quick Walkthrough, with GitHub API v3

Using decorators and function annotations, you can turn any plain old Python class into a self-describing consumer of your favorite HTTP webservice:

from uplink import *

# To register entities that are common to all API requests, you can
# decorate the enclosing class rather than each method separately:
@headers({"Accept": "application/vnd.github.v3.full+json"})
class GitHub(object):

    @get("/users/{username}")
    def get_user(self, username):
        """Get a single user."""

    @json
    @patch("/user")
    def update_user(self, access_token: Query, **info: Body):
        """Update an authenticated user."""

To construct a consumer instance, use the helper function uplink.build:

github = build(GitHub, base_url="https://api.github.com/")

To access the GitHub API with this instance, we simply invoke any of the methods that we defined in the interface above. To illustrate, let's update my GitHub profile bio:

response = github.update_user(oauth_token, bio="Beam me up, Scotty!").execute()

Voila, update_user(...) seamlessly builds the request (using the decorators and annotations from the method's definition), and execute() sends that synchronously over the network. Furthermore, the returned response is a requests.Response (documentation):

print(response.json()) # {u'disk_usage': 216141, u'private_gists': 0, ...

In essence, Uplink delivers reusable and self-sufficient objects for accessing HTTP webservices, with minimal code and user pain ☺️.

Installation

uplink supports Python 2.7 & 3.3-3.7. To install the package, you can use pip:

$ pip install uplink

Documentation

For more details, check out the documentation at http://uplink.readthedocs.io/.

uplink's People

Contributors

prkumar avatar itstehkman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.