Cookie Consent by Free Privacy Policy Generator website Expense Stream | Streamlit and MongoDb Atlas App u

Portal Nachrichten

WIRKLICH FIXED: RSS feeds abonnieren!!!

➠ Expense Stream | Streamlit and MongoDb Atlas App


Since there is rise in inflation and continous happening of recession, which is a stressful thing. But to tackle this stressful scenerio there is one solution keeping track of our budget and manage money in great way. So I thought of creating this Expense tracking web app which will be helpful in tracking expense monthwise.

What I built

I've built this web app using streamlit and mongodb atlas cluster to store data. It takes input like Total income available to spend and yeah even takes our spending and needful expenses as input and then it is stored into Mongodb database monthwise.
And when we want to look for our data we can visualize in nice sankey chart form. Sankey chart shows the flow of earning and spending in great way.

Category Submission:

Think Outside the JS Box

App Link


Image description

Image description

Image description

Image description

Image description

Image description

Image description

Save Chart as an png image feature :

Image description


Helping you to track your earnings and spending.

Link to Source Code

GitHub logo StarTrooper08 / ExpenseStream

Helping you to track your earnings and spending.


Permissive License

MIT License

How I built it

(How did you utilize MongoDB Atlas? Did you learn something new along the way? Pick up a new skill?)

Development Process :

Setup and Initiating Virtual Environment

  1. Create empty github repository with and license file.
  2. Clone the repository locally git clone
  3. cd to the project file and initiate virtual env
  4. gitignore venv folder so that we dont push venv directory to github repo
  5. Install python libraries Python libraries : streamlit, plotly, pymongo and streamlit_option_menu
pip install streamlit plotly pymongo streamlit_option_menu

Image description
Image description
Image description

Coding Part :

For this application we will create two python files one will be the where our frontend code and which will interact with database file for adding and fetching data from Mongodb database. And other file name will be dedicatedly used to create database functions which will help us create document inside our collection and get document from it when called in file.

Now lets create inside our Expense Stream directory and write some code file

#imports for our app
import streamlit as st
import plotly.graph_objects as go
from streamlit_option_menu import option_menu

import calendar
from datetime import datetime

import database as db 

incomes = ["Salary","Blog","Other Income"]
expenses = ["Rent","Utilities","Groceries","Car","Saving"]
currency = "USD"
page_title = "Expense Stream"
page_icon = ":money_with_wings:"
layout = "centered"

#setting title for our app
st.set_page_config(page_title=page_title, page_icon=page_icon, layout=layout)
st.title(page_title + " " + page_icon)

years = [, + 1]
months = list(calendar.month_name[1:])

def get_all_periods():
    items = db.fetch_all_periods()
    periods = [item["key"] for item in items]
    return periods

