Metadata-Version: 2.1
Name: sans
Version: 1.1.1
Summary: Synchronous / Asynchronous HTTPX extension for NationStates
Author: Zephyrkul
License: MIT License
        
        Copyright (c) 2018 - 2023
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: homepage, https://github.com/Zephyrkul/sans
Project-URL: documentation, https://sans.readthedocs.io/en/stable/
Project-URL: repository, https://github.com/Zephyrkul/sans.git
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: AsyncIO
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Internet
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Classifier: Typing :: Typed
Requires-Python: <4.0,>=3.7.0
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: httpx (~=0.23)
Requires-Dist: importlib-metadata (>=1.4.0) ; python_version < "3.8"
Provides-Extra: docs
Requires-Dist: Sphinx (~=5.3) ; extra == 'docs'
Provides-Extra: json
Requires-Dist: xmltodict (~=0.13) ; extra == 'json'
Provides-Extra: lxml
Requires-Dist: lxml (~=4.9) ; extra == 'lxml'

sans
====

|pypi| |Code style: black| |Build Status| |Documentation Status|

**S**\ ynchronous / **A**\ synchronous **N**\ ation\ **S**\ tates

An extension for `HTTPX <https://www.python-httpx.org/>`_ for the `NationStates API <https://www.nationstates.net/pages/api.html>`_

Installing
----------

.. code::

   python3 -m pip install -U sans

Development version:

.. code::

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

Examples
--------

Synchronous
~~~~~~~~~~~

.. code:: python

   import sans
   from xml.etree import ElementTree as ET

   def main():
      sans.set_agent("Darcania")
      request = sans.Nation(
         "darcania",
         "fullname population flag census",
         mode="score",
         scale="65 66",
      )
      root = sans.get(request)
      sans.indent(root)
      print(ET.tostring(root, encoding="unicode"))

      with sans.stream("GET", sans.RegionsDump()) as response:
         for region in response.iter_xml():
            sans.indent(region)
            print(ET.tostring(region, encoding="unicode"))

   if __name__ == "__main__":
      main()

Asynchronous
~~~~~~~~~~~~

.. code:: python

   import asyncio
   import sans
   from xml.etree import ElementTree as ET

   async def main():
      sans.set_agent("Darcania")
      async with sans.AsyncClient() as client:
         request = sans.Nation(
            "darcania",
            "fullname population flag census",
            mode="score",
            scale="65 66",
         )
         root = (await client.send(request)).xml
         sans.indent(root)
         print(ET.tostring(root, encoding="unicode"))

         async with client.stream("GET", sans.RegionsDump()) as response:
            async for region in response.aiter_xml():
               sans.indent(region)
               print(ET.tostring(region, encoding="unicode"))

   if __name__ == "__main__":
      asyncio.run(main())

Command Line
------------

.. code::

   $ sans --nation darcania census --scale "65 66" --mode score --agent Darcania

   <CENSUS>
      <SCALE id="65">
         <SCORE>4949.00</SCORE>
      </SCALE>
      <SCALE id="66">
         <SCORE>130.00</SCORE>
      </SCALE>
   </CENSUS>

   $ sans --nation testlandia fullname

   <FULLNAME>The Hive Mind of Testlandia</FULLNAME>

   sans --region "the north pacific" numnations lastupdate

   <LASTUPDATE>1683650325</LASTUPDATE>
   <NUMNATIONS>10503</NUMNATIONS>

   $ sans --quit
   No query provided. Exiting...

Requirements
------------

-  Python 3.7+
-  httpx

.. |pypi| image:: https://img.shields.io/pypi/v/sans.svg
   :target: https://pypi.python.org/pypi/sans
   :alt: pypi version
.. |Code style: black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
   :target: https://github.com/ambv/black
.. |Build Status| image:: https://results.pre-commit.ci/badge/github/Zephyrkul/sans/master.svg
   :target: https://results.pre-commit.ci/latest/github/Zephyrkul/sans/master
   :alt: pre-commit.ci status
.. |Documentation Status| image:: https://readthedocs.org/projects/sans/badge/?version=latest
   :target: http://sans.readthedocs.org/en/latest/?badge=latest
