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

Uploaded CPython 3.7+Windows x86-64

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

Uploaded CPython 3.7+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.7+macOS 11.0+ ARM64

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

File metadata

  • Download URL: ohttpy-0.1a9-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.1a9-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5cfb92348ef1082b76bb09beae1def31b3bfe2380e2a77acbec6a21584221609
MD5 edde7cf826feb9a453faf02f05cf3ba8
BLAKE2b-256 74528306230cb26742ffa894ae9005d74587be18b2ac6af110df3dcbf0f233f2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a9-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3afe4825b76a910e023064901fbff476512939406ccc28260785df725ec63e39
MD5 fbf7ac798c04a15926782edb93533d7b
BLAKE2b-256 0fbee077c102c53ce137d5aa7a696c19fb38a4325425085c1e60288fb8765bf6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a9-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 73f83ac0b4a5eef838858aa24cd4fd4ded81286b44d1fdd2a426ccea0ac5595d
MD5 e0f71b9ae26a854f5c1bdb19311b2fe2
BLAKE2b-256 7fac9ac56c533679b7c8fdb7e20dd1c426cd178c054d67c69f09b6ea71c58384

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a9-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 35124bdf47da1ecf7e8b28993db03d8ac455be640dd125ba650c2f751abe3b30
MD5 b4acd09c125cce44f2ab75822389ed89
BLAKE2b-256 125282d98341952b26f23cdd35943ced35fa7a133e754bb54af37e5494055234

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a9-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1fce4bf18e52b9a83ab07a43049c26a38aa1bdd9bf5514d0ad40551eebf78d97
MD5 5b7f624c957b5e556626c38cd0a11637
BLAKE2b-256 7719559577f46acfacec64ed8727dd4d8d620bc1b0a4f0cb223f922a043e687a

See more details on using hashes here.

Provenance

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