semvec/pypi-packages huggingface dataset:
hug_peewee 0.0.2
An extension to hug that adds clean integration with the peewee ORM
License: MIT
Keywords: Python,Python3

hug\_peewee
===========

|PyPI version| |Build Status| |Coverage Status| |License| |Join the chat
at https://gitter.im/timothycrosley/hug\_peewee|

An extension to hug that adds clean integration with the peewee ORM:

.. code:: py

    import hug_peewee

    db = hug_peewee.connection.manage(__name__, 'sqlite', 'my.db')

Works with hug 2.1.0 or greater.

Installing hug\_peewee
======================

Installing hug\_peewee is as simple as:

.. code:: bash

    pip3 install hug_peewee --upgrade

Ideally, within a virtual environment.

What is hug\_peewee?
====================

An extension to hug that adds clean integration with the peewee ORM

--------------

Thanks and I hope you find hug\_peewee helpful!

~Timothy Crosley

.. |PyPI version| image:: https://badge.fury.io/py/hug_peewee.svg
   :target: http://badge.fury.io/py/hug_peewee
.. |Build Status| image:: https://travis-ci.org/timothycrosley/hug_peewee.svg?branch=master
   :target: https://travis-ci.org/timothycrosley/hug_peewee
.. |Coverage Status| image:: https://coveralls.io/repos/timothycrosley/hug_peewee/badge.svg?branch=master&service=github
   :target: https://coveralls.io/github/timothycrosley/hug_peewee?branch=master
.. |License| image:: https://img.shields.io/github/license/mashape/apistatus.svg
   :target: https://pypi.python.org/pypi/hug_peewee/
.. |Join the chat at https://gitter.im/timothycrosley/hug\_peewee| image:: https://badges.gitter.im/Join%20Chat.svg
   :target: https://gitter.im/timothycrosley/hug_peewee?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
visitor 0.1.3
A tiny pythonic visitor implementation.
License: MIT

visitor
=======

A tiny library to facilitate `visitor
<https://en.wikipedia.org/wiki/Visitor_pattern>`_ implementation in Python
(which are slightly peculiar due to dynamic typing). In fact, it is so small,
you may just be better off copy & pasting the source straight into your
project...


Example use
-----------

A simple JSON-encoder:

.. code-block:: python

    from visitor import Visitor


    class JSONEncoder(Visitor):
        def __init__(self):
            self.indent = 0

        def escape_str(self, s):
            # note: this is not a good escape function, do not use this in
            # production!
            s = s.replace('\\', '\\\\')
            s = s.replace('"', '\\"')
            return '"' + s + '"'

        def visit_list(self, node):
            self.indent += 1
            s = '[\n' + '  ' * self.indent
            s += (',\n' + '  ' * self.indent).join(self.visit(item)
                                                   for item in node)
            self.indent -= 1
            s += '\n' + '  ' * self.indent + ']'
            return s

        def visit_str(self, node):
            return self.escape_str(node)

        def visit_int(self, node):
            return str(node)

        def visit_bool(self, node):
            return 'true' if node else 'false'

        def visit_dict(self, node):
            self.indent += 1
            s = '{\n' + '  ' * self.indent
            s += (',\n' + '  ' * self.indent).join(
                '{}: {}'.format(self.escape_str(key), self.visit(value))
                for key, value in sorted(node.items())
            )
            self.indent -= 1
            s += '\n' + '  ' * self.indent + '}'
            return s


    data = [
        'List', 'of', 42, 'items', True, {
            'sub1': 'some string',
            'sub2': {
                'sub2sub1': False,
                'sub2sub2': 123,
            }
        }
    ]

    print(JSONEncoder().visit(data))



Output::

    [
      "List",
      "of",
      42,
      "items",
      true,
      {
        "sub1": "some string",
        "sub2": {
          "sub2sub1": false,
          "sub2sub2": 123
        }
      }
    ]