Quick Start#
In this section, we go over everything you need to know to start building applications using Corkus.py, the Python Wynncraft API Wrapper. It’s fun and easy. Let’s get started.
Prerequisites#
- Python Knowledge:
You need to know at least a little Python to use Corkus. It’s a asynchronous wrapper so you need to have basic knowledge how asyncio work and how to use
async
andawait
syntax. Corkus supports Python 3.8+.- Wynncraft Knowledge:
A basic understanding of how Wynncraft works is a must. In the event you are not already familiar with Wynncraft start at Wynncraft Help.
With these prerequisites satisfied, you are ready to learn how to do some of the most common tasks with Corkus.
Example usage#
This guide gives a brief introduction to the Corkus.py. It assumes you have the library installed. If you don’t, check the Installing Corkus.py.
This is a simple application for fetching player statistics:
import asyncio
from corkus import Corkus
async def main():
async with Corkus() as corkus:
player = await corkus.player.get("MrBartusekXD")
print(f"username: {player.username}")
character = player.best_character
print(f"best character: {character.display_name} ({character.combat.level}lv)")
if player.guild:
guild = await player.guild.fetch()
print(f"guild: {player.guild.name} {guild.level}lv ({len(guild.members)} members)")
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
This will print something like that:
username: MrBartusekXD
best character: Mage (102lv)
guild: The Farplane 63lv (60 members)
If you are not familiar with asyncio that snippet may seam a bit scarry. Don’t worry!
Thats a minimal requirement to run asynchronous Python code! All code inside main()
is
now asynchronous.
You probably see that this snippet also uses a Context Manager in order to simplify the code. You don’t need to use it, this code works exactly the same:
import asyncio
from corkus import Corkus
async def main():
corkus = Corkus()
await corkus.start()
player = await corkus.player.get("MrBartusekXD")
print(f"username: {player.username}")
character = player.best_character
print(f"best character: {character.display_name} ({character.combat.level}lv)")
if player.guild:
guild = await player.guild.fetch()
print(f"guild: {player.guild.name} {guild.level}lv ({len(guild.members)} members)")
await corkus.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
In this example you need to call Corkus.start()
and
Corkus.close()
. These are two lifecycle function that needs
to always be called at the start and end of your application.
Note
You should use Context Manager when dealing with smaller scripts and directly
create and close Corkus
instance when dealing with bots or other
bigger applications.
Next steps#
Next up, you can continue the guide and learn more about The Corkus Client
.
Or you can check out the following resources: