Skip to main content

The simplest REST requests package for quick API integration

Project description

nanorequests

PyPI version License

Overview

The simplest REST requests package for quick API integration.

The nanorequests package is a lightweight wrapper around the requests library, providing simplified HTTP request methods and exception handling.

Requirements

The nanorequests package requires the following dependencies:

  • requests

Installation

You can install the nanorequests package using pip:

pip install nanorequests

Usage

To use the nanorequests package, you can import it and create an instance of the NanoRequests class. This class provides static methods for making different types of HTTP requests.

from nanorequests import NanoRequests

# Create an instance of NanoRequests
nr = NanoRequests()

# Make a GET request
response = nr.get('https://dummyjson.com/products')

# Make a POST request
payload = {'title': 'Nano Requests Python'}
response = nr.post('https://dummyjson.com/products/add', json=payload)

The NanoRequests class also handles different types of HTTP status codes and raises specific exceptions for each status code. You can catch these exceptions and handle them accordingly.

from nanorequests import NanoRequests, NotFoundException

nr = NanoRequests()

try:
    response = nr.get('https://dummyjson.com/products/99999')
except NotFoundException as e:
    print(f"Product not found. Status code: {e.status_code}, Message: {e.message}")

Examples

GET Request

response = nr.get('https://dummyjson.com/products/1')
print(response)

POST Request

payload = {'title': 'Viral Parmar'}
response = nr.post('https://dummyjson.com/products/add', json=payload)
print(response)

PUT Request

payload = {'title': 'Python Requests PIP'}
response = nr.put('https://dummyjson.com/products/1', json=payload)
print(response)

DELETE Request

response = nr.delete('https://dummyjson.com/products/1')
print(response)

PATCH Request

payload = {'title': 'Open Source Python'}
response = nr.patch('https://dummyjson.com/products/1', json=payload)
print(response)

Features

The nanorequests package provides the following features:

  • Simplified methods for making GET, POST, PUT, DELETE, and PATCH requests.
  • Exception handling for different types of HTTP status codes.
  • Support for JSON responses which are automatically parsed in case of 2XX response.
  • Easy integration with the requests library.

Handling Custom Exceptions

from nanorequests import NanoRequests, NotFoundException, UnauthorizedException

try:
    response = NanoRequests.get('https://dummyjson.com/products/1')
    print(response)
except NotFoundException as e:
    print(f'Resource not found: {e}')
except UnauthorizedException as e:
    print(f'Unauthorized access: {e}')
except Exception as e:
    print(f'An unexpected error occurred: {e}')

Reference

For detailed information on each class and method, please refer to the source code and docstrings of the nanorequests package.

Author

The nanorequests package is developed and maintained by Viral Parmar.

License

This project is licensed under the terms of the MIT license. Please see the LICENSE.txt file for more information. Feel free to raise an issue or pull request to support this project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nanorequests-1.0.2.tar.gz (5.0 kB view details)

Uploaded Source

File details

Details for the file nanorequests-1.0.2.tar.gz.

File metadata

  • Download URL: nanorequests-1.0.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for nanorequests-1.0.2.tar.gz
Algorithm Hash digest
SHA256 ec20663e215ef7973463089ffd93518a9c3a28edecd69299c06540ad9e0dd08b
MD5 65c92f54e043073058736787c9c575b4
BLAKE2b-256 0255d882b4095444ad3af51c5f2b572db4dc696696c51bd623fa055bfc339f26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page