DESCRIPTION.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. ========
  2. queuelib
  3. ========
  4. .. image:: https://secure.travis-ci.org/scrapy/queuelib.png?branch=master
  5. :target: http://travis-ci.org/scrapy/queuelib
  6. .. image:: https://img.shields.io/codecov/c/github/scrapy/queuelib/master.svg
  7. :target: http://codecov.io/github/scrapy/queuelib?branch=master
  8. :alt: Coverage report
  9. Queuelib is a collection of persistent (disk-based) queues for Python.
  10. Queuelib goals are speed and simplicity. It was originally part of the `Scrapy
  11. framework`_ and stripped out on its own library.
  12. Requirements
  13. ============
  14. * Python 2.7 or Python 3.3
  15. * no external library requirements
  16. Installation
  17. ============
  18. You can install Queuelib either via the Python Package Index (PyPI) or from
  19. source.
  20. To install using pip::
  21. $ pip install queuelib
  22. To install using easy_install::
  23. $ easy_install queuelib
  24. If you have downloaded a source tarball you can install it by running the
  25. following (as root)::
  26. # python setup.py install
  27. FIFO/LIFO disk queues
  28. =====================
  29. Queuelib provides FIFO and LIFO queue implementations.
  30. Here is an example usage of the FIFO queue::
  31. >>> from queuelib import FifoDiskQueue
  32. >>> q = FifoDiskQueue("queuefile")
  33. >>> q.push(b'a')
  34. >>> q.push(b'b')
  35. >>> q.push(b'c')
  36. >>> q.pop()
  37. b'a'
  38. >>> q.close()
  39. >>> q = FifoDiskQueue("queuefile")
  40. >>> q.pop()
  41. b'b'
  42. >>> q.pop()
  43. b'c'
  44. >>> q.pop()
  45. >>>
  46. The LIFO queue is identical (API-wise), but importing ``LifoDiskQueue``
  47. instead.
  48. PriorityQueue
  49. =============
  50. A discrete-priority queue implemented by combining multiple FIFO/LIFO queues
  51. (one per priority).
  52. First, select the type of queue to be used per priority (FIFO or LIFO)::
  53. >>> from queuelib import FifoDiskQueue
  54. >>> qfactory = lambda priority: FifoDiskQueue('queue-dir-%s' % priority)
  55. Then instantiate the Priority Queue with it::
  56. >>> from queuelib import PriorityQueue
  57. >>> pq = PriorityQueue(qfactory)
  58. And use it::
  59. >>> pq.push(b'a', 3)
  60. >>> pq.push(b'b', 1)
  61. >>> pq.push(b'c', 2)
  62. >>> pq.push(b'd', 2)
  63. >>> pq.pop()
  64. b'b'
  65. >>> pq.pop()
  66. b'c'
  67. >>> pq.pop()
  68. b'd'
  69. >>> pq.pop()
  70. b'a'
  71. Mailing list
  72. ============
  73. Use the `scrapy-users`_ mailing list for questions about Queuelib.
  74. Bug tracker
  75. ===========
  76. If you have any suggestions, bug reports or annoyances please report them to
  77. our issue tracker at: http://github.com/scrapy/queuelib/issues/
  78. Contributing
  79. ============
  80. Development of Queuelib happens at GitHub: http://github.com/scrapy/queuelib
  81. You are highly encouraged to participate in the development. If you don't like
  82. GitHub (for some reason) you're welcome to send regular patches.
  83. All changes require tests to be merged.
  84. Tests
  85. =====
  86. Tests are located in `queuelib/tests` directory. They can be run using
  87. `nosetests`_ with the following command::
  88. nosetests
  89. The output should be something like the following::
  90. $ nosetests
  91. .............................................................................
  92. ----------------------------------------------------------------------
  93. Ran 77 tests in 0.145s
  94. OK
  95. License
  96. =======
  97. This software is licensed under the BSD License. See the LICENSE file in the
  98. top distribution directory for the full license text.
  99. Versioning
  100. ==========
  101. This software follows `Semantic Versioning`_
  102. .. _Scrapy framework: http://scrapy.org
  103. .. _scrapy-users: http://groups.google.com/group/scrapy-users
  104. .. _Semantic Versioning: http://semver.org/
  105. .. _nosetests: https://nose.readthedocs.org/en/latest/