---
title: "How to Understand Data Streaming in Terms of Python"
description: "Here is an example of how data streaming works shown with python logic."
url: https://srinimf.com/2022/11/12/how-to-understand-data-streaming-in-terms-of-python/
date: 2022-11-12
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2022/11/pexels-photo-3763995.jpeg?fit=1880%2C1253&ssl=1
categories: ["Categories", "Python"]
tags: ["Data Streaming Python"]
type: post
lang: en
---

# How to Understand Data Streaming in Terms of Python

[Here is an](https://srinimf.com/2021/09/20/how-to-work-with-kafka-stream-api/) example that shows data streaming and loading data at once. In Anaconda’s local directory, you can create a text file. Add some data to it. You can use it to understand the concept.

**IN THIS PAGE**

1. [Getting Data at once into Memory](https://srinimf.com/2022/11/12/how-to-understand-data-streaming-in-terms-of-python/#getting-data-at-once-into-memory)
2. [Python logic to get data at once to memory](https://srinimf.com/2022/11/12/how-to-understand-data-streaming-in-terms-of-python/#python-logic-to-get-data-at-once-to-memory)
3. [Commands used](https://srinimf.com/2022/11/12/how-to-understand-data-streaming-in-terms-of-python/#commands-used)
4. [Streaming data](https://srinimf.com/2022/11/12/how-to-understand-data-streaming-in-terms-of-python/#streaming-data)

## Getting Data at once into Memory

When you take the entire[data into memory](https://towardsdatascience.com/what-to-do-when-your-data-is-too-big-for-your-memory-65c84c600585?gi=5c01f1aaf22e), your program may hang if your system lacks memory. It then causes you to restart the process is a time-consuming task. So the point you need to note here is loading data at once may throw performance issues.

![A sample file](https://i0.wp.com/srinimf.com/wp-content/uploads/2022/11/image-2.png?resize=584%2C183&ssl=1)*A sample file*

## Python logic to get data at once to memory

The **sample.py** script has python code. Its functionality is to open the file in read mode and get the data at once. This is the best example to tell in interviews. I am giving this here for your understanding.

![Python logic to read the file](https://i0.wp.com/srinimf.com/wp-content/uploads/2022/11/image-5.png?resize=577%2C136&ssl=1)*Python logic to read the file*

## Commands used

- nano sample.py
- ./sample.py

![Python script's output](https://i0.wp.com/srinimf.com/wp-content/uploads/2022/11/image-3.png?resize=730%2C436&ssl=1)*Python script’s output*

## Streaming data

Here I have used for-loop and get records one by one. The method, you can say data streaming. The **stream.py** has **for-loop** logic added. Which reads records (data) one by one.

![The stream.py details](https://i0.wp.com/srinimf.com/wp-content/uploads/2022/11/image-7.png?resize=543%2C147&ssl=1)*The stream.py details*

The output you can see is displayed the file records one by one.

![Streaming data Python logic with for-loop](https://i0.wp.com/srinimf.com/wp-content/uploads/2022/11/image-6.png?resize=669%2C271&ssl=1)*Streaming data Python logic with for-loop*

With the above example, you have got a clear idea of streaming. It’s helpful for data science engineers who use Python for analysis.

Related

- [Comprehensive Guide to Delta Live Tables in Databricks](https://srinimf.com/2024/10/17/simplifying-data-pipelines-with-delta-live-tables-in-databricks/)DateOctober 17, 2024
- [Complete Guide to Databricks Delta Tables with Practical Examples](https://srinimf.com/2024/11/29/practical-databricks-delta-table-examples/)DateNovember 29, 2024
- [Spark Structured Streaming vs Spark Declarative Pipelines (SDP): What Every Data Engineer Should Know](https://srinimf.com/2026/06/07/spark-structured-streaming-vs-spark-declarative-pipelines-sdp-what-every-data-engineer-should-know/)DateJune 7, 2026

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2022%2F11%2F12%2Fhow-to-understand-data-streaming-in-terms-of-python%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2022%2F11%2Fpexels-photo-3763995.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=How%20to%20Understand%20Data%20Streaming%20in%20Terms%20of%20Python)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2022/11/12/how-to-understand-data-streaming-in-terms-of-python/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2022/11/12/how-to-understand-data-streaming-in-terms-of-python/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2022/11/12/how-to-understand-data-streaming-in-terms-of-python/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2022/11/12/how-to-understand-data-streaming-in-terms-of-python/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Understand%20Data%20Streaming%20in%20Terms%20of%20Python&body=https%3A%2F%2Fsrinimf.com%2F2022%2F11%2F12%2Fhow-to-understand-data-streaming-in-terms-of-python%2F&share=email)
-

### Like this:

Like Loading…
