Welcome to SpacePyTraders’s documentation!

SpacePyTraders.client.get_user_token(username)

Trys to create a new user and return their token

Parameters

username (str) – Username to user

Returns

Token if user valid else None

Return type

str

SpacePyTraders.client.make_request(method, url, headers, params)

Checks which method to use and then makes the actual request to Space Traders API

Parameters
  • method (str) – The HTTP method to use

  • url (str) – The URL of the request

  • headers (dict) – the request headers holding the Auth

  • params (dict) – parameters of the request

Returns

Returns the request

Return type

Request

Exceptions:

Exception: Invalid method - must be GET, POST, PUT or DELETE

Api

class SpacePyTraders.client.Api(username, token=None)
__init__(username, token=None)

Initialize self. See help(type(self)) for accurate signature.

Client

class SpacePyTraders.client.Client(username, token=None)
generic_api_call(method, endpoint, params=None, token=None, warning_log=None)

Function to make consolidate parameters to make an API call to the Space Traders API. Handles any throttling or error returned by the Space Traders API.

Parameters
  • method (str) – The HTTP method to use. GET, POST, PUT or DELETE

  • endpoint (str) – The API endpoint

  • params (dict, optional) – Any params required for the endpoint. Defaults to None.

  • token (str, optional) – The token of the user. Defaults to None.

Returns

depends on the return from the API but likely JSON

Return type

Any

Flight Plans

class SpacePyTraders.client.FlightPlans(username, token=None)
get_active_flight_plans(symbol)

Get all the currently active flight plans in the system given. This is for all global accounts

Parameters

symbol (str) – Symbol of the system. OE or XV

Returns

dict containing a list of flight plans for each system as the key

Return type

dict

get_flight_plan(flightPlanId)

Get the details of a currently active flight plan

Parameters

flightPlanId (str) – ID of the flight plan

Returns

dict containing the details of the flight plan

Return type

dict

new_flight_plan(shipId, destination)

Submit a new flight plan for a ship

Parameters
  • shipId (str) – ID of the ship to fly

  • destination (str) – Symbol of the locatino to fly the ship to

Game

class SpacePyTraders.client.Game(username, token=None)
get_game_status()

Check to see if game is up

Loans

class SpacePyTraders.client.Loans(username, token=None)
get_loans_available()

Gets the list of loans available

Returns

dict containing a list of loans

Return type

dict

get_user_loans()

Gets the list of loans available

Returns

dict containing a list of loans

Return type

dict

pay_off_loan(loanId)

Pays of the loan with ID provided

Parameters

loanId (str) – ID of the loan to pay off

Returns

Success or fail message

Return type

dict

request_loan(type)

Request a new loan

Parameters

type (str) – The type of loan - e.g. STARTUP

Returns

The loan taken

Return type

dict

Locations

class SpacePyTraders.client.Locations(username, token=None)
get_location(symbol)

Get info on a location with the provided Symbol

Parameters

symbol (str) – The symbol for the location eg: OE-PM

Returns

A dict containing info about a location

Return type

dict

get_ships_at_location(symbol)

Get the ships docked at a location

Parameters

symbol (str) – The symbol for the location eg: OE-PM

Returns

A dict containing a JSON list of the ships docked at the location.

Return type

dict

get_system_locations(symbol)

Get locations in the defined system

Parameters

symbol (str) – The symbol for the system eg: OE

Returns

A dict containing a JSON list of the locations in the system

Return type

dict

Marketplace

class SpacePyTraders.client.Marketplace(username, token=None)
get_marketplace(symbol)

Get the marketplace for the location provided

Parameters

symbol (str) – The symbol for the location eg: OE-PM

Returns

A dict containing details of the location and a JSON list of the items available in the marketplace

Return type

dict

PurchaseOrders

class SpacePyTraders.client.PurchaseOrders(username, token=None)
new_purchase_order(shipId, good, quantity)

Makes a purchase order to the location the ship is currently located at.

Parameters
  • shipId (str) – ID of the ship to load the goods onto

  • good (str) – Symbol of the good to purchase

  • quantity (int) – How many units of the good to purchase

SellOrders

class SpacePyTraders.client.SellOrders(username, token=None)
new_sell_order(shipId, good, quantity)

Makes a sell order to the location the ship is currently located at.

Parameters
  • shipId (str) – ID of the ship to offload the goods from

  • good (str) – Symbol of the good to sell

  • quantity (int) – How many units of the good to sell