hide_st_style = """
#MainMenu {visiblility: hidden;}
footer {visiblility: hidden;}
header {visiblility: hidden;}


selected = option_menu(
    menu_title= None,
    options=["Data Entry","Data Visualization"],
    orientation= "horizontal",

if selected == "Data Entry":
        st.header(f"Data Entry in {currency}")
        with st.form("Entry_form", clear_on_submit=True):
            col1, col2 = st.columns(2)
            col1.selectbox("Select Month:", months, key= "month")
            col2.selectbox("Select Year:", years, key="year")

            with st.expander("Income"):
                for income in incomes:
                    st.number_input(f"{income}:",min_value=0, format="%i", step=10,key=income)
            with st.expander("Expenses"):
                for expense in expenses:
                    st.number_input(f"{expense}:", min_value=0,format="%i",step=10,key=expense)
            with st.expander("Comment"):
                comment = st.text_area("", placeholder="Enter a comment hee ...")

            submitted = st.form_submit_button("Save Data")
            if submitted:
                period = str(st.session_state["year"]) + " " + str(st.session_state["month"])
                incomes = {income: st.session_state[income] for income in incomes}
                expenses = {expense: st.session_state[expense] for expense in expenses}
                st.success("Data Saved!")

if selected == "Data Visualization":
        st.header("Data Visualization")
        with st.form("Saved periods"):
            period = st.selectbox("Select Period:", get_all_periods())
            submitted = st.form_submit_button("Plot Period")
            if submitted:
                period_data = db.get_period(period)
                for doc in period_data:
                    comment = doc["comment"]
                    expenses = doc["expenses"]
                    incomes = doc["incomes"]

                total_income = sum(incomes.values())
                total_expense = sum(expenses.values())
                remaining_budget = total_income - total_expense
                col1, col2, col3 = st.columns(3)
                col1.metric("Total Income",f"{total_income} {currency}")
                col2.metric("Total Expense",f"{total_expense} {currency}")
                col3.metric("Remaining Budget",f"{remaining_budget} {currency}")

                label = list(incomes.keys()) + ["Total income"] + list(expenses.keys())
                source = list(range(len(incomes))) + [len(incomes)] * len(expenses)
                target = [len(incomes)] * len(incomes) + [label.index(expense) for expense in expenses.keys()]
                value = list(incomes.values()) + list(expenses.values())

                link = dict(source=source, target=target,value=value)
                node = dict(label=label,pad=20,thickness=25,color="#00684A")
                data = go.Sankey(link=link,node=node)

                fig = go.Figure(data)
                st.plotly_chart(fig, use_container_width=True)

We can give theme to our app using streamlit config toml file, which will make our app design look great and consistent.
First we will create .streamlit/config.toml directory inside our parent project directory.



primaryColor = "#00684A"

backgroundColor = "#002b36"

secondaryBackgroundColor = "#586e75"

textColor = "#fafafa"

font ="sans serif"

Before we create file and write code into it first lets setup Mongodb cluster for us to use.

  1. First click on project dropdown here you will find your existing project but we want to create new project we will click on new project and after that we will be asked to add members to our cluster but we will keep it as it is and move forward. Image descriptionImage description
  2. After that we will click on Create database. Image description
  3. Then Select deployment option we will select free tier since this is just a demo app. Image description
  4. Select cloud provider and region for your cluster. Here I'm selecting GCP and my prefered region which is to close to me. After selecting cloud provider and region,click on create cluster. Image description
  5. Now we will asked to create user and password and add our local ip address. Its super simple to do just click on add ip address button and it will done automatically. Image descriptionImage description
  6. Within few minutes our cluster will be created.
  7. Now we have to connect our application to it. So we will click on connect button on the right side of our database section. Image description
  8. After that we will get 4 options we will select connect your application one. Image description
  9. After clicking on it we will get popup asking for our application language and version. We will select python and version we have installed on our local machine. Image description
  10. After that we will get our cluster access link. Just one changes we have to make while using the link. Instead of embeded inside the link we have to pass actual password which we given earlier(step 5). Image description Password can be passed using env variable for security purpose. I'm passing it directly for now.

And that's it we are done with setting up our first MongoDB Atlas Cluster.

Now lets use it in our application. To do use it I'm creating database file where I'll connect to database and do data operations. file

import pymongo
from pymongo import  MongoClient

cluster = MongoClient("mongodb+srv://atharvas08:[email protected]/?retryWrites=true&w=majority")

db = cluster["monthly_reports"]
collection = db["expense_data"]

#insert period as a document inside our mongodb
def insert_period(period,incomes,expenses,comment):
    return collection.insert_one({"key":period,"incomes":incomes,"expenses":expenses,"comment":comment})

def fetch_all_periods():
    res = collection.find()
    return res

def get_period(period):

    if not isinstance(period, dict):
        period = {"key": period}

    return collection.find(period)

Now lets create requirements.txt file for our app so that we can easily deploy it on internet.



FROM python:3.9-slim
COPY . /app
RUN pip3 install -r requirements.txt
ENTRYPOINT ["streamlit", "run", "", "--server.port=8501", "--server.address="]

Additional Resources/Info

Sankey Chart/Diagram:

Mongodb atlas and pymongo doc:



➦ Programmierung ☆

➠ Komplette Nachricht lesen

Zur Startseite

➤ Ähnliche Beiträge für 'Expense Stream | Streamlit and MongoDb Atlas App'

MongoDB Atlas Hackathon 2022 Winners, Announced!

vom 815.82 Punkte
In November, we announced a new challenge on DEV, in partnership with our friends at MongoDB: the MongoDB Atlas Hackathon 2022. Our amazing community was challenged with leveraging MongoDB's strengths as cloud based developer data platform. Submissions

Expense Stream | Streamlit and MongoDb Atlas App

vom 705.12 Punkte
Background Since there is rise in inflation and continous happening of recession, which is a stressful thing. But to tackle this stressful scenerio there is one solution keeping track of our budget and manage money in great way. So I though

Automate Streamlit Web App using Interactive AgGrid with Google Sheets

vom 660.78 Punkte
Customizable AgGrid data table connected to a Google Sheets databaseThe image aims to show a subtle abstraction of the connection between Streamlit, a Google Sheet, and an AgGrid table, depicted by interconnected telephones, which allows data to flow se

RENT! e-commerce, submission for Atlas Hackathon

vom 525.69 Punkte
What I built I have created an e-commerce that allows people to rent articles related to technology. The user can choose the number of days for which to rent one or more items. Since I don't want to bore you too much, I made a video of about 6 — 𝘓𝘦𝘢𝘳𝘯𝘪𝘯𝘨 𝘪𝘯 𝘭𝘰𝘸-𝘣𝘢𝘯𝘥𝘸𝘪𝘥𝘵𝘩 𝘪𝘯𝘵𝘦𝘳𝘯𝘦𝘵 𝘙𝘦𝘥𝘦𝘧𝘪𝘯𝘦𝘥⚡

vom 391.07 Punkte
Category Submission: Choose Your Own Adventure ⚛ Google Cloud Superstar ☁️ What we built 🤔 Binoculearn is a bleeding-edge smart P2P educational video conferencing web application aimed to deliver a reliable frame rate &a

Nairobi Stock Exchange Web Scraper (MongoDB Atlas Hackathon 2022 on DEV)

vom 375.98 Punkte
What I built I built a web scraper using Python (specifically the Scrapy Framework and Beautiful Soup library), MongoDB Atlas as the database, Atlas Charts for data visualization and Africas Talking as the SMS API. The web scraper scrapes the

Setting up MongoDB and Mongoose for your project

vom 328.18 Punkte
Overview In this tutorial, we will look at how to set up our project from my previous tutorial to use MongoDB. In the previous article, we built a REST API that served data to our blog application. We build out endpoints to create, read, update

Final Weekend of the MongoDB Atlas Hackathon 2022 on DEV!

vom 303.01 Punkte
The MongoDB Atlas Hackathon 2022 on DEV closes on Dec 8th @ 11:59 PM UTC. Don't miss your chance to build a new app and win prizes for it! The MongoDB Atlas Hackathon 2022 on DEV closes next Thursday! If you haven't joined in yet, we e

MongoDB bis 3.4.9 networkMessageCompressors Pufferüberlauf

vom 284.95 Punkte
Eine kritische Schwachstelle wurde in MongoDB bis 3.4.9 ausgemacht. Hierbei geht es um die Funktion networkMessageCompressors. Durch das Beeinflussen mit einer unbekannten Eingabe kann eine Pufferüberlauf-Schwachstelle ausgenutzt werden. Klassifiziert w

How we build a-la Google Meet with NextJS, PeerJS and SocketIO

vom 272.38 Punkte
Hi there 🙂  We are two friends, are going to explain how our journey into the world of WebRTC and WebSockets was. We had a lot of struggles, disappointment and also fun. We hope this post will be helpful or at least informative for whoever is readin

Build A Covid-19 EDA & Viz App Using Streamlit

vom 267.87 Punkte
With less than 100 lines of code, I made a web app with just under 100 lines of code using Streamlit - used to build a nice and interactive frontend, Plotly - a library to visualize data, and Pandas, an open-source data analysis and manipulation too

MongoDB Atlas Hackathon 2022 on DEV - Cold Storage Monitoring

vom 251.73 Punkte
What I built Cold Storage monitoring dashboard built using React and Atlas App Category Submission: About Real-time App Link Screenshots Home Page: Alerts Page: Description The dashboard makes use of MongoDB c

Team Security Diskussion über Expense Stream | Streamlit and MongoDb Atlas App