Uplink

A Declarative HTTP Client for Python, inspired by Retrofit.

Useful Links

  • Uplink @ PyPI
  • Uplink @ Github
  • Issue Tracker
  • Release History

Table of Contents

  • Installation
  • Quickstart
  • Authentication
  • Serialization
  • Clients
  • Tips & Tricks
  • API
  • Changelog

Quick search

Uplink 📡¶

A Declarative HTTP Client for Python. Inspired by Retrofit.

Release Python Version License Codecov Join the chat at https://gitter.im/python-uplink/Lobby

Note

Uplink is in beta development. The public API is still evolving, but we expect most changes to be backwards compatible at this point.

Uplink turns your HTTP API into a Python class.

from uplink import Consumer, get, headers, Path, Query

class GitHub(Consumer):
   """A Python Client for the GitHub API."""

   @get("users/{user}/repos")
   def get_repos(self, user: Path, sort_by: Query("sort")):
      """Get user's public repositories."""

Build an instance to interact with the webservice.

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

Then, executing an HTTP request is as simply as invoking a method.

repos = github.get_repos(user="octocat", sort_by="created")

The returned object is a friendly requests.Response:

print(repos.json())
# Output: [{'id': 64778136, 'name': 'linguist', ...

For sending non-blocking requests, Uplink comes with support for aiohttp and twisted (example).

Features¶

  • Quickly Define Structured API Clients
    • Use decorators and type hints to describe each HTTP request
    • JSON, URL-encoded, and multipart request body and file upload
    • URL parameter replacement, request headers, and query parameter support
  • Bring Your Own HTTP Library
    • Non-blocking I/O support for Aiohttp and Twisted
    • Supply your own session (e.g., requests.Session) for greater control
  • Easy and Transparent Deserialization/Serialization
    • Define custom converters for your own objects
    • Support for marshmallow schemas and handling collections (e.g., list of Users)
  • Extendable
    • Install optional plugins for additional features (e.g., protobuf support)
    • Compose custom response and error handling functions as middleware
  • Authentication
    • Built-in support for Basic Authentication
    • Use existing auth libraries for supported clients (e.g., requests-oauthlib)

Uplink officially supports Python 2.7 & 3.3-3.7.

User Testimonials¶

Michael Kennedy (@mkennedy), host of Talk Python and Python Bytes podcasts-

Of course our first reaction when consuming HTTP resources in Python is to reach for Requests. But for structured APIs, we often want more than ad-hoc calls to Requests. We want a client-side API for our apps. Uplink is the quickest and simplest way to build just that client-side API. Highly recommended.

Or Carmi (@liiight), notifiers maintainer-

Uplink’s intelligent usage of decorators and typing leverages the most pythonic features in an elegant and dynamic way. If you need to create an API abstraction layer, there is really no reason to look elsewhere.

User Manual¶

Follow this guide to get up and running with Uplink.

  • Installation
    • Using pip
    • Download the Source Code
    • Extras
  • Quickstart
    • Defining an API Client
    • Making a Request
    • URL Manipulation
    • Header Manipulation
    • Request Body
    • Form Encoded, Multipart, and JSON Requests
    • Handling JSON Responses
    • Persistence Across Requests from a Consumer
    • Response and Error Handling
  • Authentication
    • Basic Authentication
    • Other Authentication
    • Using Auth Support for Requests and aiohttp
  • Serialization
    • Using Marshmallow Schemas
    • Custom JSON Deserialization
    • Converting Collections
    • Writing A Custom Converter
  • Clients
    • Swapping Out the Default HTTP Session
    • Synchronous vs. Asynchronous
  • Tips & Tricks
    • Decorating All Request Methods in a Class
    • Adopting the Argument’s Name
    • Annotating Your Arguments For Python 2.7

API Reference¶

This guide details the classes and methods in Uplink’s public API.

  • API
    • The Base Consumer Class
      • Consumer
      • Session
    • Decorators
      • headers
      • params
      • json
      • form_url_encoded
      • multipart
      • timeout
      • args
      • response_handler
      • error_handler
      • inject
      • returns.*
    • Function Annotations
      • Path
      • Query
      • QueryMap
      • Header
      • HeaderMap
      • Field
      • FieldMap
      • Part
      • PartMap
      • Body
      • Url
    • HTTP Clients
      • Requests
      • Aiohttp
      • Twisted
    • Converters
      • Marshmallow
      • Converting Collections
      • Writing a Custom Converter

Miscellaneous¶

  • Changelog
    • 0.6.1 - 2018-9-14
    • 0.6.0 - 2018-9-11
    • 0.5.5 - 2018-8-01
    • 0.5.4 - 2018-6-26
    • 0.5.3 - 2018-5-31
    • 0.5.2 - 2018-5-30
    • 0.5.1 - 2018-4-10
    • 0.5.0 - 2018-4-06
    • 0.4.1 - 2018-3-10
    • 0.4.0 - 2018-2-10
    • 0.3.0 - 2018-1-09
    • 0.2.2 - 2017-11-23
    • 0.2.0 - 2017-11-03
    • 0.1.1 - 2017-10-21
    • 0.1.0 - 2017-10-19
©2018, P. Raj Kumar. | Page source
Fork me on GitHub