Skip to main content

G4F-like OpenAI compatible wrapper for Perchance AI generators

Project description

Perchancy 🚀

PyPI version License: MIT

Perchancy is a high-speed, OpenAI-compatible Python wrapper for Perchance AI generators. It allows you to programmatically generate text and images using the vast community-driven generators on Perchance with zero manual browser management.


✨ Key Features

  • ⚡ Blazing Fast: Optimized scanning algorithms for near-instant image and text extraction.
  • 🤖 Automatic Lifecycle: No need to call close(). The browser closes automatically when your script finishes or encounters an error.
  • 🔄 Auto-Sync Chrome: Automatically downloads and matches the correct version of Chrome for Testing to prevent driver errors.
  • 📽️ Streaming Support: Real-time text generation streaming (just like the native OpenAI API).
  • 🌍 Auto-Translation: Built-in support to translate AI responses into English, Russian, or any other language automatically.
  • 🛡️ Filter Bypass: Optional disable_safety_settings to ignore safety filters and overlays.

📦 Installation

pip install perchancy

🚀 Quick Start

Text Generation with Streaming

import perchancy

# Initialize once - the browser will close itself when the script ends
client = perchancy.Client(headless=True)

response = client.chat.completions.create(
    model="ai-text-generator",
    messages=[{"role": "user", "content": "Tell me a short story about a golden dragon."}],
    stream=True,
    translation="auto" # Translates the response back to your prompt's language
)

for chunk in response:
    content = chunk["choices"][0]["delta"].get("content", "")
    if content:
        print(content, end="", flush=True)

Image Generation

import perchancy
import base64

client = perchancy.Client(headless=True, disable_safety_settings=True)

response = client.images.generate(
    model="ai-text-to-image-generator",
    prompt="cyberpunk city, neon lights, 8k resolution",
    num_images=2
)

if "error" not in response:
    for i, img in enumerate(response["data"]):
        with open(f"output_{i}.png", "wb") as f:
            f.write(base64.b64decode(img["url"]))

📖 Documentation

1. Finding "Models" (Endpoints)

Perchance doesn't have a fixed list of models. A "model" is simply the name of the specific generator in the URL.

  • Visit perchance.org.
  • Find a generator (e.g., ai-text-generator).
  • The word after the slash in the URL perchance.org/NAME is your model parameter.

2. Client Configuration

  • headless (bool): Run the browser in the background (default: True).
  • debug (bool): Enable detailed status logs in the console.
  • disable_safety_settings (bool): If True, the script removes safety overlays to extract "blocked" content.
  • Lifecycle: The library uses atexit to ensure all browser processes are killed cleanly when your Python process exits.

3. chat.completions.create Parameters

  • model (str): The name of the Perchance generator.
  • messages (list): Message objects (supports role and content).
  • stream (bool): Enable real-time streaming output.
  • translation (str): Target language (e.g., "russian", "ru", "auto").

4. images.generate Parameters

  • model (str): The name of the image generator.
  • prompt (str): The visual description.
  • num_images (int): Number of images. The library automatically selects the maximum allowed by that specific generator's UI if you request more than its limit.

🔐 Authentication (Optional)

The library includes an auth utility for saving cookies from your Perchance account.

Note:

  • Authentication is NOT required. The library works perfectly as a guest.
  • This is intended for advanced users to bypass guest limits.
  • Disclaimer: The auth module's functionality has not been verified as guest mode proved sufficient during development.
from perchancy.auth import login_and_save_cookies
login_and_save_cookies()

⚠️ Disclaimer

This project is an unofficial wrapper and is not affiliated with, endorsed by, or sponsored by Perchance. The author is not responsible for any misuse, IP bans, or account suspensions. Use this tool strictly for educational and research purposes.

📝 License

Distributed under the MIT License. See LICENSE for more information.


Created with ❤️ by BlackCrowy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

perchancy-0.0.3.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

perchancy-0.0.3-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file perchancy-0.0.3.tar.gz.

File metadata

  • Download URL: perchancy-0.0.3.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for perchancy-0.0.3.tar.gz
Algorithm Hash digest
SHA256 7c0d144d18f1d33e99c6051ed577a5a2560ddf5d2e24e299202736c671c87032
MD5 0f2c557cde77977b3331c9a21a46f670
BLAKE2b-256 5b8679601d8c4bb894e5749fd806e6bfe4bba650421c1202e456f35fc1bd2ff1

See more details on using hashes here.

File details

Details for the file perchancy-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: perchancy-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for perchancy-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 86b98e8dbe149a220b0232f09f980cfed1fe9ffa8a25e34985eaacfbf551d5c4
MD5 f59406c766f28a1dcc6e91d5adfce3e6
BLAKE2b-256 aa1707b92b91703c4526f46ae29ee3c16bee770942d9d70f37ccfef1d690c8a9

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