Skip to main content

nebulous.py

PyPI - Version PyPI - Python Version


Table of Contents

Installation

  1. Install git
  2. Install java-random: python -m pip install --user git+https://github.com/MostAwesomeDude/java-random
    • NOTE: This is a required step, as the java-random package on pypi is outdated and broken.
  3. Install nebulous.py: python -m pip install --user nebulous.py

Usage

Utilizing the client

import asyncio
import logging

from dotenv import dotenv_values

from nebulous.game.account import ServerRegions
from nebulous.game.models.client import Client, ClientCallbacks
from nebulous.game.models.gameobjects import GamePlayer
from nebulous.game.packets import ConnectRequest3, ConnectResult2, Disconnect, GameData, KeepAlive

secrets = dotenv_values("../.env.secrets")
logger = logging.getLogger("Client Tests")
logger.setLevel(logging.INFO)


class TestCallbacks(ClientCallbacks):
    async def on_connect(self, client: Client, packet: ConnectRequest3) -> ConnectRequest3:
        print("Connected to server")
        return packet

    async def on_disconnect(self, client: Client, packet: Disconnect) -> Disconnect:
        print("Disconnected from server")
        return packet

    async def on_keep_alive(self, client: Client, packet: KeepAlive) -> KeepAlive:
        print("Sending keep alive packet")
        return packet

    async def on_connect_result(self, client: Client, packet: ConnectResult2) -> ConnectResult2:
        print(f"Received connection result: {packet.result}")
        return packet

    async def on_game_data(self, client: Client, packet: GameData) -> GameData:
        print(f"Received game data")
        return packet

    async def on_player_ready(self, client: Client, player: GamePlayer) -> GamePlayer:
        print(f"Player ready: {player.name}, index: {player.index}")

        await client.chat.send_game_message("Hello, world! :)")

        return player


async def test_client():
    client = Client(secrets.get("TICKET", ""), ServerRegions.US_EAST, callbacks=TestCallbacks())  # type: ignore

    await client.start()


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

Interacting with the API

Note: Upon signing in, the api client will perform a series of requests to fetch the player's data, among other things(e.g. sale info, purchase prices, etc.). This also includes an automatic account check-in, which grants 50 plasma each day.

From test_account.py:

def test_fetch_self():
    account = Account(secrets.get("TICKET", ""), ServerRegions.US_EAST)  # type: ignore
    player = account.player_obj

    if player is None:
        logger.error("Failed to fetch player object")

        return

    player_profile = player.get_profile()
    player_stats = player.get_stats()

    player_xp = player_stats.general_stats.xp

    logger.info(f"Player: {player_stats.account_name}")
    logger.info(f"Level: {xp2level(player_xp)}")
    logger.info(f"Current XP: {player_xp}")

    clan_member = player_stats.clan_member

    logger.info(f"Clan: {clan_member.clan.name}")
    logger.info(f"Role: {clan_member.clan_role}")

    logger.info(f"Account bio: {player_profile.bio}")

    # fetch friends
    logger.info("Fetching friends...")

    friends = player.get_friends()

    if len(friends) == 0:
        logger.info("No friends :(")

        return

    for friend in friends:
        friend_profile = friend.get_profile()
        friend_stats = friend.get_stats()
        friend_xp = friend_stats.general_stats.xp

        logger.info(f"Friend: {friend_stats.account_name}")
        logger.info(f"Level: {xp2level(friend_xp)}")
        logger.info(f"Current XP: {friend_xp}")
        logger.info(f"Account bio: {friend_profile.bio}")
        logger.info(f"BFF: {friend.bff}")
        logger.info(f"Last seen: {friend.last_played_utc}\n")

        logger.info("Cooldown for 1.5 seconds...")
        time.sleep(1.5)  # don't spam the API

Client objects also contain an instance to an Account object, which can be accessed via client.account.

Dumping Packets

You can also dump packets as json, as shown in sample_packet.json:

print(packet.as_json(indent=4))

License

nebulous.py is distributed under the terms of the MIT license.

Metadata

Release files for nebulous.py 1.5.1

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

Source distribution (sdist)

Source distribution for nebulous.py 1.5.1
File Size Uploaded
nebulous_py-1.5.1.tar.gz 38.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nebulous.py 1.5.1
File Interpreter ABI Platform
nebulous_py-1.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 77.8 kB

Release files / nebulous_py-1.5.1.tar.gz

Download URL nebulous_py-1.5.1.tar.gz
Size 38.1 kB
Tags Source
SHA-256 checksum
How to use checksums
654916c33872a962581a03b2a317d11b0706f6d7c81c73438507077c78aae4f7
BLAKE2b-256 checksum
How to use checksums
dac93f78ec8aa3f62858dead47788800ec77c198d02e9003b7b358b91db65b78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.25.2

Release files / nebulous_py-1.5.1-py3-none-any.whl

Download URL nebulous_py-1.5.1-py3-none-any.whl
Size 39.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc91560c89397c240c470c87bbef59518270270be9ef4c3118c6f306417d167b
BLAKE2b-256 checksum
How to use checksums
c859259d072c692626bdb9ce598c2d7e297efa0d60d2a01084bae9d563745b18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.25.2

Release history Release notifications | RSS feed

This release

1.5.1 This release

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.0.1

2 release files

1.0.0

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