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

Uploaded CPython 3.7+Windows x86-64

ohttpy-0.1a12-cp37-abi3-manylinux_2_28_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.7+macOS 11.0+ ARM64

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

File metadata

  • Download URL: ohttpy-0.1a12-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.1a12-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 29b6919f5eb97e104509249b90c2f6061670262011f74717a8f08d3bc6690511
MD5 c60e8fb5b88ad8a6e7a2ed221406739a
BLAKE2b-256 c47fa7e083819a61480561bfcd32098bbe4f82094774abdd188a793e54aee2a2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a12-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 190921e69436ff6a6bd14c232d887d3f2a694449c6251d43725e0079ec4b62af
MD5 c20b2a595502b55c2074f28c1a1fed9d
BLAKE2b-256 6b961b38bf1bcbafd444115982135f77c9312850de32627b762cc61d95314c85

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a12-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2f44780ef036d6816c77165f922341325ec01dd9897547aa8b7110e257245cb6
MD5 678393b6e4b58ee191114bdea7263d3d
BLAKE2b-256 16580fe5ad0530042fcd6bb1d92c34b0c2ce0e6a9310ae0e24acfa08da898c01

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a12-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 88e9f07787c4187a27cc0cd0538db58702dbcc0ca0cb0ead5a0a28ea2af890bd
MD5 3566db1466100636f73615e95e851066
BLAKE2b-256 6218ab978c625a20928350a7a625bcf3ee80a302529807dd2f567ccea5fd5ad7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a12-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2df9534fc60205b10735edd0ab5ad3c8736f54612b6344a79660a1426b7b1f13
MD5 75178f8302b91a554321a85c20c2f1a3
BLAKE2b-256 0d1a6f8d5b1b1e45766a5fa8807f4702bcf4f183631455f02d5e6379eed6f596

See more details on using hashes here.

Provenance

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