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.
response = session.post("http://ohttp-server/path/to/post", data="test data", stream=True)
for chunk in response.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:
    print(resp.status_code)
    print(resp.headers)
    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)
is_stream=True
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=is_stream,
)
if is_stream:
    for chunk in completion:
        print(chunk.choices[0].delta.content or "", end="", flush=True)
else:
    print(completion.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.1a8-cp37-abi3-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.7+Windows x86-64

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

Uploaded CPython 3.7+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.7+macOS 11.0+ ARM64

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

File metadata

  • Download URL: ohttpy-0.1a8-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.1a8-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9f09f0d16efd934ac449c74f792a02a9a483f8309b4de9a1e2eadd657224e22a
MD5 177ee5fc0616accebcc61fcb68255d50
BLAKE2b-256 c929ac7e4b5c9350332e431d8d3d4e0eaa85947cc71c3a194a86ab891af8cce1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a8-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0672c57c08b10da58fcaf7eb0e69ccdd4efdf12df7e0363f9db1de90ea3e2be6
MD5 221a1896754575190576f046545930a0
BLAKE2b-256 07e83afc3f5729f5c174048eb00ace0bca01e6d06a88e407c183454069261bb1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a8-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cd6680903444119fa239a1e078f01ac2a5267d3007a05eae9e051fcd86a86b8a
MD5 d5e36b7edd35c610dd697e75662f958a
BLAKE2b-256 8f45ffaffb4d4f329c1cb56dbfd34fc7410befbe59d7ddc358c4e82209b05e75

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a8-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3537ed7406a189f78e51d8cb1ff461febc0d9c320755e65e510c75547551ae11
MD5 85853813d733350462e2fafc5d880fa5
BLAKE2b-256 4593258e8fac42838aba7f0a925ed916bc380723429ef45a803d5d3d6ad3ce0e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ohttpy-0.1a8-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cb0f0dee5986707d0afcab2226ebf45a5fca8f14e6a5ab3228a65dd59f1826fa
MD5 dad1fd25dc5719b91f82a4c6db14158d
BLAKE2b-256 3a1aba48ec4c9a44e76c78fd52653b9d1d1b04c39b0d8491363a3898f24a7c50

See more details on using hashes here.

Provenance

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