Skip to main content

# Ultralite For when portability is critical, but you still need some HTTP convenience

## Author by Cathal Garvey, copyright 2014, proudly licensed under the [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.txt).

## About Anyone who’s coded in Python for long will have discovered [Kenneth Reitz’s “Requests” library](http://docs.python-requests.org/en/latest/), which makes HTTP operations far more clean and straightforward than provided for by the Python standard library (though things are improving on that score).

Requests is as simple to install as pip install requests, and as pip comes installed with newer distributions of Python, this is really the best way you can get good HTTP in Python.

However, there are times when you want your code to be portable and not to depend on even the easiest third-party libraries, and for that there’s Ultralite.

The goal is to support 90% of the convenience of requests, while remaining short and in-lineable, so you can literally copy/paste all of the code in this module and drop it into your own code to get a taste of requests, anywhere. And all of this while passing flake8 and pyflakes.

## How do I use this? The intended use-case is to copy/paste this into your own modules or libraries. You can also use pip install ultralight to install for use in the interactive interpreter or to list it as a dependency in setup.py.

When copy/pasting, just copy the entire Ultralite class from this module, and import the standard library modules it requires. Default headers can be added to the class attribute “_default_headers”; these will be added to all requests’ header dictionaries, with user-provided headers overwriting them.

At present this only supports HEAD and GET requests, but will handle POST/PUT/DELETE in the near future also in a manner similar to requests (enabled by improvements in the standard library).

Features provided that mimic requests:

  • Ultralite methods “get”/”head”/”put”/”post”/”delete” (not all implemented)

  • Methods return Ultralite.UltraliteResponse objects which are requests-like:
    • UltraliteResponse.headers -> dict

    • UltraliteResponse.status_code -> int

    • UltraliteResponse.reason -> str

    • UltraliteResponse.content -> bytes

    • UltraliteResponse.text -> unicode decoding of UltraliteResponse.content

    • UltraliteResponse.raw -> http.client.HTTPResponse / urllib.error.XXX

    • UltraliteResponse.request -> urllib.request.Request

    • UltraliteResponse.raise_for_status() -> Raise Ultralite.UltraliteError if http response code is not within 2XX range, otherwise do nothing.

    • UltraliteResponse.json() -> attempt json-decoding UltraliteResponse.text

## Does this depend on anything? Nope. This is valid pure-stdlib python as of Python 3.3+.

Metadata

Release files for ultralite 0.1.1

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

Source distribution (sdist)

Source distribution for ultralite 0.1.1
File Size Uploaded Provenance Actions
ultralite-0.1.1.tar.gz 2.5 kB Without provenance Details for ultralite-0.1.1.tar.gz

Release files / ultralite-0.1.1.tar.gz

Download URL ultralite-0.1.1.tar.gz
Size 2.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ca8a05a9b2f95449252ce67c8406b2b02e21c05c9603675786d069241e305de6
BLAKE2b-256 checksum
How to use checksums
484823d0d5086a56eeccca633266dd99328a51ddb22fa467227bb89787dd3a51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for ultralite 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file No provenance

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