Skip to main content

osu!-tools for python

GitHub license GitHub stars PyPI - Downloads PyPI - Python Version

Description

osu!-tools is a Python framework for interacting with various osu! APIs and file-types.

  • Make requests to the osu! v1 API to view user, score, map or match information.
  • Uses oppai-ng to get pp information for any given score
  • Read osu!.db, scores.db and collection.db into a Python object, and export it to json

Installation

pip install osu-tools

Basic Examples

API v1

>> import osutools


# Authenticate a client using an osu! API token
>> osu = osutools.OsuClient("token")

Get User

>> me = osu.fetch_user(username="flubb 4")
>> print(f"{me} | {me.pp}pp | #{me.rank} Global")

flubb 4 | 7507.3pp | #8765 Global

Get best 5 scores + show information

>> best = me.fetch_best()[:5]


>> for score in best:
..  beatmap = score.fetch_map()
..  print(f"{score.pp}pp | {score.score} | {beatmap} | {score.mods}")

431.448pp | 1554216 | WONDERFUL WONDER (TV Size) [Simple Heart] mapped by Kuki1537 | DT
399.029pp | 44559304 | Flames Within These Black Feathers [Kowari's Extreme] mapped by Seni | NM
387.581pp | 2219153 | Angel With A Shotgun (Sped Up Ver.) [Sacred Bullet] mapped by Sotarks | HDDT
379.095pp | 377539970 | Save Me [Tragedy] mapped by Drummer | NM
371.206pp | 6547546 | One by One [Sotarks' Rampage] mapped by Elinor | HR

Get information about a specific beatmap

>> beatmap = osu.fetch_map(map_id=2788620)
>> print(f"{beatmap.song_title} [{beatmap.difficulty_name}] | {beatmap.artist} | {beatmap.creator_name}")

Sofia [Nyantiaz's Hard] | Clairo | Qiyana

Get leaderboards and submitted scores for the beatmap

>> leaderboard = beatmap.fetch_scores()
>> my_score = beatmap.fetch_scores(username="flubb 4")[0]
>> print(f"Best Score: {leaderboard[0]}\nMy Score: {my_score}")

Best Score: HDDTHR score on beatmap 2788620 by Mikayla
My Score: HDDT score on beatmap 2788620 by flubb 4

Databases

Set osu directory, and automatically read the databases.

>> osu.set_osu_folder("path/to/folder")

# Load the pp values for all local plays (enables faster processing of functions that use the pp value like get_best_scores_before()
>> osu.scores_db.load_pp()

Get the average length of all of your maps

>> avg_map_length = sum([beatmap.length for beatmap in osu.osu_db.map_list()]) / float(len(osu.osu_db.map_list()))
>> print(timedelta(milliseconds=avg_map_length))

0:02:35.320889

Get your top 10 ranked scores before 2020

>> names = ["flubb 4", "ito", "biglizard"] # I've changed my username a lot
>> scores = osu.scores_db.get_best_scores_before(datetime.datetime(year=2020, month=1, day=1, tzinfo=timezone.utc), names=, ranked_only=True)
>> for x, score in enumerate(scores[:5]):
..    print(f"{x+1}: {score.pp} play on {score.map.song_title} [{score.map.difficulty_name}] with {score.mods}")

1: 312.0760803222656 play on Snow Halation (feat. BeasttrollMC) [Reform's Extra] with DT
2: 311.7738952636719 play on Harumachi Clover (Swing Arrangement) [Dictate Edit] [Expert] with DT
3: 277.50250244140625 play on Yuki no Hana [Sharlo's Insane] with DT
4: 272.4308776855469 play on Kira Kira Days [Shiawase!!] with NM
5: 269.6291198730469 play on Natsukoi Hanabi [Insane] with DT

Export your databases to JSON

>> osu.osu_db.export() # saves to osu_db.json by default
>> osu.scores_db.export("~/osu/scores.json") # can give custom path

PP Calculation

Get pp for an SS on a given map with HDHR

>> from osutools.utils import Mods
>> from osutools.oppai import Oppai

>> beatmap_path = "96neko - Uso no Hibana (Enjoy) [Hanabi].osu"
>> mod_combo = Mods.HR & Mods.HD
>> pp = Oppai.calculate_pp(beatmap_path, mods=mod_combo.value)
>> print(pp)

219.83245849609375

Get pp for an online map

>> beatmap = osu.fetch_map(1255495)
>> pp = Oppai.calculate_pp_from_url(beatmap.download_url, mods=mod_combo.value, accuracy=99.5)
>> print(pp)

311.27484130859375

Todo

  • api v2
  • better errors
  • probably some kind of internal ratelimit prevention?
  • tests 👀
  • discord integration utilities?
  • download beatmap

Acknowledgements

Metadata

Release files for osu-tools 0.2.13

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

Source distribution (sdist)

Source distribution for osu-tools 0.2.13
File Size Uploaded
osu!tools-0.2.13.tar.gz 261.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for osu-tools 0.2.13
File Interpreter ABI Platform
osu_tools-0.2.13-py3-none-any.whl Python 3 none any Details

Total release size: 526.3 kB

Release files / osu!tools-0.2.13.tar.gz

Download URL osu!tools-0.2.13.tar.gz
Size 261.4 kB
Tags Source
SHA-256 checksum
How to use checksums
417078f0a89beeddfb65862c3a29a0480665af3241b2613b78b6f78b664be056
BLAKE2b-256 checksum
How to use checksums
c317e5f2738e3609636415d8f6766b813bb7086735aefd658afcb87309dec12a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

Release files / osu_tools-0.2.13-py3-none-any.whl

Download URL osu_tools-0.2.13-py3-none-any.whl
Size 264.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da9eee7dad2ad28b43e8735d8aabdcf07f30559566a15d91cc86be1c1b6a278a
BLAKE2b-256 checksum
How to use checksums
8558a8224b973139ee6ff85e0e5c21e3db2e25f93f305522cf438d298ee636d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.2.13 This release

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

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