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/v1"

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

# Use OpenAI SDK as normal for example llama chat (includingg stream capability)
is_stream=True
chat_completion_stream = 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 chat_completion_stream:
        print(chunk.choices[0].delta.content or "", end="")
else:
    print(chat_completion_stream.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.1a5-cp37-abi3-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.7+Windows x86-64

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

Uploaded CPython 3.7+macOS 11.0+ ARM64

ohttpy-0.1a5-cp37-abi3-macosx_10_12_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: ohttpy-0.1a5-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.1a5-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c2aa900e5e13cc032c6ab23a6d8beb52f4c0c474a8977f19a5372c736c128834
MD5 1e86f8f23d1b7af50bebe303d0b72407
BLAKE2b-256 a11ef6700892bd11cddf6fe05bf092de451abd285891e6a0adbee066391538f9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9dfe9d064482c63994d4a39e89d1030f65279a7d8da0cc46e16f87784bfb470f
MD5 91e76d8500432340394f2c7012b00c5f
BLAKE2b-256 c08fd571332a8ca1c724352df6dee85207323a97472d7a1c13b00ef5c6c0fbe8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a5-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 42681799fe4a0f4bdb274be46426c6318252ed0fd21e84812311c6b829ee83f7
MD5 3eb0d7f0d908735cbae184069bd3f8d1
BLAKE2b-256 44f98d74672fef36cccc0f210b7eabb25c9f4de3e408d49abdf0f686a2a6477c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a5-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3bf126c772362c418a6d2f3d1532c23d2d6c2392724d1e21b981d7935aa98af5
MD5 cb5be092272072fce9bd1fd10fb8d88e
BLAKE2b-256 1ca5589f67edc9fdb0daf02bae37b9b3d09254af9bbd175626177699fc8865e0

See more details on using hashes here.

Provenance

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