Skip to main content

HowLongToBeat Python API

Python Test Released Published Version CodeQL

codecov Bugs

A simple Python API to read data from howlongtobeat.com.

It is inspired by ckatzorke - howlongtobeat JS API.

Content

Usage

Installation

Installing the package downloading the last release

pip install howlongtobeatpy

Installing the package from the source code

Download the repo, enter the folder with 'setup.py' and run the command

pip install .

Usage in code

Start including it in your file

from howlongtobeatpy import HowLongToBeat

Now call search()

The API main functions are:

results = HowLongToBeat().search("Awesome Game")

or, if you prefer using async:

results = await HowLongToBeat().async_search("Awesome Game")

The return of that function is a list of possible games, or None in case you passed an invalid "game name" as parameter or if there was an error in the request.

If the list is not None you should choose the best entry checking the Similarity value with the original name, example:

results_list = await HowLongToBeat().async_search("Awesome Game")
if results_list is not None and len(results_list) > 0:
    best_element = max(results_list, key=lambda element: element.similarity)

Once done, "best_element" will contain the best game found in the research. Every entry in the list (if not None in case of errors) is an object of type: HowLongToBeatEntry.

Alternative search (by ID)

If you prefer, you can get a game by ID, this can be useful if you already have the game's howlongtobeat-id (the ID is the number in the URL, for example in https://howlongtobeat.com/game/7231 the ID is 7231).

To avoid a new parser, the search by ID use a first request to get the game title, and then use the standard search with that title, filtering the results and returning the unique game with that ID.

Remember that it could be a bit slower, but you avoid searching the game in the array by similarity.

Here's the example:

result = HowLongToBeat().search_from_id(123456)

or, if you prefer using async:

result = await HowLongToBeat().async_search_from_id(123456)

This call will return an unique HowLongToBeatEntry or None in case of errors.

DLC search

An enum has been added to have a filter in the search:

SearchModifiers.NONE # default
SearchModifiers.ISOLATE_DLC
SearchModifiers.HIDE_DLC

This optional parameter allow you to specify in the search if you want the default search (with DLCs), to HIDE DLCs and only show games, or to ISOLATE DLCs (show only DLCs).

Results auto-filters

To ignore games with a very different name, the standard search automatically filter results with a game name that has a similarity with the given name > than 0.4, not adding the others to the result list. If you want all the results, or you want to change this value, you can put a parameter in the constructor:

results = HowLongToBeat(0.0).search("Awesome Game")

putting 0.0 (or just 0) will return all the found games, otherwise you can write another (float) number between 0...1 to set a new filter, such as 0.7.

Also remember that by default the similarity check is case-sensitive between the name given and the name found, if you want to ignore the case you can use:

results = HowLongToBeat(0.0).search("Awesome Game", similarity_case_sensitive=False)

Remember that, when searching by ID, the similarity value and the case-sensitive bool are ignored.

An auto-filter for game-types has been added, it is not active by default (False) but can be used as:

results = HowLongToBeat(input_auto_filter_times = True).search("The Witcher 3")

That auto-filter "nullify" values based on the game-type, if it is a singleplayer game then the coop/multiplayer values are overridden to Null; on the other side if it is a Multiplayer game the singleplayer values such as "main story" could be overridden to Null if that game doesn't have a story. Use with caution, it is probably better if you decide what fits best for you.

Reading an entry

An entry is made of few values, you can check them in the Entry class file. It also include the full JSON of values (already converted to Python dict) received from HLTB.

Issues, Questions & Discussions

If you found a bug report it as soon as you can creating an issue, the code may not be perfect.

If you need any new feature, or want to discuss the current implementation/features, consider opening a discussion or even propose a change with a Pull Request.

Authors

  • ScrappyCocco - Thank you for using my API

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

howlongtobeatpy-1.0.23.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

howlongtobeatpy-1.0.23-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file howlongtobeatpy-1.0.23.tar.gz.

File metadata

  • Download URL: howlongtobeatpy-1.0.23.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for howlongtobeatpy-1.0.23.tar.gz
Algorithm Hash digest
SHA256 1445bcd72b90c8172e7858ffe46ff357bc4d4b360a74299701dd04418a2296eb
MD5 00520e4dcb8e38254083f7589460fa0c
BLAKE2b-256 b7b11f70430e1afd9b4d7e1441e4246e030a06551a68c7cbe67e76c712756c67

See more details on using hashes here.

Provenance

The following attestation bundles were made for howlongtobeatpy-1.0.23.tar.gz:

Publisher: manual-publish-version.yml on ScrappyCocco/HowLongToBeat-PythonAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file howlongtobeatpy-1.0.23-py3-none-any.whl.

File metadata

File hashes

Hashes for howlongtobeatpy-1.0.23-py3-none-any.whl
Algorithm Hash digest
SHA256 9faff74f6a864f96d6a72b2871ce91845cfee06533ed867441f2156e535f920c
MD5 762ef9dfc5d7d44561323d80a77d36ff
BLAKE2b-256 53794627a4f61942bea808a7dcc7de9392a511cc9c7ea3ab62cc444ff68c8a2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for howlongtobeatpy-1.0.23-py3-none-any.whl:

Publisher: manual-publish-version.yml on ScrappyCocco/HowLongToBeat-PythonAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.23 This release

2 files

1.0.22

2 files

1.0.21

2 files

1.0.20

2 files

1.0.19

2 files

1.0.18

2 files

1.0.17

2 files

1.0.16

2 files

1.0.15

2 files

1.0.14

2 files

1.0.13

2 files

1.0.12

2 files

1.0.11

2 files

1.0.10

2 files

1.0.9

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

1 file

1.0.5

1 file

1.0.3

1 file

1.0.2

1 file

1.0.1

1 file

1.0.0

1 file

0.1.22

1 file

0.1.21

1 file

0.1.20

1 file

0.1.19

1 file

0.1.18

1 file

0.1.17

1 file

0.1.16

1 file

0.1.15

1 file

0.1.14

1 file

0.1.13

1 file

0.1.12

1 file

0.1.11

1 file

0.1.10

1 file

0.1.9

1 file

0.1.8

1 file

0.1.7

1 file

0.1.6

1 file

0.1.5

2 files

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

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