Synchronous / Asynchronous NationStates API wrapper for Python
Project description
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
Release history Release notifications | RSS feed
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)
Built Distribution
sans-0.0.1-py3-none-any.whl
(14.6 kB
view hashes)