Synchronous / Asynchronous NationStates API wrapper for Python
Project description
sans
Synchronous / Asynchronous NationStates (Python wrapper for the NationStates API)
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 lxml import etree
async def main():
sans.Api.agent = "Darcania"
request = sans.Api(
"fullname population flag census",
nation="darcania",
mode="score",
scale="65 66",
)
root = await request
pretty = root.to_pretty_string()
print(pretty)
request = sans.Dumps.REGIONS
async for region in request:
pretty = region.to_pretty_string()
print(pretty)
asyncio.run(main()) # Python 3.7+ only
Synchronous
import sans
from lxml import etree
def main():
sans.run_in_thread()
sans.Api.agent = "Darcania"
request = sans.Api(
"fullname population flag census",
nation="darcania",
mode="score",
scale="65 66",
)
root = request.threadsafe()
pretty = root.to_pretty_string()
print(pretty)
request = sans.Dumps.REGIONS
for region in request.threadsafe:
pretty = region.to_pretty_string()
print(pretty)
main()
Command Line
python3 -m sans --nation darcania census --scale "65 66" --mode score
User Agent: Darcania
<NATION>...</NATION>
>>> --nation testlandia fullname
<NATION>...</NATION>
>>> --region "the north pacific" numnations lastupdate
<REGION>...</REGION>
>>>
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.1a1.tar.gz
(8.4 kB
view hashes)
Built Distribution
sans-0.0.1a1-py3-none-any.whl
(12.6 kB
view hashes)