Skip to main content

restpylot Module

Python package

A lightweight, flexible REST API client built on the requests library. The RestClient class simplifies HTTP interactions with persistent session management for connection pooling, support for multiple authentication strategies, file operations, and comprehensive error handling—all wrapped in an intuitive, easy-to-use interface.

Features

  • HTTP Methods: Supports GET, POST, PUT, DELETE, and PATCH requests.
  • Multiple Authentication Methods: Bearer token authentication, API key headers, and custom authentication (including HTTP Basic Auth via requests.auth.AuthBase).
  • Dynamic Authentication Updates: Set or update authentication credentials at runtime without reinitializing the client.
  • File Downloads: Stream and save file responses directly to disk with configurable chunk sizes.
  • Session Management: Leverages persistent HTTP sessions for connection pooling and performance optimization.
  • Custom Headers: Easily set default headers and customize them per request.
  • Configurable Timeout: Set request timeouts to handle slow or unresponsive APIs.
  • Comprehensive Error Handling: Graceful exception handling with detailed logging for HTTP errors, timeouts, and connection issues.
  • Debug Logging: Optional detailed logging for troubleshooting API interactions and request/response inspection.

Installation

To use the restpylot module:

pip install restpylot

Usage

Initialization

You can initialize the restpylot with a base URL, headers, authorization token, timeout, and debug mode.

from restpylot import RestClient

client = RestClient(
    base_url='https://api.example.com',
    headers={'Custom-Header': 'value'},
    auth_token='your_auth_token',
    timeout=10,
    debug=True
)

Making Requests

The restpylot provides methods for making various types of HTTP requests.

GET Request

response = client.get('/endpoint', params={'key': 'value'})
print(response)

POST Request

response = client.post('/endpoint', json={'key': 'value'})
print(response)

PUT Request

response = client.put('/endpoint', json={'key': 'value'})
print(response)

DELETE Request

response = client.delete('/endpoint')
print(response)

PATCH Request

response = client.patch('/endpoint', json={'key': 'value'})
print(response)

Setting Authorization Token

You can update the authorization token at any time.

client.set_auth_token('new_auth_token')

Setting API Key

You can set an API key with a custom header.

client.set_api_key('your_api_key', header='X-Api-Key')

Closing the Session

It is a good practice to close the session when you are done with the client.

client.close()

Logging

If debug mode is enabled, the restpylot will log detailed information about the requests and responses.

License

This module is provided under the GPL-3.0 License.

Metadata

Release files for restpylot 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for restpylot 0.1.7
File Size Uploaded
restpylot-0.1.7.tar.gz 16.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for restpylot 0.1.7
File Interpreter ABI Platform
restpylot-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 33.7 kB

Release files / restpylot-0.1.7.tar.gz

Download URL restpylot-0.1.7.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
837dc957570a2867a9cce1440334cb39f32e4d81a4b724b3eda44b7bcbda5246
BLAKE2b-256 checksum
How to use checksums
db25fa1f7493f8c37c991c90f3a5d04846b7ed37858a94a4e782f2e18b3f39f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.12.13 Linux/6.17.0-1020-azure

Release files / restpylot-0.1.7-py3-none-any.whl

Download URL restpylot-0.1.7-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
250d43dcfd073d2af49e377ad0291403d9ffb6638207cdbd4e53241f2cfaf38c
BLAKE2b-256 checksum
How to use checksums
27ca21515cc1abbba64ba3c7b5dca1abc7c2e21aed1822c5daf1ee86132cbebf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.12.13 Linux/6.17.0-1020-azure

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page