pyfortified-requests
Extension of Python HTTP requests with verbose logging using pyfortified-logging, and robust handling for Downloading files containing JSON, CSV, and XML data formats and Streaming.
Important Note
This Python project is a refactoring of requests-mv-integration for the purpose of general usage intent.
Work In Progress
The following still needs to be performed for this Python project:
Unit-testing: This project will be switching over to using Python native Unit testing framework unittest.
More concise documentation is required.
Travis CI
Badges
Badges
Install
pip install pyfortified_requests
Architecture
pyfortified-requests is an extension of the Python package requests and it is used for handling all HTTP requests including APIs in REST and SOAP, screen scrapping, and handling response downloads in JSON, XML, and CSV.
Usage
URL_REST_COUNTRIES = \
'http://api.population.io/1.0/countries'
from pyfortified_requests import (
RequestsFortifiedDownload,
)
request_download = RequestsFortifiedDownload(logger_level=logging.DEBUG)
result = \
request_download.request(
request_method='GET',
request_url=URL_REST_COUNTRIES,
request_params=None,
request_retry=None,
request_headers=HEADER_CONTENT_TYPE_APP_JSON,
request_label="REST Countries"
)
json_rest_countries = result.json()
pprint(json_rest_countries)
Example
$ make run-example-countries
======================================================
run-examples pyfortified-requests
======================================================
rm -fR _tmp/*.json
======================================================
'Logger file path: ./tmp/log_1526043820.json'
[
'{"asctime": "2018-05-14 10:40:54 -0700", "levelname": "NOTE", "name": "pyfortified_requests", "version": "0.3.3", "message": "debug"}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "INFO", "name": "pyfortified_requests", "version": "0.3.3", "message": "START"}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "DEBUG", "name": "pyfortified_requests", "version": "0.3.3", "message": "REST Countries: Start"}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "DEBUG", "name": "pyfortified_requests", "version": "0.3.3", "message": "REST Countries: Start: Details", "Disk:": {"free": "91.54 GB", "percent": 60, "total": "232.62 GB", "path": "/", "used": "140.84 GB"}, "Mem": {"free": "133.81 KB", "cached": "0 B", "total": "16.00 GB", "used": "13.19 GB", "shared": "0 B", "buffers": "0 B"}, "allow_redirects": true, "build_request_curl": true, "cookie_payload": null, "request_auth": null, "request_cert": null, "request_data": null, "request_headers": {"Content-Type": "application/json", "User-Agent": "(pyfortified-requests/0.3.3, Python/3.5.4)"}, "request_json": null, "request_label": "REST Countries", "request_method": "GET", "request_params": null, "request_retry": {"tries": 3, "delay": 10, "timeout": 60}, "request_url": "http://api.population.io/1.0/countries", "stream": false, "timeout": null, "verify": true}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "DEBUG", "name": "pyfortified_requests", "version": "0.3.3", "message": "REST Countries: Start", "request_label": "REST Countries", "request_retry_excps": ["ConnectTimeout", "ReadTimeout", "Timeout"], "request_retry_http_status_codes": [500, 502, 503, 504, 429], "timeout": null}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "DEBUG", "name": "pyfortified_requests", "version": "0.3.3", "message": "REST Countries: Attempt", "attempts": 1, "delay": 10, "request_label": "REST Countries", "request_url": "http://api.population.io/1.0/countries", "timeout": 60, "tries": 3}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "DEBUG", "name": "pyfortified_requests", "version": "0.3.3", "message": "REST Countries: Session: Details", "cookie_payload": {}, "request_label": "REST Countries"}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "DEBUG", "name": "pyfortified_requests", "version": "0.3.3", "message": "REST Countries: Details", "request_data": "", "request_headers": {"Content-Type": "application/json", "User-Agent": "(pyfortified-requests/0.3.3, Python/3.5.4)"}, "request_label": "REST Countries", "request_method": "GET", "request_params": {}, "request_url": "http://api.population.io/1.0/countries", "timeout": 60}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "NOTE", "name": "pyfortified_requests", "version": "0.3.3", "message": "REST Countries: Curl", "request_curl": "curl --verbose -X GET -H \'Content-Type: application/json\' -H \'User-Agent: (pyfortified-requests/0.3.3, Python/3.5.4)\' --connect-timeout 60 -L \'http://api.population.io/1.0/countries\'", "request_label": "REST Countries", "request_method": "GET"}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "DEBUG", "name": "pyfortified_requests.support.requests_session_client", "version": "0.3.3", "message": "Session Request: Details", "allow_redirects": true, "headers": {"Content-Type": "application/json", "User-Agent": "(pyfortified-requests/0.3.3, Python/3.5.4)"}, "method": "GET", "timeout": 60, "url": "http://api.population.io/1.0/countries", "verify": true}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "DEBUG", "name": "pyfortified_requests", "version": "0.3.3", "message": "REST Countries: Response: Details", "http_status_code": 200, "http_status_desc": "Request fulfilled, document follows", "http_status_type": "Successful", "response_headers": {"Vary": "Accept", "Allow": "OPTIONS, GET", "Cache-Control": "max-age=3600", "Via": "1.1 7bfcc2251021d9dc94a87ff179d69731.cloudfront.net (CloudFront)", "Expires": "Mon, 14 May 2018 18:23:07 GMT", "Connection": "keep-alive", "X-Amz-Cf-Id": "_Q_sioBJ9zkP0pFZztqnQJHLBXl5DWoAnGnb2HBGxJHDEmPX4jH82g==", "Date": "Mon, 14 May 2018 17:23:07 GMT", "Content-Type": "application/json", "Server": "nginx/1.10.2", "Content-Length": "1572", "X-Cache": "Hit from cloudfront", "Age": "1039", "Content-Encoding": "gzip"}}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "DEBUG", "name": "pyfortified_requests", "version": "0.3.3", "message": "REST Countries: Cookie Payload", "cookie_payload": {}, "request_label": "REST Countries"}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "DEBUG", "name": "pyfortified_requests", "version": "0.3.3", "message": "REST Countries: Try Send Request: Is Return Response: Checking", "request_url": "http://api.population.io/1.0/countries"}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "DEBUG", "name": "pyfortified_requests", "version": "0.3.3", "message": "REST Countries: Try Send Request: Is Return Response: Valid", "request_url": "http://api.population.io/1.0/countries"}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "INFO", "name": "pyfortified_requests", "version": "0.3.3", "message": "REST Countries: Finished", "request_time_msecs": 96}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "DEBUG", "name": "pyfortified_requests", "version": "0.3.3", "message": "REST Countries: Usage", "Disk:": {"free": "91.54 GB", "percent": 60, "total": "232.62 GB", "path": "/", "used": "140.84 GB"}, "Mem": {"free": "133.17 KB", "cached": "0 B", "total": "16.00 GB", "used": "13.19 GB", "shared": "0 B", "buffers": "0 B"}}\n',
'{"asctime": "2018-05-14 10:40:55 -0700", "levelname": "INFO", "name": "pyfortified_requests", "version": "0.3.3", "message": "COMPLETED", "connection": "<requests.adapters.HTTPAdapter object at 0x104096be0>", "cookies": "<RequestsCookieJar[]>", "elapsed": "0:00:00.079948", "encoding": null, "headers": "{\'Allow\': \'OPTIONS, GET\', \'Cache-Control\': \'max-age=3600\', \'Content-Length\': \'1572\', \'Vary\': \'Accept\', \'Age\': \'1039\', \'Connection\': \'keep-alive\', \'X-Cache\': \'Hit from cloudfront\', \'Content-Type\': \'application/json\', \'Server\': \'nginx/1.10.2\', \'Via\': \'1.1 7bfcc2251021d9dc94a87ff179d69731.cloudfront.net (CloudFront)\', \'Expires\': \'Mon, 14 May 2018 18:23:07 GMT\', \'Date\': \'Mon, 14 May 2018 17:23:07 GMT\', \'X-Amz-Cf-Id\': \'_Q_sioBJ9zkP0pFZztqnQJHLBXl5DWoAnGnb2HBGxJHDEmPX4jH82g==\', \'Content-Encoding\': \'gzip\'}", "history": [], "raw": "<urllib3.response.HTTPResponse object at 0x1040a86d8>", "reason": "OK", "request": "<PreparedRequest [GET]>", "status_code": 200, "url": "http://api.population.io/1.0/countries"}\n',
]
'DEBUG'
{
'countries': [
'Afghanistan',
'AFRICA',
'Albania',
'Algeria',
'Angola',
'Antigua and Barbuda',
'Arab Rep of Egypt',
'Argentina',
'Armenia',
'Aruba',
'ASIA',
'Australia',
'Australia/New Zealand',
'Austria',
'Azerbaijan',
'The Bahamas',
***
'Uganda',
'Ukraine',
'United Arab Emirates',
'United Kingdom',
'United States',
'US Virgin Islands',
'Uruguay',
'Uzbekistan',
'Vanuatu',
'Vietnam',
'Western Africa',
'Western Asia',
'Western Europe',
'Western Sahara',
'World',
'Zambia',
'Zimbabwe',
],
}
Classes
class RequestsFortified – Base class using requests with retry functionality and verbose logging.
class RequestsFortifiedDownload – Download file handling.
class RequestsFortifiedUpload – Upload file handling.
Requirements
pyfortified-requests module is built upon Python 3 and has dependencies upon several Python modules available within Python Package Index PyPI.
make install
or
python3 -m pip uninstall --yes --no-input -r requirements.txt
python3 -m pip install --upgrade -r requirements.txt
Packages
beautifulsoup4: https://pypi.python.org/pypi/beautifulsoup4
deepdiff: https://pypi.python.org/pypi/deepdiff
pyfortified-logging: https://pypi.org/project/pyfortified-logging
pyhttpstatus-utils: https://pypi.python.org/pypi/pyhttpstatus-utils
requests: https://pypi.python.org/pypi/requests
safe-cast: https://pypi.python.org/pypi/safe-cast
Metadata
Release files for pyfortified-requests 0.3.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyfortified-requests-0.3.6.tar.gz | 33.6 kB | Without provenance | Details for pyfortified-requests-0.3.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyfortified_requests-0.3.6-py3-none-any.whl | Python 3 | none | any | Details for pyfortified_requests-0.3.6-py3-none-any.whl |
Total release size: 72.2 kB
Release files / pyfortified-requests-0.3.6.tar.gz
| Download URL | pyfortified-requests-0.3.6.tar.gz |
|---|---|
| Size | 33.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a704863cd1b673861347bb20af540448fe984a3c434d849abc4da704991ac61b
|
|
BLAKE2b-256 checksum How to use checksums |
678dfbd58eb7bead6f135deef8e62e1149ee29c3fda80bb9f77191af7906d916
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pyfortified_requests-0.3.6-py3-none-any.whl
| Download URL | pyfortified_requests-0.3.6-py3-none-any.whl |
|---|---|
| Size | 38.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a7bb206b2d95e27b5af4dae428f21c3be848d0b3ec896067b80324ed649d4a9
|
|
BLAKE2b-256 checksum How to use checksums |
84d2c16d897657493855f0914c27fe9f37fa397d967529715d71813926fed7f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pyfortified-requests 0.3.6
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.