Skip to main content

VNG-API

Static Badge PyPI Version Python version GitHub License

A async API client for the game "Von Neumann Game" by Gnieark

This library implements both the normal user API as well as the Others NPC API.

Project on PyPi: https://pypi.org/project/vng-api/

Basic Principles

Statistics

APIClient.stats keeps a up to date list of statistics as reported by the API, this includes the current remaining calls in the rate limit bucket as well as the total bucket size.

APIResponse

Almost all requests return a vng_api.base.APIResponse object. You can check if your request suceeded by checking the success value. The data that was returned is put into data. You can also use var unpacking on APIResponse to get both the normal APIResponse object and the contents of data at the same time.

The general HTTP response code can be acessed via status.

Example:

ret, version = await client.version()
# raise exception if the api call failed
ret.may_raise()
print(ret.suceess)
# -> True
print(version)
# -> 140
# var unpacking still leaves the data in the original object untouched and can be acessed as normal:
print(ret.data)
# -> 140
print(ret.status)
# -> 200

In case of a unsucessfull API call, you can use error_code and error_message to get the reason.
Note that Error 500, 503 and similar will leave those fields empty.

You may use APIResponse.may_rise() to raise a descriptive exception whenever a API call failed.

APIBatchResult

In the case of batched requests (as used by APIClient.probe.manny.tasks()), it will return a vng_api.base.APIBatchResult object. This behaves similar to APIResponse in that the overall success of the batch is checkable via success.

The individual APIResponse objects of each API call in the batch are stored in responses.

Example use

Following are some complete example usages for the library.

Batch crafting

Start crafting Steel Bars with all free mannies on Probe with ID 420

from vng_api.client import APIClient
import asyncio

async def main():
    client = APIClient('my_token')
    # get all mannies of the probe with ID 420
    ret, mannies = await client.probe.manny.get_all(420)
    # raise exception if api call failed
    ret.may_rise()
    # create context manager for mannie tasks on probe 420
    tasks = client.probe.manny.tasks(420)
    async with tasks:
        # queue the crafting task for each manny
        for manny in mannies.values():
            if manny.currentTask is None and manny.location.type == 'probe':
                await tasks.craft(manny.id, 'steel_bar')
    # check if the API calls of the task batching where successfull
    if not tasks.results.success:
        # get the batches that failed and compile error message
        failed = filter(lambda inp: not inp.success, tasks.results.responses)
        raise Exception(f'Failed to tasks mannies:\n{'\n'.join([f'- {f.error_code}: {f.error_message}' for f in failed])}')

asyncio.run(main())

Sector searching

Will search the current sector of probe 420 for any object with minable deuterium

from vng_api.client import APIClient
from vng_api.helper import get_manny_minable
import asyncio

async def main():
    client = APIClient('my_token')
    ret, sector_response = await client.probe.sector.get(420)
    ret.may_rise()
    found = False
    # use helper function to extract minable objects from sector observation
    minable_objects = get_manny_minable(sector_response.sector)
    # look through objects to search for the ones with deuterium
    for mo in minable_objects:
        if mo.resourceAmounts is not None:
            if mo.ResourceAmounts.deuterium > 0:
                print(f'object {mo.id} of type {mo.type} has {mo.resourceAmounts.deuterium:.2f} deuterium!')
                found = True
    if not found:
        print('no deuterium in this system :(')
    
asyncio.run(main())

Others NPCs

This will start a resource harvest on the first available planet with all available auxiliaries.
Note that for simplicity this example will assume that all auxiliaries are free and that you already know the ID of your fleet.

from vng_api.client import APIClient
from vng_api.types.others import OthersShip
from vng_api.helper import get_harvestable
import asyncio
from pprint import pprint

async def main():
    client = APIClient('my_token')
    # get fleet ships
    ret, fleet_info = await client.others.fleet.get('my_fleet_id')
    ret.may_rise()
    # find mothership in list
    mothership: OthersShip = list(filter(lambda f: f.type == 'mothership', fleet_info.ships))[0]
    # ensure that mothership is in sector
    assert mothership.location.state == 'in_sector'
    # get first available harvestable planet
    ret = await client.others.sector.get(mothership.id, mothership.sector.relative)
    ret.may_rise()
    # use helper function to extract all harvestable sector objects from sector observation
    planets = get_harvestable(ret.data)
    assert len(planets) > 0
    # start harvest
    ret, action = await client.others.ship.harvest(mothership.id, planets[0].id, mothership.auxiliaryCount)
    ret.may_rise()
    pprint(action)
    
asyncio.run(main())

Metadata

Release files for vng-api 1.150.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 vng-api 1.150.1
File Size Uploaded Provenance Actions
vng_api-1.150.1.tar.gz 39.4 kB Without provenance Details for vng_api-1.150.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vng-api 1.150.1
File Interpreter ABI Platform Actions
vng_api-1.150.1-py3-none-any.whl Python 3 none any Details for vng_api-1.150.1-py3-none-any.whl

Total release size: 94.0 kB

Release files / vng_api-1.150.1.tar.gz

Download URL vng_api-1.150.1.tar.gz
Size 39.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5f7a0be6425d520c386aa801c918f518030aa6608d181a999780ec46eda9ad3f
BLAKE2b-256 checksum
How to use checksums
ce45b0da55f90fcd77c1bd79d5dd37dcc0b13a641548ae9135d394d59e6cd416
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.1

Release files / vng_api-1.150.1-py3-none-any.whl

Download URL vng_api-1.150.1-py3-none-any.whl
Size 54.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0658bafa73f512eef85da8216167a70c33648a8151ec83d9a83bd2da000f0238
BLAKE2b-256 checksum
How to use checksums
bc9a10aa9a552966f104bb54fbf621ff3ebb59ee3333f34521e31715e52d9652
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.1

Security for vng-api 1.150.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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