queue.Queue and collections.deque serve different purposes. queue.Queue is intended for allowing different threads to communicate using queued messages/data, whereas collections.deque is simply intended as a data structure. That's why queue.Queue has methods like put_nowait(), get_nowait(), and join(), whereas collections.deque doesn't. queue.Queue isn't intended to be used as a collection, which is why it lacks the likes of the in operator.

It boils down to this: if you have multiple threads and you want them to be able to communicate without the need for locks, you're looking for queue.Queue; if you just want a queue or a double-ended queue as a datastructure, use collections.deque.

Finally, accessing and manipulating the internal deque of a queue.Queue is playing with fire - you really don't want to be doing that.

Answer from Keith Gaughan on Stack Overflow
🌐
Python
docs.python.org › 3 › library › collections.html
collections — Container datatypes
class collections.deque([iterable[, maxlen]])¶ · Returns a new deque object initialized left-to-right (using append()) with data from iterable. If iterable is not specified, the new deque is empty. Deques are a generalization of stacks and queues (the name is pronounced “deck” and is short for “double-ended queue”).
Top answer
1 of 7
429

queue.Queue and collections.deque serve different purposes. queue.Queue is intended for allowing different threads to communicate using queued messages/data, whereas collections.deque is simply intended as a data structure. That's why queue.Queue has methods like put_nowait(), get_nowait(), and join(), whereas collections.deque doesn't. queue.Queue isn't intended to be used as a collection, which is why it lacks the likes of the in operator.

It boils down to this: if you have multiple threads and you want them to be able to communicate without the need for locks, you're looking for queue.Queue; if you just want a queue or a double-ended queue as a datastructure, use collections.deque.

Finally, accessing and manipulating the internal deque of a queue.Queue is playing with fire - you really don't want to be doing that.

2 of 7
64

If all you're looking for is a thread-safe way to transfer objects between threads, then both would work (both for FIFO and LIFO). For FIFO:

  • Queue.put() and Queue.get() are thread-safe
  • Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.

Note:

  • Other operations on deque might not be thread safe, I'm not sure.
  • deque does not block on pop() or popleft() so you can't base your consumer thread flow on blocking till a new item arrives.

However, it seems that deque has a significant efficiency advantage. Here are some benchmark results in seconds using CPython 2.7.3 for inserting and removing 100k items

deque 0.0747888759791
Queue 1.60079066852

Here's the benchmark code:

import time
import Queue
import collections

q = collections.deque()
t0 = time.clock()
for i in xrange(100000):
    q.append(1)
for i in xrange(100000):
    q.popleft()
print 'deque', time.clock() - t0

q = Queue.Queue(200000)
t0 = time.clock()
for i in xrange(100000):
    q.put(1)
for i in xrange(100000):
    q.get()
print 'Queue', time.clock() - t0
🌐
GeeksforGeeks
geeksforgeeks.org › python › deque-in-python
Deque in Python - GeeksforGeeks
A deque stands for Double-Ended Queue. It is a special type of data structure that allows to add and remove elements from both ends efficiently. This makes it useful in applications like task scheduling, sliding window problems and real-time data processing. Python · from collections import deque de = deque(['name','age','DOB']) print(de) Output ·
Published   December 11, 2025
🌐
Dataquest
dataquest.io › blog › python-deque-queues-stacks
Python Deque Function: A Better Choice for Queues and Stacks – Dataquest
April 7, 2025 - If you use Python, you're probably familiar with lists, and you probably use them a lot, too. They're great data structures with many helpful methods that allow the user to modify the list by adding, removing, and sorting items. However, there are some use cases when a list may look like a great choice, but it just isn't. That is where the deque() function (short for double-ended queue, pronounced like "deck") from the collections module can be a much better choice when you need to implement queues and stacks in Python.
🌐
CircuitPython
docs.circuitpython.org › en › latest › docs › library › collections.html
collections – collection and container types — Adafruit CircuitPython 1 documentation
class collections.deque(iterable, maxlen[, flag]) · Deques (pronounced “deck” and short for “double-ended queue”) are fixed length list-like containers that support O(1) appends and pops from either side of the deque.
🌐
CodeSignal
codesignal.com › learn › courses › advanced-built-in-data-structures-and-their-usage › lessons › understanding-queues-and-deques-in-python
Understanding Queues and Deques in Python
A deque, or "double-ended queue", allows the addition and removal of items from both ends. Python provides the collections module containing the deque class for implementing deques.
🌐
Python
docs.python.org › 3 › library › queue.html
queue — A synchronized queue class
February 23, 2026 - collections.deque is an alternative implementation of unbounded queues with fast atomic append() and popleft() operations that do not require locking and also support indexing. ... © Copyright 2001 Python Software Foundation.
🌐
GeeksforGeeks
geeksforgeeks.org › python › creating-queue-using-collections-deque-in-python
Creating Queue Using Collections.Deque In Python - GeeksforGeeks
July 23, 2025 - In Python, Queue and Deque are the data structures used for managing collections of elements in a first-in, first-out (FIFO) manner.
Find elsewhere
🌐
Medium
medium.com › @sanjula99perera › efficient-queue-implementation-in-python-using-collections-deque-2446908ffa34
“Efficient Queue Implementation in Python Using collections.deque” | by Sanjulaperera | Medium
May 28, 2024 - Initial queue: ['a', 'b', 'c'] Elements dequeued from queue: a b c Queue after removing elements: [] ... The deque class from the collections module provides an efficient way to implement a queue.
🌐
Real Python
realpython.com › python-deque
Python's deque: Implement Efficient Queues and Stacks – Real Python
January 12, 2026 - It implements multi-producer, ... abstractions over deque unless you’re implementing your own data structure. Queues are collections of items....
🌐
Note.nkmk.me
note.nkmk.me › home › python
How to Use Deque in Python: collections.deque | note.nkmk.me
April 20, 2025 - In Python, the collections.deque class provides an efficient way to handle data as a queue, stack, or deque (double-ended queue). collections - deque objects — Container datatypes — Python 3.13.3 do ...
🌐
Codecademy
codecademy.com › docs › python › deque
Python | Deque | Codecademy
April 10, 2025 - A deque is a double-ended queue implementation in Python’s collections module. It provides a versatile data structure that generalizes a stack and a queue by allowing efficient append and pop operations from both ends of the sequence.
🌐
getopt
rico-schmidt.name › pymotw-3 › collections › deque.html
deque — Cola doblemente terminada — El módulo Python 3 de la semana
$ python3 collections_deque_populating.py extend : deque(['a', 'b', 'c', 'd', 'e', 'f', 'g']) append : deque(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']) extendleft: deque([5, 4, 3, 2, 1, 0]) appendleft: deque([6, 5, 4, 3, 2, 1, 0])
🌐
Educative
educative.io › answers › how-to-implement-a-queue-in-python
How to implement a queue in Python
We have used the following methods ... False. ... The collections.deque module in Python provides a double-ended queue (deque) that allows adding and removing elements efficiently from both ends....
🌐
Medium
medium.com › @shras_a › queue-in-python-34a74641502e
Queue in Python. Queues are fundamental data structures… | by Shravya | Medium
November 14, 2024 - This article will walk you through the basics of queues, their types, and how to work with them in Python. ... FIFO Queue: First In, First Out. Processing items in arrival order (e.g., task scheduling). Example: queue.Queue or collections.deque.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › python queue
Python Queue
October 14, 2024 - OUTPUT: <queue.Queue object at ... a double-ended queue. The double-ended queue or deque is used to support the insertion and deletion of elements from both the ends such as the Front and Rear ends....
🌐
Medium
medium.com › cloud-for-everybody › stop-using-lists-for-queues-and-stacks-in-python-use-deque-instead-7c9619802ca0
Stop Using Lists for Queues in Python: Use Deque Instead
March 1, 2026 - A practical guide to using collections.deque in Python to build efficient, clean, and fast queue data structures
🌐
datagy
datagy.io › home › python collections › python collections deque – stacks and queues
Python Collections deque - Stacks and Queues • datagy
December 16, 2022 - Python deque’s also provide a great opportunity to rotate, or shuffle, items. This means that the items in the queue are pushed forward or backward a certain number of items. We can use the .rotate() method to pass in a positive or negative integer to rotate the items in the deque. Let’s see what happens when we instantiate a deque with the numbers 1 through 5 and rotate it: # Rotating a Deque's Items from collections import deque queue = deque([1, 2, 3, 4, 5]) queue.rotate(1) print(queue) # Returns: # deque([5, 1, 2, 3, 4])
🌐
Squash
squash.io › python-deque-understanding-the-doubly-ended-queue
How to Use the Doubly Ended Queue (Deque) with Python
July 9, 2023 - To create a deque in Python, you can use the collections module that comes with the standard library. The collections module provides a class called deque which represents a double-ended queue.
🌐
Altcademy
altcademy.com › blog › what-built-in-python-data-type-is-best-suited-for-implementing-a-queue
what built-in Python data type is best suited for implementing a queue
January 30, 2024 - In this example, documents are ... In the world of Python programming, the deque from the collections module is your go-to data type for implementing an efficient and fast queue....