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.
  • Response Cleanup: Close each response after processing, including streamed downloads; use the client as a context manager to close its session automatically.
  • Session Management: Leverages persistent HTTP sessions for connection pooling and performance optimization.
  • Custom Headers: Set session-wide defaults or provide headers for an individual request without changing session defaults.
  • 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)

All request methods accept an optional headers argument. These headers apply only to that request, override matching session headers, and leave other session defaults in place.

response = client.get('/endpoint', headers={'X-Request-ID': 'one-off'})

POST Request

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

Use data instead of json to send form-encoded data. A request cannot specify both.

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

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_apikey_header('your_api_key', api_key_type='X-Api-Key')

Session Cleanup

Use the client as a context manager to close the session automatically when the block exits, including when an exception is raised.

with RestClient(base_url='https://api.example.com') as client:
    response = client.get('/endpoint')

You can also close the session explicitly:

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.2.2

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.2.2
File Size Uploaded Provenance Actions
restpylot-0.2.2.tar.gz 17.3 kB Without provenance Details for restpylot-0.2.2.tar.gz

Built distribution (wheel)

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

Total release size: 35.4 kB

Release files / restpylot-0.2.2.tar.gz

Download URL restpylot-0.2.2.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
676b165ae04769478f0c363839df45776dcda221737a2ad17d2ddedec972b5d3
BLAKE2b-256 checksum
How to use checksums
4a3b5bf8d52cd3c1de7865c07b419852789bbe8569e39bc7a53afbb04c05d157
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.12.15 Linux/7.0.0-1017-azure

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

Download URL restpylot-0.2.2-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fbbf2aaf2818ec420fbaa55449679d24831c9c470a9f25521f0415b28a4356d1
BLAKE2b-256 checksum
How to use checksums
6512b43407fe133f402759331ff262104c9d768c46a2110f680c52a597e52aaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.12.15 Linux/7.0.0-1017-azure

Security for restpylot 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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