DESCRIPTION.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. .. image:: https://raw.githubusercontent.com/msiemens/tinydb/master/artwork/logo.png
  2. :scale: 100%
  3. :height: 150px
  4. |Build Status| |Coverage| |Version|
  5. Quick Links
  6. ***********
  7. - `Example Code`_
  8. - `Supported Python Versions`_
  9. - `Documentation <http://tinydb.readthedocs.org/>`_
  10. - `Changelog <https://tinydb.readthedocs.io/en/latest/changelog.html>`_
  11. - `Extensions <https://tinydb.readthedocs.io/en/latest/extensions.html>`_
  12. - `Contributing`_
  13. Introduction
  14. ************
  15. TinyDB is a lightweight document oriented database optimized for your happiness :)
  16. It's written in pure Python and has no external dependencies. The target are
  17. small apps that would be blown away by a SQL-DB or an external database server.
  18. TinyDB is:
  19. - **tiny:** The current source code has 1200 lines of code (with about 40%
  20. documentation) and 1000 lines tests. For comparison: Buzhug_ has about 2500
  21. lines of code (w/o tests), CodernityDB_ has about 7000 lines of code
  22. (w/o tests).
  23. - **document oriented:** Like MongoDB_, you can store any document
  24. (represented as ``dict``) in TinyDB.
  25. - **optimized for your happiness:** TinyDB is designed to be simple and
  26. fun to use by providing a simple and clean API.
  27. - **written in pure Python:** TinyDB neither needs an external server (as
  28. e.g. `PyMongo <http://api.mongodb.org/python/current/>`_) nor any dependencies
  29. from PyPI.
  30. - **works on Python 2.7 and 3.3 – 3.6 and PyPy:** TinyDB works on all modern
  31. versions of Python and PyPy.
  32. - **powerfully extensible:** You can easily extend TinyDB by writing new
  33. storages or modify the behaviour of storages with Middlewares.
  34. - **100% test coverage:** No explanation needed.
  35. To dive straight into all the details, head over to the `TinyDB docs
  36. <https://tinydb.readthedocs.io/>`_. You can also discuss everything related
  37. to TinyDB like general development, extensions or showcase your TinyDB-based
  38. projects on the `discussion forum <http://forum.m-siemens.de/.>`_.
  39. Supported Python Versions
  40. *************************
  41. TinyDB has been tested with Python 2.7, 3.3 - 3.6 and PyPy.
  42. Example Code
  43. ************
  44. .. code-block:: python
  45. >>> from tinydb import TinyDB, Query
  46. >>> db = TinyDB('/path/to/db.json')
  47. >>> db.insert({'int': 1, 'char': 'a'})
  48. >>> db.insert({'int': 1, 'char': 'b'})
  49. Query Language
  50. ==============
  51. .. code-block:: python
  52. >>> User = Query()
  53. >>> # Search for a field value
  54. >>> db.search(User.name == 'John')
  55. [{'name': 'John', 'age': 22}, {'name': 'John', 'age': 37}]
  56. >>> # Combine two queries with logical and
  57. >>> db.search((User.name == 'John') & (User.age <= 30))
  58. [{'name': 'John', 'age': 22}]
  59. >>> # Combine two queries with logical or
  60. >>> db.search((User.name == 'John') | (User.name == 'Bob'))
  61. [{'name': 'John', 'age': 22}, {'name': 'John', 'age': 37}, {'name': 'Bob', 'age': 42}]
  62. >>> # More possible comparisons: != < > <= >=
  63. >>> # More possible checks: where(...).matches(regex), where(...).test(your_test_func)
  64. Tables
  65. ======
  66. .. code-block:: python
  67. >>> table = db.table('name')
  68. >>> table.insert({'value': True})
  69. >>> table.all()
  70. [{'value': True}]
  71. Using Middlewares
  72. =================
  73. .. code-block:: python
  74. >>> from tinydb.storages import JSONStorage
  75. >>> from tinydb.middlewares import CachingMiddleware
  76. >>> db = TinyDB('/path/to/db.json', storage=CachingMiddleware(JSONStorage))
  77. Contributing
  78. ************
  79. Whether reporting bugs, discussing improvements and new ideas or writing
  80. extensions: Contributions to TinyDB are welcome! Here's how to get started:
  81. 1. Check for open issues or open a fresh issue to start a discussion around
  82. a feature idea or a bug
  83. 2. Fork `the repository <https://github.com/msiemens/tinydb/>`_ on Github,
  84. create a new branch off the `master` branch and start making your changes
  85. (known as `GitHub Flow <https://guides.github.com/introduction/flow/index.html>`_)
  86. 3. Write a test which shows that the bug was fixed or that the feature works
  87. as expected
  88. 4. Send a pull request and bug the maintainer until it gets merged and
  89. published ☺
  90. .. |Build Status| image:: http://img.shields.io/travis/msiemens/tinydb.svg?style=flat-square
  91. :target: https://travis-ci.org/msiemens/tinydb
  92. .. |Coverage| image:: http://img.shields.io/coveralls/msiemens/tinydb.svg?style=flat-square
  93. :target: https://coveralls.io/r/msiemens/tinydb
  94. .. |Version| image:: http://img.shields.io/pypi/v/tinydb.svg?style=flat-square
  95. :target: https://pypi.python.org/pypi/tinydb/
  96. .. _Buzhug: http://buzhug.sourceforge.net/
  97. .. _CodernityDB: http://labs.codernity.com/codernitydb/
  98. .. _MongoDB: http://mongodb.org/