Skip to main content

A simple curseforge api wrapper

Project description

curse-api


A simple async python Curseforge api wrapper using pydantic

Built to serve CF endpoints while providing methods and functions to assist in finding the right mod.


Some backstory

A while back when I was starting to learn python further then the basics I created a small tool to download Minecraft mods from a pack manifest. Soon after I wrote it the new API changes came and broke it. Now once more I want to return to that project idea and expand further. After first rewriting the project using chili it felt off, so returned to rewrite once more using pydantic for data validation and ease of access. This is mostly a pet project to learn further python.


Features

Main Dependency:

Native async library support:

  • Aiohttp - pip install curse-api[aiohttp]
  • Httpx - pip install curse-api[httpx]

Currently implemented:

  • Important endpoint support
  • Full CurseForge model
  • Mediocre error handling
  • Pluggable API factories
  • Serialization and deserialization of models
  • Python 3.7, 3.8 & 3.9 support
  • Async

To Do:

  • Fix to be usable with pydantic based ORM's
  • Address all TODO's
  • Test other games too
  • Add more
  • Write docs
  • Update and fix error handling
  • Shortcuts to import clients

CI/CD:

  • Type checking
  • Version testing
  • Tests

Examples

Quick start

Requires an api from CF to use the API. You can get one here. This example runs through most of the basics

from curse_api import CurseAPI
from curse_api.clients.httpx import HttpxFactory
import os
import asyncio


async def main():
    async with CurseAPI(os.environ["CF_API_KEY"], factory=HttpxFactory) as api:

        "Mods"
        a = await api.search_mods(searchFilter="JEI", slug="jei")
        # applies the search filters to the standard of CF docs

        mod = await api.get_mod(250398)  # returns a singular Mod
        mod_list = await api.get_mods([285109, 238222])  # returns a list of Mods

        "files"
        "See examples/download.py"
        # TODO finish file support
        files = await api.get_files([3940240])  # returns a list of Files matching their id
        mod_files = await api.get_mod_files(238222)  # returns all the Files of on a give Mod

        "Version details - large data"
        "See examples/modloader.py"
        mc = await api.minecraft_versions()  # returns all of minecraft version data
        ml = await api.modloader_versions()  # returns **ALL** modloader versions on curseforge

        mc_112 = await api.get_specific_minecraft_version("1.12.2")  # returns minecraft version related information
        forge = await api.get_specific_minecraft_modloader("forge-36.2.39")  # returns forge related version information


if __name__ == "__main__":
    asyncio.run(main())

Downloading to a file

This example opens a properly named file in the current working directory and writes to it.

from curse_api import CurseAPI
from curse_api.clients.httpx import HttpxFactory
import os
import asyncio


async def main():
    async with CurseAPI(os.environ["CF_API_KEY"], factory=HttpxFactory) as api:

        # fetch the latest file from project with slug 'jei'
        mod_l, page_data = await api.search_mods(slug="jei")
        latest = mod_l[0].latestFiles[0]

        with open(latest.fileName, "wb") as f:
            down = await api.download(latest.downloadUrl)  # type: ignore
            async for b in down:
                f.write(b)


if __name__ == "__main__":
    asyncio.run(main())

Sub project / extension ideas

  • Modloader download and installation
  • Minecraft Version type / parser
  • MC pack installation
  • DB cache extension
  • Manifest parsing

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

curse_api-3.1.2.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

curse_api-3.1.2-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file curse_api-3.1.2.tar.gz.

File metadata

  • Download URL: curse_api-3.1.2.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.8 Windows/10

File hashes

Hashes for curse_api-3.1.2.tar.gz
Algorithm Hash digest
SHA256 acc2b5b7002f5ceff35562b455ca9e00f334cf55bd27c56331cc4cf19be31596
MD5 b377272ccfb2db438ae4904eb3f81d27
BLAKE2b-256 b528b3977019b204f6923c2000be377cc864a1e99bc81306d94b306f019f056b

See more details on using hashes here.

File details

Details for the file curse_api-3.1.2-py3-none-any.whl.

File metadata

  • Download URL: curse_api-3.1.2-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.8 Windows/10

File hashes

Hashes for curse_api-3.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 457ae608b1f8a021ebafa0db42950f291e502a35cc77ea28afb19ad192a51ab9
MD5 7c1f627ebc61bab901cbf9f3b28d9073
BLAKE2b-256 93d16d33540fc405cbbef5f7b897aaba5eb408140d14495f666abb1eea2c53ab

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