kimmobrunfeldt / nap

Licence: MIT License
Convenient way to request HTTP APIs

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to nap

RESTEasy
REST API calls made easier
Stars: ✭ 12 (-71.43%)
Mutual labels:  requests
Git-API
Gets info from github and transfers into json styled data
Stars: ✭ 18 (-57.14%)
Mutual labels:  requests
opentracing-utils
Convenient utilities for adding OpenTracing support in your python projects
Stars: ✭ 20 (-52.38%)
Mutual labels:  requests
pyscrapper
📷 web scrapping in python: multiple libraries -requests, beautifulsoup, mechanize, selenium
Stars: ✭ 50 (+19.05%)
Mutual labels:  requests
spreadsheets-to-dataframes
Pycon 2021 Tutorial to help Spreadsheet (Excel) Users learn Python
Stars: ✭ 30 (-28.57%)
Mutual labels:  requests
get youtube subtitle
📺 Youtube字幕下载脚本
Stars: ✭ 56 (+33.33%)
Mutual labels:  requests
python-ogren-4-saatte-python-baslangic
(TR) 4 saatlik Python başlangıç atölyesinin içerik dokümanı. (EN version is in progress!)
Stars: ✭ 71 (+69.05%)
Mutual labels:  requests
NetworkAgent
This package is meant to make http request of an easy way inspiren in the architecture of Moya package. This package is 100% free of dependencies and works with Combine api + Codable
Stars: ✭ 16 (-61.9%)
Mutual labels:  requests
YouTube-Tutorials--Italian
📂 Source Code for (some of) the Programming Tutorials from my Italian YouTube Channel and website ProgrammareInPython.it. This is just a small portion of the content: please visit the website for more.
Stars: ✭ 28 (-33.33%)
Mutual labels:  requests
magic-api-spring-boot-starter
magic-api的spring-boot-starter版本
Stars: ✭ 30 (-28.57%)
Mutual labels:  http-api
Web-crawler-engineer-for-Python
Web-crawler-engineer-for-Python
Stars: ✭ 42 (+0%)
Mutual labels:  requests
reqwasm
HTTP requests library for WASM Apps
Stars: ✭ 81 (+92.86%)
Mutual labels:  requests
rigor
HTTP-based DSL for for validating RESTful APIs
Stars: ✭ 65 (+54.76%)
Mutual labels:  requests
ansible-api
A RESTful HTTP Api for Ansible
Stars: ✭ 122 (+190.48%)
Mutual labels:  http-api
rif
Power-user command-line tool for productive API developers
Stars: ✭ 17 (-59.52%)
Mutual labels:  http-api
NodeKit
surfstudio.github.io/nodekit
Stars: ✭ 27 (-35.71%)
Mutual labels:  requests
tiktok-downloader
Tiktok Downloader/Scraper using requests & bs4
Stars: ✭ 47 (+11.9%)
Mutual labels:  requests
django-debug-toolbar-requests
A Django Debug Toolbar panel for most popular http library requests.
Stars: ✭ 16 (-61.9%)
Mutual labels:  requests
wappdriver
Wondering how to send WhatsApp messages using Python using only 3 lines of code? You have come to the right place!
Stars: ✭ 40 (-4.76%)
Mutual labels:  requests
Interface TestPlatform
python3+django+requests+ddt+unittest接口自动化测试平台
Stars: ✭ 52 (+23.81%)
Mutual labels:  requests

Nap

Build Status Coverage Status Badge fury Badge PyPi

Nap provides convenient way to request HTTP APIs. After coding a few HTTP API wrapper classes, I decided to code Nap. It's is just a small(~150 loc) wrapper around requests. Requests is a superb HTTP library, which supports everything you'll need to get things done in today's web.

Example

from nap.url import Url
api = Url('https://api.github.com/')
# GET https://api.github.com/users
api.get('users')

users = api.join('users')
# GET https://api.github.com/users/kimmobrunfeldt
users.get('kimmobrunfeldt')

# Another way to make the same request as above:
api.get('users/kimmobrunfeldt')

Get started

Install

Python versions 2.7, 3.6, 3.7, 3.8 and PyPy are supported and tested against.

Install latest release with pip:

pip install nap

Install latest development version usin pip:

pip install git+git://github.com/kimmobrunfeldt/nap.git

Install latest development version using setup.py:

git clone [email protected]:kimmobrunfeldt/nap.git
cd nap
python setup.py install

Nap API documentation

See API documentation

Examples

Find gists from GitHub.

from nap.url import Url
api = Url('https://api.github.com/')

# Get gists since May 1st 2014 (will be paginated)
gists = api.get('gists', params={'since': '2014-05-01T00:00:00Z'})
print(gists.json())

You can also specify default keyword arguments to be passed on every request in Url initialization. All authentications supported by requests are automatically supported.

from nap.url import Url
# Keyword arguments given to Url will be given to each request method
# by default for every request.
api = Url('https://api.github.com/', auth=('user', 'pass'))

# Get authenticated user
response = api.get('user')
print(response.json())

# You can also override the default keyword arguments afterwords
response = api.get('users/kimmobrunfeldt', auth=('kimmo', 'password1'))

A bit more complicated example. Automatically convert all JSON responses to Python dict objects. Demonstrate various HTTP methods. Also raise errors from other than 200 OK responses.

from nap.url import Url
import requests

class JsonApi(Url):
    def after_request(self, response):
        if response.status_code != 200:
            response.raise_for_status()

        return response.json()

# Use https://github.com/kennethreitz/httpbin for testing
api = JsonApi('http://httpbin.org/')

# response is dict object containing parsed JSON
response = api.post('post', data={'test': 'Test POST'})
print(response)

response = api.put('put', data={'test': 'Test PUT'})
print(response)

try:
    # httpbin will response with `Method Not Allowed` if we try to do
    # POST http://httpbin.org/get
    api.post('get')
except requests.exceptions.HTTPError as e:
    print('Response was not OK, it was: %s' % e.response.status_code)

Contributing

Documentation for Nap developers

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].