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

Uploaded CPython 3.7+Windows x86-64

ohttpy-0.1a3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

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

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

Uploaded CPython 3.7+macOS 11.0+ ARM64

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

File metadata

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

File hashes

Hashes for ohttpy-0.1a3-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f3aa0227d11d82fc7cbd8837b7e63ea5ee85126116bbab412b8401e7acafd8f7
MD5 da60623dafbb932581aea899906b43b8
BLAKE2b-256 ebd3761a2cc07380a46c82d2f6abc746bcd8033646cf0bc18c8287e0804bec1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ohttpy-0.1a3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 12f9433468c3685b474e432f790c5d08925dc563b1e28c47e5f3d09ce8992842
MD5 3c61d35dbf89a4dcda11dd2a2ca9591e
BLAKE2b-256 eaadbf1394fec41531e4d5c2d76d857d9eb235e415c1deb13794808926e4756a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ohttpy-0.1a3-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d530646928ea26a96bfa77e0e2061efbb8bb9820f09e6c6cad8dd508f7cc4a72
MD5 1a23411deb52e3120824f6cd170131bc
BLAKE2b-256 b3d27236fad8854f678f6177e86c6f77e22d7f462bf1cd8431aebd4f386c54ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ohttpy-0.1a3-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5c9018b88bbe8b0d5590f4faea132b284e4d7062e0032115847ea1789332b527
MD5 6a8ef37061c03951529731c09b44029a
BLAKE2b-256 5163d00412afc3809f9cc701bd8f9a1935f7a88521386859d6739d30860eb4c6

See more details on using hashes here.

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