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 ohttpy.Session:

import ohttpy

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

# Use session like a request.Session including streaming response support.
resp = session.post("http://ohttp-server/path/to/post", data="test data", stream=True)
resp.raise_for_error()
for chunk in resp.iter_content():
    if chunk:
        print(chunk.decode(), end="", flush=True)

HTTPX Transport Example

To use OHTTP in a httpx.Transport setting, simply replace the object construction with ohttpy.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 streaming response support.
method = "GET"
url = "http://ohttp-server/path/to/get/"
with httpx_client.stream(method, url) as resp:
    resp.raise_for_error()
    for chunk in resp.stream:
        print(chunk.decode(), end="", flush=True)

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())
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=url + "/v1")

# Use OpenAI SDK as normal for example llama chat (including stream capability)
completion = client.chat.completions.create(
    model="meta-llama/Llama-3.2-3B-Instruct",
    messages=[
        {"role": "system", "content": "You are a helpful AI assistant."},
        {"role": "user", "content": "where does the sun rise from?"},
    ],
    temperature=0.2,
    top_p=0.7,
    max_tokens=1024,
    stream=True,
)
for chunk in completion:
    print(chunk.choices[0].delta.content or "", end="", flush=True)

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.1a10-cp37-abi3-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.7+Windows x86-64

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

Uploaded CPython 3.7+manylinux: glibc 2.28+ ARM64

ohttpy-0.1a10-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.1a10-cp37-abi3-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

ohttpy-0.1a10-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.1a10-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: ohttpy-0.1a10-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.1a10-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ccba03d0928c63d998f6ace6c16acbcb2c3663518d1e204a89822c96fb1627bb
MD5 9d1cbe80e63b4d4a67169cebfb446772
BLAKE2b-256 07ca7643f5a990466d1828ea2e7dcbc0a9f255a56daeae226366deab9293e849

See more details on using hashes here.

Provenance

The following attestation bundles were made for ohttpy-0.1a10-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.1a10-cp37-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ohttpy-0.1a10-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9efd9e45ab7bb19126a39f490098be8e70967d66d791231ea55d67944bcb7cb9
MD5 b90abe6afb90ff4bd30759bbf00a2cba
BLAKE2b-256 bb5577cb494f45a2b0653e3d9040bac576cdc9bdbad20330a2f28c08edc9c0c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for ohttpy-0.1a10-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.1a10-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ohttpy-0.1a10-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1e0ea6063ed2b15aa7b92e10d1c93f2ec4364198d92078046412beb55486da5e
MD5 0931f0e686e64a8786f48d2b94250012
BLAKE2b-256 0edf2320a3946e176db0bd2ee2a68bfe8492ae5550ceb9eed221f7fb4fd8ccae

See more details on using hashes here.

Provenance

The following attestation bundles were made for ohttpy-0.1a10-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.1a10-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ohttpy-0.1a10-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0d9b07e2fa0dd65115bd98aacc2e1a26a874d9856d07d32dd20b919ac549c9c1
MD5 cf811b68aec4d02a0b9548d567b48f5d
BLAKE2b-256 2088f4d69ed3fb7f2826f7e1ef7b8dc31f412bf5fa529b53c023ad24aa3493d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for ohttpy-0.1a10-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.1a10-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ohttpy-0.1a10-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 284f93bcac024c617bcd1344809b0b66be1950da636a2f54bd6f242bfbe95b7c
MD5 7310249e0730ca31ebf7a54e3e1a8cef
BLAKE2b-256 561c3c4065f8207bc44b40a3b64544dd3ec1de7755c94202bc0780fd0365acd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for ohttpy-0.1a10-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