G4F-like OpenAI compatible wrapper for Perchance AI generators
Project description
Perchancy 🚀
Perchancy is a high-speed, OpenAI-compatible Python wrapper for Perchance AI generators. Generate text and images programmatically with zero manual browser management.
✨ Key Features
- ⚡ Blazing Fast: Optimized DOM scanning for instant extraction.
- 🤖 Auto Lifecycle: Browser closes automatically via
atexit. - 🔄 Auto-Sync Chrome: Automatically downloads matching Chrome for Testing.
- 📽️ Streaming Support: Real-time text generation.
- 🌍 Auto-Translation: Built-in Google Translate support for prompt/response.
- 🛡️ Per-Request Safety: Toggle
disable_safety_settingsindividually for each call.
📦 Installation
pip install perchancy
🚀 Quick Start
Text Generation (Non-Streaming)
import perchancy
client = perchancy.Client(headless=True)
# Generate full text synchronously
response = client.chat.completions.create(
model="ai-text-generator",
messages=[{"role": "user", "content": "Write a 3-sentence horror story."}],
stream=False, # Wait for the complete response
translation="auto", # Automatically translate back to your prompt's language
disable_safety_settings=True # Bypass UI content filters
)
# Access content using standard OpenAI dictionary keys
content = response["choices"][0]["message"]["content"]
print(f"ID: {response['id']}")
print(f"Model: {response['model']}")
print("-" * 20)
print(content)
Text Generation (Streaming)
import perchancy
client = perchancy.Client(headless=True)
response = client.chat.completions.create(
model="ai-text-generator",
messages=[{"role": "user", "content": "Write a short sci-fi intro."}],
stream=True,
translation="auto",
disable_safety_settings=True
)
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)
response = client.images.generate(
model="ai-text-to-image-generator",
prompt="cyberpunk city, neon lights",
num_images=2,
disable_safety_settings=True
)
for i, img in enumerate(response.get("data", [])):
with open(f"out_{i}.png", "wb") as f:
f.write(base64.b64decode(img["url"]))
🛠 Advanced: Extra Params & Mappings
Perchance generators often have sliders, dropdowns, or input fields (like seed, guidanceScale, or negativePrompt). You can control these using extra_params.
1. How to find parameters?
- Open the generator in your browser.
- Right-click any UI element (slider, input, etc.) and click Inspect.
- Note the
id,name, ordata-name(e.g.,id="seedInput").
2. Usage Example
client.images.generate(
model="ai-text-to-image-generator",
prompt="A magical forest",
# Set values directly using element IDs
extra_params={
"guidanceScale": "7.5",
"negativePrompt": "low quality, blurry"
},
# Use mappings to create aliases for complex selectors
param_mappings={
"quality": ["#resolution-dropdown-id", "[data-name='qualitySelect']"]
},
quality="high" # Now 'quality' works as a direct argument via **kwargs
)
🔐 Authentication (Optional)
from perchancy.auth import login_and_save_cookies
login_and_save_cookies()
Note:
- Authentication is NOT required. The library works perfectly as a guest.
- This is intended for advanced users to bypass guest limits.
- Disclaimer: The
authmodule's functionality has not been verified as guest mode proved sufficient during development.
📖 Documentation Summary
- Finding Models: The "model" is the slug in the URL:
perchance.org/NAME. - Client Configuration:
headless(bool): Run in background (default:True).debug(bool): Enable detailed status logs.
- Custom Selectors: You can manually override
input_selectors,button_selectors, oroutput_selectorsin thecreate/generatemethods if a specific generator has a non-standard layout.
⚠️ Disclaimer
Unofficial wrapper. Use for educational purposes only. Author is not responsible for any misuse or bans.
📝 License
MIT License.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file perchancy-0.0.4.tar.gz.
File metadata
- Download URL: perchancy-0.0.4.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51684e1c0ebb7eb453e5aa418085d38e3a5f743130f53827402005a857f5ea64
|
|
| MD5 |
c05e43e50450c62b3cb07e0b01fe943c
|
|
| BLAKE2b-256 |
9bc19e1773e1f1c7b7bda15760cc42420f373861a7e0d91cfa27b2052231ed2c
|
File details
Details for the file perchancy-0.0.4-py3-none-any.whl.
File metadata
- Download URL: perchancy-0.0.4-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84909b31ee918a3359170a2b8c8ce6a4821d49de57dcdad78406b33cd0ec25f9
|
|
| MD5 |
5d6c42ded8568fb6f807105cbe9f8a5e
|
|
| BLAKE2b-256 |
f2268cdc4fe16c0b91a25a9d6f9106d49ea3d63116fa68f6dd1c07329f5e0c82
|