Ships

class SpacePyTraders.client.Ships(username, token=None)
buy_ship(location, type)

Buys a ship of the type provided and at the location provided. Certain ships can only be bought from specific locations. Use get_available_ships to see full list.

Parameters
  • location (str) – symbol of the location the ship to buy is

  • type (str) – type of ship you want to buy e.g. GR-MK-III

get_available_ships(type=None)

Get the avialable ships to purchase across all systems

Parameters

type (str, optional) – Filter the list of ships to the class level. eg ‘MK-II’ (Note: those are capital i’s). Defaults to None.

Returns

A dict containing a JSON list of ships that are available.

Return type

dict

API LINK: https://api.spacetraders.io/#api-ships-ships

get_ship(shipId)

Get info on the ship

Parameters

shipId (str) – The shipId of the ship you want to get info on

Returns

A dict containing the info about the ship

Return type

dict

API LINK: https://api.spacetraders.io/#api-ships-GetShip

get_user_ships()

Get a list of all the ships you own

Returns

A JSON list of the ships you own. Each item is a return from the get_ship_info endpoint.

Return type

dict

API Link: https://api.spacetraders.io/#api-ships-GetShips

jettinson_cargo(shipId, good, quantity)

Jettison (delete) some cargo from a ship

Parameters
  • shipId (str) – The shipId of the ship you want to jettison cargo from

  • good (str) – The symbol of the good you want to jettison. Eg. FUEL

  • quantity (int) – How many units of the good you want to jettison

Returns

If successful a dict is returned with the remaining quantitiy of the good on the ship

Return type

dict

API Link: https://api.spacetraders.io/#api-ships-JettisonCargo

scrap_ship(shipId)

Scraps the shipId for a small amount of credits. Ships need to be scraped at a location with a Shipyard. Known Shipyards: - OE-PM-TR

Parameters

shipId (str) – ID of the ship to scrap

Returns

True if the ship was scrapped

Return type

bool

Raises

Exception – If something went wrong during the scrapping process

transfer_cargo(fromShipId, toShipId, good, quantity)

Move cargo from own ship to another that are in the same location

Parameters
  • fromShipId (str) – The shipId of the ship you want to transfer the cargo FROM

  • toShipId (str) – The shipId of the ship you want to transfer the cargo TO

  • good (str) – The symbol of the good you want to transfer. Eg. FUEL

  • quantity (int) – How many units of the good you want to transfer

Returns

A dict is returned with two keys “fromShip” & “toShip” each with the updated ship info for the respective ships

Return type

dict

API Link: https://api.spacetraders.io/#api-ships-TransferCargo

Structures

class SpacePyTraders.client.Structures(username, token=None)
create_new_structure(location, type)

Create a new structure on the location provided. Note that only certain structures can be built at specific locations

Parameters
  • location (str) – symbol of the location to build the structure

  • type (str) – type of structure you want to build

deposit_goods(structureId, shipId, good, quantity)

Deposit goods from a ship to a structure. The ship must be at the location the structure has been built.

Parameters
  • structureId (str) – ID of the structure to deposit the goods into

  • shipId (str) – ID of the ship to take the goods from

  • good (str) – symbol of the good to deposite. Eg: FUEL

  • quantity (str) – How many units of the good to deposit

Returns

dict containing the updated info of the ship and structure

Return type

dict

get_structure(structureId)

Get the info about a structure

Parameters

structureId (str) – ID of the structure to deposit the goods into

Returns

dict containing the info of the strucutre

Return type

dict

get_users_structures()

Get the info about a structure

Returns

dict containings a JSON list of the structures the user owns

Return type

dict

transfer_goods(structureId, shipId, good, quantity)

Transfer goods from a structure to a ship. The ship must be docked at the location the structure has been built.

Parameters
  • structureId (str) – ID of the structure to deposit the goods into

  • shipId (str) – ID of the ship to take the goods from

  • good (str) – symbol of the good to deposite. Eg: FUEL

  • quantity (str) – How many units of the good to deposit

Returns

dict containing the updated info of the ship and structure

Return type

dict

Systems

class SpacePyTraders.client.Systems(username, token=None)
get_systems()

Get info about the systems and their locations.

Returns

dict containing a JSON list of the different systems

Return type

dict

Users

class SpacePyTraders.client.Users(username, token=None)
get_your_info()

Get your user info

Returns

dict containing your user data

Return type

dict

Indices and tables