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_akipy 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:
-
Create a feature branch
git checkout -b feature/your-feature-name
-
Make your changes
- Edit the code as needed
- Add/update tests in the
tests/directory - Ensure your code follows the project's style
-
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
-
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 pytestto verify - Push again
Project Structure
akipy/
├── akipy/ # Main package source code
│ ├── __init__.py
│ ├── akinator.py # Synchronous Akinator class
│ ├── async_akipy.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
Release history Release notifications | RSS feed
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 akipy-0.2.4.tar.gz.
File metadata
- Download URL: akipy-0.2.4.tar.gz
- Upload date:
- Size: 19.5 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29b16f9a6c5812018b1bd095f365a0e76504d6fef84cbe5f6179004335f78434
|
|
| MD5 |
6fe1753d95dfc4afeffe578c4ad58785
|
|
| BLAKE2b-256 |
74a50a3eac0976f858ce8643d6933960b6fbce02d9d6fc38e3e01058e333b2d5
|
File details
Details for the file akipy-0.2.4-py3-none-any.whl.
File metadata
- Download URL: akipy-0.2.4-py3-none-any.whl
- Upload date:
- Size: 14.8 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67e810e829c56fd92a38cde4acb1d9356c828b81d009e589ab7ac2ba03d0333c
|
|
| MD5 |
75e1ef9679d23792ef3270c038f3c0b2
|
|
| BLAKE2b-256 |
16958b6789f0e41d12b7d87e62b4d643c868df8e24eaa15a70a0fdecad7d133a
|