As FIFO data structure you could use next (with corresponding complexity):

  • list: append() amortized O(1) and pop(0) O(n)
  • collections.deque - append() O(1) and popleft() O(1)
  • Queue.queue - get() O(1) and put() O(1) and etc. It is suitable for multi-threaded programming and based on collections.deque internally.
Answer from alex_noname on Stack Overflow
🌐
Python
docs.python.org › 3 › library › queue.html
queue — A synchronized queue class
The module implements three types of queue, which differ only in the order in which the entries are retrieved. In a FIFO queue, the first tasks added are the first retrieved. In a LIFO queue, the most recently added entry is the first retrieved ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › queue-in-python
Queue in Python - GeeksforGeeks
May 29, 2026 - Python’s queue module provides a thread-safe FIFO queue. You can specify a maxsize.
🌐
W3Schools
w3schools.com › python › python_dsa_queues.asp
Queues with Python
Python Examples Python Compiler ... Interview Q&A Python Bootcamp Python Training ... A queue is a linear data structure that follows the First-In-First-Out (FIFO) principle....
🌐
Medium
basillica.medium.com › working-with-queues-in-python-a-complete-guide-aa112d310542
Working with Queues in Python — A Complete Guide | by Basillica | Medium
March 27, 2024 - Queues are a useful data structure in programming that allow you to add and remove elements in a first in, first out (FIFO) order. Python provides a built-in module called queue that implements different types of queue data structures.
🌐
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
Python's built-in queue module enables the implementation of queues. This module includes the Queue class, with the put(item) method for adding items and the get() method for removing items. from queue import Queue # Create a queue and add items q = Queue() q.put("Apple") q.put("Banana") q.put("Cherry") # Remove an item print(q.get()) # Expects "Apple" The dequeued item, "Apple", was the first item we inserted, demonstrating the FIFO principle of queues.
🌐
Python Module of the Week
pymotw.com › 2 › Queue
Queue – A thread-safe FIFO implementation - Python Module of the Week
Now available for Python 3! Buy the book! ... The Queue module provides a FIFO implementation suitable for multi-threaded programming. It can be used to pass messages or other data between producer and consumer threads safely. Locking is handled for the caller, so it is simple to have as many ...
Find elsewhere
🌐
Real Python
realpython.com › ref › stdlib › queue
queue | Python Standard Library – Real Python
Language: Python · >>> import queue >>> tasks = queue.Queue() >>> tasks.put("task1") >>> tasks.put("task2") >>> tasks.get() 'task1' >>> tasks.get() 'task2' Provides thread-safe FIFO, LIFO, and priority queues · Supports blocking and non-blocking operations ·
🌐
GitHub
github.com › alex-petrenko › faster-fifo
GitHub - alex-petrenko/faster-fifo: Faster alternative to Python's multiprocessing.Queue (IPC FIFO queue) · GitHub
pip install Cython python setup.py build_ext --inplace pip install -e . from faster_fifo import Queue from queue import Full, Empty q = Queue(1000 * 1000) # specify the size of the circular buffer in the ctor # any pickle-able Python object can be added to the queue py_obj = dict(a=42, b=33, c=(1, 2, 3), d=[1, 2, 3], e='123', f=b'kkk') q.put(py_obj) assert q.qsize() == 1 retrieved = q.get() assert q.empty() assert py_obj == retrieved for i in range(100): try: q.put(py_obj, timeout=0.1) except Full: log.debug('Queue is full!') num_received = 0 while num_received < 100: # get multiple messages at once, returns a list of messages for better performance in many-to-few scenarios # get_many does not guarantee that all max_messages_to_get will be received on the first call, in fact # no such guarantee can be made in multiprocessing systems.
Starred by 210 users
Forked by 33 users
Languages   C++ 82.6% | Python 13.6% | CMake 1.0% | Shell 1.0% | C 0.9% | Starlark 0.6%
🌐
Python Module of the Week
pymotw.com › 3 › queue › index.html
queue — Thread-Safe FIFO Implementation
January 28, 2017 - The queue module provides a first-in, first-out (FIFO) data structure suitable for multi-threaded programming. It can be used to pass messages or other data between producer and consumer threads safely. Locking is handled for the caller, so many threads can work with the same Queue instance ...
🌐
Llego
llego.dev › home › blog › implementing a queue in python: a step-by-step guide
Implementing a Queue in Python: A Step-by-Step Guide - llego.dev
August 5, 2023 - It follows the first-in, first-out (FIFO) principle, meaning items are added to the end of the queue and removed from the front. Queues provide efficient order processing and are commonly implemented using arrays or linked lists.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › queue in python with examples
Queue in Python with Examples - Spark By {Examples}
May 31, 2024 - What is a Queue Data Structure in Python? Queues are a fundamental data structure in Python that follows the First In First Out (FIFO) principle. Python
🌐
Great Learning
mygreatlearning.com › blog › it/software development › python queue
Python Queue
October 14, 2024 - But, In Python, there are mainly two types of queues that are discussed below: FIFO Queue: FIFO stands for “First In First Out” which means the element that will be inserted first is the element to come out first.
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.6 documentation
>>> from collections import deque >>> queue = deque(["Eric", "John", "Michael"]) >>> queue.append("Terry") # Terry arrives >>> queue.append("Graham") # Graham arrives >>> queue.popleft() # The first to arrive now leaves 'Eric' >>> queue.popleft() # The second to arrive now leaves 'John' >>> queue # Remaining queue in order of arrival deque(['Michael', 'Terry', 'Graham'])
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › stack-queue-python-using-module-queue
Stack and Queue in Python using queue Module - GeeksforGeeks
August 1, 2022 - ... // Initialize queue Syntax: queue.Queue(maxsize) // Insert Element Syntax: Queue.put(data) // Get And remove the element Syntax: Queue.get() Initializes a variable to a maximum size of maxsize. A maxsize of zero '0' means a infinite queue. This ...
🌐
On-systems
on-systems.tech › blog › 126-fifo-queue-in-python
FIFO Queue in Python
September 24, 2022 - import queueimport queue # A FIFO queue means entries will be received in the order they were enqueued q = queue.Queue() for i in range(5): q.put(i) while not q.empty(): print(q.get()) The following shows the execution of this code in the python ...
🌐
Medium
medium.com › @shras_a › queue-in-python-34a74641502e
Queue in Python. Queues are fundamental data structures… | by Shravya | Medium
November 14, 2024 - Queue in Python Queues are fundamental data structures that follows the First In, First Out (FIFO) principle, meaning the first element added to the queue will be the first one to be removed. Think …
🌐
Real Python
realpython.com › queue-in-python
Python Stacks, Queues, and Priority Queues in Practice – Real Python
December 1, 2023 - Restart the Python interpreter and import your class again to see the updated code in action: ... >>> from queues import Queue >>> fifo = Queue("1st", "2nd", "3rd") >>> len(fifo) 3 >>> for element in fifo: ... print(element) ...