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.2.tar.gz (16.3 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.2-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: perchancy-0.0.2.tar.gz
  • Upload date:
  • Size: 16.3 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.2.tar.gz
Algorithm Hash digest
SHA256 ecdb7c770e8921716010ccad0ac7cdf5f3ae37d5768911521f298f3a7a8c2328
MD5 c51ea4871026a0bc6154e73199fd4678
BLAKE2b-256 72a654408119bdc0ddfc7ebb9965335312cd024daa8ca009dba5fcae30f5d7be

See more details on using hashes here.

File details

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

File metadata

  • Download URL: perchancy-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 856f456bd1b92a9b51ff63d1ab41886879f8683e3d11ce035387cd9c800569cf
MD5 86a527445bb8977c6ad20c5d60a3da02
BLAKE2b-256 c39ba8b17c400290bc1f97ab12d8ead3463081e3a6d461e1b790e01192628ca3

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