Skip to main content

pickle-openai

PyPI version License: MIT

Securely serialize and deserialize OpenAI client instances.

This library allows you to safely store your OpenAI client configuration (including API keys) in an encrypted format. It uses pickle for serialization and cryptography for strong encryption, requiring a password to protect your data.

Installation

pip install pickle-openai

Usage

Here's how to securely dump an OpenAI client to an encrypted string and load it back.

import os
from pickle_openai import PickledOpenAI
from openai import OpenAI

# 1. Initialize your OpenAI client
# Make sure OPENAI_API_KEY is set in your environment
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))

# 2. Create a PickledOpenAI instance from your client
pickled_client = PickledOpenAI.from_openai(client)

# 3. Dump the client to a password-protected, encrypted string
password = "your-strong-password"
encrypted_string = pickled_client.pickle_dumps(password)

print(f"Encrypted client string: {encrypted_string}")

# You can now store this encrypted_string safely.

# 4. Load the client back from the encrypted string
loaded_pickled_client = PickledOpenAI.pickle_loads(encrypted_string, password)

# 5. Recreate the OpenAI client
recreated_client = loaded_pickled_client.to_openai_sync()

# The recreated client is ready to use
response = recreated_client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello world!"}],
)
print(f"OpenAI API Response: {response.choices[0].message.content}")

This works for both openai.OpenAI and openai.AzureOpenAI clients (and their async versions).

License

This project is licensed under the MIT License.

Metadata

Release files for pickle-openai 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pickle-openai 0.1.0
File Size Uploaded
pickle_openai-0.1.0.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pickle-openai 0.1.0
File Interpreter ABI Platform
pickle_openai-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.1 kB

Release files / pickle_openai-0.1.0.tar.gz

Download URL pickle_openai-0.1.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c7ca1a45c4d84655264d8c85c3799c1a6e44a2b4a34e65a31bd1adbafff635e7
BLAKE2b-256 checksum
How to use checksums
ec8b12e683aa800865762d4f0fb54f11e4f8bab39eb6f95717a273d162721a53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.11.13 Darwin/24.5.0

Release files / pickle_openai-0.1.0-py3-none-any.whl

Download URL pickle_openai-0.1.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb0c4539474e5168ecf84ee073a0f44978c5dea1a5bdd93c397f0ffc3254dc77
BLAKE2b-256 checksum
How to use checksums
29eb979610654bf306929e0a78194b76db3634ea867027031037bce6f66d801f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.11.13 Darwin/24.5.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page