Skip to main content

perchance-api

pypi python

Unofficial Python API for Perchance.

Installation

To install this module, run the following command:

pip install perchance-api

Examples

Text generation

import asyncio
from perchance import TextGenerator

async def main():
    async with TextGenerator() as gen:
        prompt = "How far is the Moon?"

        async for chunk in gen.stream(prompt):
            print(chunk, end='')

asyncio.run(main())

The text generator drives the official Perchance embed in a browser so its anti-bot verification can complete. A browser window opens by default; pass TextGenerator(headless=True) to hide it (verification may then fail).

Image generation

import asyncio
from PIL import Image
from perchance import ImageGenerator

async def main():
    async with ImageGenerator() as gen:
        prompt = "Fantasy landscape"

        result = await gen.image(prompt, shape='landscape')
        binary = await result.download()
        image = Image.open(binary)
        image.show()

asyncio.run(main())

Credits

Originally created by eeemoonYurii as the perchance package. This fork (perchance-api) rewrites the API calls and adds the describe/streaming updates.

Metadata

Release files for perchance-api 0.2.1

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

Source distribution (sdist)

Source distribution for perchance-api 0.2.1
File Size Uploaded
perchance_api-0.2.1.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for perchance-api 0.2.1
File Interpreter ABI Platform
perchance_api-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.0 kB

Release files / perchance_api-0.2.1.tar.gz

Download URL perchance_api-0.2.1.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
695cd37b628b7f4d127b1ffeedf9af7c9135577e60a469a05ce04a8a9cbc6f61
BLAKE2b-256 checksum
How to use checksums
21d63f0843ac79703dff8988f243197fdfffebcf446458cef15720acfac54438
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / perchance_api-0.2.1-py3-none-any.whl

Download URL perchance_api-0.2.1-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a328565bc785b039c34800f261e9a7409f9c9d1d14641afd5e32c76d67dc6fe5
BLAKE2b-256 checksum
How to use checksums
f4ac507f84fb29651d6c194d7fd8554f9d4b7619d65d457aa5d1c14d9ad43714
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

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