Pynationstates

Content Pages

Requesting the API

The Nationstates package includes a simple interface for developers.

For example, for the following code:

>>> import nationstates as ns
>>> api = ns.Api(UniqueAndDescriptiveUserAgent)
>>> nation = api.get_nation("The United Island Tribes")

The Api object centralizes API use. It preforms the necessary handeling of Nationstates objects to create objects that share certain attributes (Such as requests’s Session object). The :method:`.get_nation` method creates a Nationstates object for the ‘The United Island Tribes’.

Shards

The Nationstates package has multiple ways to represent shards, Strings and the Shard Object.

Using Strings

Strings can be used to represent simpler shards.

>>> import nationstates as ns
>>> api = ns.Nationstates(UniqueAndDescriptiveUserAgent)
>>> r = api.world().get_shards("numnations")

Shard Object

The Shard Object was built to allow more complicated shards. They allow you to attach parameters to the shard as well as just plainly representing a shard. It is recommended for more dynamic/advanced usage of the module.

>>> import nationstates as ns
>>> api = ns.Nationstates(UniqueAndDescriptiveUserAgent)
>>> happenings = ns.Shard("happenings", view="region.the_pacific", filter="founding")
>>> r = api.world().get_shards(happenings])

Code Overview

Here you will find an overview of Pynationstates’s objects and methods, but not the objects attributes which are generated dynamically by pynationstates.

nationstates Package