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.

Source Distribution

sans-0.0.1.tar.gz (18.4 kB view hashes)

Uploaded source

Built Distribution

sans-0.0.1-py3-none-any.whl (14.6 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page