Skip to main content

A Python library wrapper for Akinator

Project description

akipy

Python library wrapper for akinator.com You can use this in your python projects to integrate Akinator functionalities.

Wrapper is still in development. Some things may or may not work. If you experience issues, feel free to raise an issue here.

Some things that could be improved:

  • Exception Handling
  • Docs
  • Better error Handling
  • Custom Exceptions

If you want to help, the above is the main priority for now.

Why ?

I already used to use a wrapper library for Akinator (akinator.py) before. But suddenly it seems to be not working. I debugged and made sure the problem is because of API changes from Akinator themselves. There were so many changes making me think I would have to change a lot of things. So instead of doing that, I just made it from scratch. Obviously I took a lot of inspiration from the old Python wrapper I was using thus the code structure would look very similar. In fact, I'm trying to replicate the same interface that was present in the old wrapper. Because I don't want to make changes to any piece of software that may depend on this library (which isn't working now).

I hope there isn't any interface breaking changes here. If there are any, please contact me either through Telegram or raise an issue here on GitHub or if you want to help, raise a Pull Request.

Installation

pip install akipy

Usage

There is both synchronous and asynchronous variants of akipy available.

Synchronous: from akipy import Akinator

Asynchronous: from akipy.async_akinator import Akinator

I'll provide a sample usage for synchronous usage of Akinator. All the examples are also in the project's examples folder. So please check them out as well.

import akipy

aki = akipy.Akinator()
aki.start_game()

while not aki.win:
    ans = input(str(aki) + "\n\t")
    if ans == "b":
        try:
            aki.back()
        except akipy.CantGoBackAnyFurther:
            pass
    else:
        try:
            aki.answer(ans)
        except akipy.InvalidChoiceError:
            pass

print(aki)
print(aki.name_proposition)
print(aki.description_proposition)
print(aki.pseudo)
print(aki.photo)

Developer Setup

First Time Setup

If you're a developer who just cloned this repository, follow these steps to set up your development environment:

1. Install uv (if not already installed)

# On macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# On Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

2. Install dependencies

# Install all dependencies including dev dependencies
uv sync

This will:

  • Create a virtual environment
  • Install all production dependencies from pyproject.toml
  • Install all development dependencies (pytest, ruff, mypy, pre-commit, etc.)

3. Install pre-commit hooks

# Install git hooks for automatic code quality checks
uv run pre-commit install
uv run pre-commit install --hook-type pre-push

4. Verify setup

# Run tests to ensure everything is working
uv run pytest

# Check code quality
uv run ruff check .

# Run type checking
uv run mypy akipy

Development Workflow

Making Changes

When you're working on changes to the codebase, follow these steps:

  1. Create a feature branch

    git checkout -b feature/your-feature-name
    
  2. Make your changes

    • Edit the code as needed
    • Add/update tests in the tests/ directory
    • Ensure your code follows the project's style
  3. Test your changes

    # Run all tests
    uv run pytest
    
    # Run tests with coverage
    uv run pytest --cov=akipy --cov-report=html
    
    # Run specific test file
    uv run pytest tests/test_akinator.py
    
  4. Check code quality (optional - pre-commit will do this automatically)

    # Run linter
    uv run ruff check .
    
    # Auto-fix linting issues
    uv run ruff check --fix .
    
    # Format code
    uv run ruff format .
    
    # Type checking
    uv run mypy akipy
    

Committing Changes

When you commit changes, pre-commit hooks will automatically run:

git add .
git commit -m "Your commit message"

The pre-commit hooks will automatically:

  • Remove trailing whitespace
  • Fix end-of-file issues
  • Validate YAML/TOML files
  • Check for debug statements
  • Run ruff linter (with auto-fix)
  • Format code with ruff

If any hook fails and can't auto-fix:

  • Fix the issues reported
  • Stage the fixed files with git add
  • Try committing again

Pushing Changes

When you push to GitHub, additional checks run:

git push origin feature/your-feature-name

The pre-push hook will:

  • Run the entire test suite
  • Only allow push if all tests pass

If tests fail:

  • Review the test failures
  • Fix the issues
  • Re-run uv run pytest to verify
  • Push again

Project Structure

akipy/
├── akipy/                  # Main package source code
│   ├── __init__.py
│   ├── akinator.py         # Synchronous Akinator class
│   ├── async_akinator.py   # Asynchronous Akinator class
│   ├── dicts.py            # Constants and mappings
│   ├── exceptions.py       # Custom exceptions
│   └── utils.py            # Utility functions
├── tests/                  # Test suite
│   ├── conftest.py         # Pytest fixtures
│   ├── test_akinator.py
│   ├── test_async_akipy.py
│   ├── test_utils.py
│   ├── test_exceptions.py
│   └── test_dicts.py
├── examples/               # Example usage scripts
├── .github/workflows/      # CI/CD configuration
├── pyproject.toml          # Project metadata and dependencies
└── README.md               # This file

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

akipy-1.2.4.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

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

akipy-1.2.4-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file akipy-1.2.4.tar.gz.

File metadata

  • Download URL: akipy-1.2.4.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.26.1 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for akipy-1.2.4.tar.gz
Algorithm Hash digest
SHA256 f77c274b53d7f56acbfd9ec6c3bd1c75d5f964dc0c1aa6cf651268d7c45418da
MD5 216bb39728315efa142c791a26d093c5
BLAKE2b-256 9b1496ef1f20689e9a7c01510f3dc614ccdb4f7267755389b9831d9524c9963c

See more details on using hashes here.

File details

Details for the file akipy-1.2.4-py3-none-any.whl.

File metadata

  • Download URL: akipy-1.2.4-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.26.1 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for akipy-1.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 becb575e461f6decabf8d1a691204f767547bfe5fa4d46f178a730d7ea2c5680
MD5 59262684836983e41441a1bf44dbb497
BLAKE2b-256 9bfa7e3f936ce1b3552b82022142dd177770b27ec549ccfbef65dc356187d767

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