Skip to main content

A package that allows for client-side OHTTP-wrapping over HTTP communication

Project description

ohttpy Package

Introduction

This package allows for client-side OHTTP-wrapping over HTTP communication. It acheives this by providing drop-in replacement classes for requests.Session and httpx.BaseTransport classes that abstract the OHTTP layer.

NOTE: This package utilizes a modified Rust library that implements OHTTP and relies on the chunked OHTTP protocol which has not been ratified into a standard at the time of writing.

NOTE: At the time of writing, this package is currently under active development and therefore, only compatible with chunked-OHTTP gateways that advertise public keys in a specific fashion.

Requests Session Example

To use OHTTP in a requests.Session setting, simply replace the object construction with ohttp.Session:

import ohttpy

# Create ohttpy session that inherits from requests.Session.
session = ohttpy.Session()

# Use session like a request.Session.
response = session.post("http://ohttp-server/path/to/post", data="test data")
print(response.text)

HTTPX Transport Example

To use OHTTP in a httpx.Transport setting, simply replace the object construction with ohttp.Transport:

import httpx
import ohttpy

# Initialize httpx client with the ohttpy Transport that inherits from httpx.Transport
httpx_client = httpx.Client(transport=ohttpy.Transport())

# Use client as normal including chunked-encoding response support.
method = "GET"
url = "http://ohttp-server/path/to/get/"
with httpx_client.stream(method, url) as resp:
    print(resp.status_code)
    print(resp.headers)
    for chunk in resp.stream:
        print(chunk.decode(), end="")

This is also applicable to clients that utilize httpx for their HTTP communication, for example openai client:

import httpx
import openai
import ohttpy

# Initialize httpx client with the ohttpy Transport that inherits from httpx.Transport
httpx_client = httpx.Client(transport=ohttpy.Transport())
base_url = "http://ohttp-server"
api_key = "API_KEY"

# Configure OpenAI client with httpx client
client = openai.OpenAI(
    api_key=api_key,
    http_client=httpx_client,
    base_url=base_url + "/v1")

# Use OpenAI SDK as normal for example llama chat (including stream capability)
is_stream=True
completion = client.chat.completions.create(
    model="meta-llama/Llama-3.2-3B-Instruct",
    messages=[
        {
            "role": "user",
            "content": "Create a song that captures the spirit and history of cybersecurity",
        }
    ],
    temperature=0.2,
    top_p=0.7,
    max_tokens=1024,
    stream=is_stream,
)
if is_stream:
    for chunk in completion:
        print(chunk.choices[0].delta.content or "", end="", flush=True)
else:
    print(completion.choices[0].message.content)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ohttpy-0.1a7-cp37-abi3-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.7+Windows x86-64

ohttpy-0.1a7-cp37-abi3-manylinux_2_28_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.28+ ARM64

ohttpy-0.1a7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ x86-64

ohttpy-0.1a7-cp37-abi3-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

ohttpy-0.1a7-cp37-abi3-macosx_10_12_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file ohttpy-0.1a7-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: ohttpy-0.1a7-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.7+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ohttpy-0.1a7-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0d356a049f861e38d25479c93b52c5b97101099bd4c09f7f80e5a78a77274730
MD5 4e1990397fc8c49f52c00e18371d9a2e
BLAKE2b-256 c3bcba28a85e72205329452467a13ea3793c1b340f6e20d40a8387add70da4cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for ohttpy-0.1a7-cp37-abi3-win_amd64.whl:

Publisher: CI.yml on Lorica-Cyber/ohttpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ohttpy-0.1a7-cp37-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ohttpy-0.1a7-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d37e1369e3ef68c977fb1b7851179bfa85bbb7f4a2bbe237101f85a9e9b207e3
MD5 87a56e88e84e1a6069cc0d831a19ce3d
BLAKE2b-256 4eaf467c89236c1ed5ae938f44cdc83d53e571b1c072ee5e6eb61e9bf5c26c79

See more details on using hashes here.

Provenance

The following attestation bundles were made for ohttpy-0.1a7-cp37-abi3-manylinux_2_28_aarch64.whl:

Publisher: CI.yml on Lorica-Cyber/ohttpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ohttpy-0.1a7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ohttpy-0.1a7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3496bcbc05c1eb10277918306c2b8b9ab7c02892761840d0002427c08252e4a0
MD5 0428cea56e15c14ca9aa8bfedfcd2bcc
BLAKE2b-256 26c6c7c5584330ace3d56403340a13dbb9e3c064535133d24937066fa6a250a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for ohttpy-0.1a7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: CI.yml on Lorica-Cyber/ohttpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ohttpy-0.1a7-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ohttpy-0.1a7-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 03ddd25e4b1eed4d26c854703956d80c70e1f709c557cdc088dd21ce1c2a8a83
MD5 575d67e1c730ae6aa7b7fb1c5fb46315
BLAKE2b-256 664af47d18a91ccbce907d3b98dcf919226572ea4173ce3655fc69db5e7af21e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ohttpy-0.1a7-cp37-abi3-macosx_11_0_arm64.whl:

Publisher: CI.yml on Lorica-Cyber/ohttpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ohttpy-0.1a7-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ohttpy-0.1a7-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c91069b235f43d3d21d9c170b8b72222ac231b1befb205aad0ee1786bb1c9c8a
MD5 fbe94786210158defdc529ebb5d1ba78
BLAKE2b-256 5ce65c7a1a9eb51a8df97d5c7af77d3e465c68247a464b83ba5b5580793b7729

See more details on using hashes here.

Provenance

The following attestation bundles were made for ohttpy-0.1a7-cp37-abi3-macosx_10_12_x86_64.whl:

Publisher: CI.yml on Lorica-Cyber/ohttpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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