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

Uploaded CPython 3.7+Windows x86-64

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

Uploaded CPython 3.7+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.7+macOS 11.0+ ARM64

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

File metadata

  • Download URL: ohttpy-0.1a11-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.1a11-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a25653603fdda5dace56e747250190db11b3b266ba6ca166927d4f6a2c639387
MD5 1e7bcb53b888de163f72facff56c84b4
BLAKE2b-256 ef59224900b2f58a642197517eafd07f1bb3a16409faaddd94a4da6f541bd20f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a11-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 77b8850100d185442111e378722024b21d4cda034f730eeed9786fa0adae4172
MD5 7e3fda4dabe97f0ac616ffc8f89c3ef5
BLAKE2b-256 492f4043fd5ee5469df1f78ad7c35900922e0d8bf5a51746b0ffbc39380a16eb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a11-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 53956b14463fe18dd28d4895eeb40e62af09e26af419ad139cb30b30bed0edb1
MD5 0416d9c9dfab02c9e392eff8e38c6c9a
BLAKE2b-256 b86a1247ff4c5fe35357ec078c20c2b9497b70729758aad47f6c70423bf01885

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a11-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4694ef9261cf2e6355b5776f3cdb7dfb988def8937e98475be9d47e04875b360
MD5 b22386238f2b6b23e70911bf21ea507f
BLAKE2b-256 861c1a3732953b8171501ab57ed3e6794ccf622cbf145caa8212bb80b4399f1d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a11-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f0fb5ecc65aa27a0d840db9deba02e50a82fa904319c57ebcceff29ce0b94e85
MD5 06cfd4d2ad0d9ddbc490f98cff2d3a3a
BLAKE2b-256 2c1b97f5ed3ca3c3428a9b0dcc734127cc6893c414ffc468208be3ec713177d0

See more details on using hashes here.

Provenance

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