Skip to main content

Synchronous / Asynchronous NationStates API wrapper for Python

Project description

pypi Code style: black Build Status Documentation Status

Synchronous / Asynchronous NationStates (Python wrapper for the NationStates API)

Note

While this library can be run in a single-threaded, synchronous environment, it is highly recommended to use Dolph’s pynationstates (GitHub | PyPI) for simpler scripts.

Installing

python3 -m pip install -U sans

Development version:

python3 -m pip install -U https://github.com/zephyrkul/sans/archive/master.zip#egg=sans

Examples

Asynchronous

import asyncio
import sans
from sans.api import Api, Dumps
from sans.utils import pretty_string

async def main():
    Api.agent = "Darcania"
    request = Api(
        "fullname population flag census",
        nation="darcania",
        mode="score",
        scale="65 66",
    )
    root = await request
    pretty = pretty_string(root)
    print(pretty)

    request = Dumps.REGIONS
    async for region in request:
        pretty = pretty_string(region)
        print(pretty)


asyncio.run(main())  # Python 3.7+ only

Synchronous

import sans
from sans.api import Api, Dumps

def main():
    sans.run_in_thread()
    Api.agent = "Darcania"
    request = Api(
        "fullname population flag census",
        nation="darcania",
        mode="score",
        scale="65 66",
    )
    root = request.threadsafe()
    pretty = pretty_string(root)
    print(pretty)

    request = Dumps.REGIONS
    for region in request.threadsafe:
        pretty = pretty_string(region)
        print(pretty)


main()

Command Line

python3 -m sans --nation darcania census --scale "65 66" --mode score --agent Darcania
<NATION>...</NATION>
sans --nation testlandia fullname
<NATION>...</NATION>
sans --region "the north pacific" numnations lastupdate
<REGION>...</REGION>
sans --quit
Exiting...

Requirements

  • Python 3.6+
  • aiohttp
  • lxml

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for sans, version 0.0.1b7
Filename, size File type Python version Upload date Hashes
Filename, size sans-0.0.1b7-py3-none-any.whl (14.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size sans-0.0.1b7.tar.gz (12.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page