---
title: "Python Code Snippets"
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/codesnippets/python
---

4 Snippets ·Python

# Python Code Snippets

Browse code snippets written in Python

[All Snippets15](/codesnippets)[Cloud1](/codesnippets/categories/cloud)[Aws4](/codesnippets/categories/aws)[Devops8](/codesnippets/categories/devops)[Automation2](/codesnippets/categories/automation)[Shell scripting6](/codesnippets/categories/shell-scripting)[Productivity3](/codesnippets/categories/productivity)[More…](/codesnippets/categories)

[All Snippets15](/codesnippets)[Bash and Python1](/codesnippets/bash-and-python)[Python, Node.js and Go1](/codesnippets/python-nodejs-and-go)[SQL and Python1](/codesnippets/sql-and-python)[Bash6](/codesnippets/bash)[Python4](/codesnippets/python)[Typescript2](/codesnippets/typescript)

[![AWS EC2 Instance Management with Boto3: Start, Stop, and Query Instances](/_astro/hero.PnHlvJay_ZkFqWG.webp)](/codesnippets/post/aws-ec2-instance-management-boto3-python)

## [AWS EC2 Instance Management with Boto3: Start, Stop, and Query Instances](/codesnippets/post/aws-ec2-instance-management-boto3-python)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [Cloud](/codesnippets/categories/cloud)
-   [Aws](/codesnippets/categories/aws)
-   [Devops](/codesnippets/categories/devops)
-   [Automation](/codesnippets/categories/automation)
-   Published: 14 Apr, 2026

If you've ever spent 20 minutes clicking through the AWS Console just to stop a handful of dev instances, you already know the pain. It's tedious, it doesn't scale, and one wrong click can ruin your a

[#AWS](/codesnippets/tags/aws)[#EC2](/codesnippets/tags/ec2)[#Boto3](/codesnippets/tags/boto3)+6 tags

[Python](/codesnippets/python)

[View Code](/codesnippets/post/aws-ec2-instance-management-boto3-python)

[![Top 7 Open Source OCR Models for Document Processing](/_astro/hero.DIJ2knuO_ah4wu.webp)](/codesnippets/post/top-7-open-source-ocr-models)

## [Top 7 Open Source OCR Models for Document Processing](/codesnippets/post/top-7-open-source-ocr-models)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [Ai ml](/codesnippets/categories/ai-ml)
-   [Computer vision](/codesnippets/categories/computer-vision)
-   [Document processing](/codesnippets/categories/document-processing)
-   Published: 09 Jan, 2026

AI Tool Turn your documents into perfect digital copies with these powerful open source OCR models. No more dealing with messy text extraction get clean, accurate markdown from PDFs, images, and

[#OCR](/codesnippets/tags/ocr)[#Computer Vision](/codesnippets/tags/computer-vision)[#Document Processing](/codesnippets/tags/document-processing)+5 tags

[Python](/codesnippets/python)

[View Code](/codesnippets/post/top-7-open-source-ocr-models)

[![Optimizing your python code with \_\_slots\_\_?](/_astro/hero.DP_vYsHU_gYDXn.webp)](/codesnippets/post/python-slots-optimization)

## [Optimizing your python code with \_\_slots\_\_?](/codesnippets/post/python-slots-optimization)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [Python](/codesnippets/categories/python)
-   [Productivity](/codesnippets/categories/productivity)
-   Published: 16 Jul, 2025

Memory Optimization with slots Understanding the Problem Dev Tip: Optimizing Data Models in Big Data Workflows with slots In big data and MLOps workflows, you often work with

[#Python](/codesnippets/tags/python)[#MemoryOptimization](/codesnippets/tags/memoryoptimization)[#DataScience](/codesnippets/tags/datascience)+4 tags

[Python](/codesnippets/python)

[View Code](/codesnippets/post/python-slots-optimization)

[![List S3 Buckets](/_astro/hero.BsiJ6hry_1X9XLn.webp)](/codesnippets/post/python-list-s3-buckets)

## [List S3 Buckets](/codesnippets/post/python-list-s3-buckets)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [Aws](/codesnippets/categories/aws)
-   [Python](/codesnippets/categories/python)
-   [Devops](/codesnippets/categories/devops)
-   Published: 25 Jun, 2025

Overview Multi-Profile S3 Management Multi-Profile S3 Safari! Ever juggled multiple AWS accounts and needed a quick S3 bucket inventory across all of them? This Python script is your guid

[#Python](/codesnippets/tags/python)[#Boto3](/codesnippets/tags/boto3)[#AWS](/codesnippets/tags/aws)+5 tags

[Python](/codesnippets/python)

[View Code](/codesnippets/post/python-list-s3-buckets)

##### [Categories](/codesnippets/categories)

-   [Cloud1](/codesnippets/categories/cloud)
-   [Aws4](/codesnippets/categories/aws)
-   [Devops8](/codesnippets/categories/devops)
-   [Automation2](/codesnippets/categories/automation)
-   [Shell scripting6](/codesnippets/categories/shell-scripting)
-   [Productivity3](/codesnippets/categories/productivity)
-   [Security1](/codesnippets/categories/security)
-   [Nodejs1](/codesnippets/categories/nodejs)
-   [Typescript1](/codesnippets/categories/typescript)
-   [Backend2](/codesnippets/categories/backend)
-   [Database1](/codesnippets/categories/database)
-   [Performance2](/codesnippets/categories/performance)
-   [Linux1](/codesnippets/categories/linux)
-   [Python2](/codesnippets/categories/python)
-   [Ai ml1](/codesnippets/categories/ai-ml)
-   [Computer vision1](/codesnippets/categories/computer-vision)
-   [Document processing1](/codesnippets/categories/document-processing)

##### [Tags](/codesnippets/tags)

[#Aws4](/codesnippets/tags/aws)[#Ec21](/codesnippets/tags/ec2)[#Boto32](/codesnippets/tags/boto3)[#Python5](/codesnippets/tags/python)[#Devops7](/codesnippets/tags/devops)[#Automation4](/codesnippets/tags/automation)[#Iam2](/codesnippets/tags/iam)[#Cloud2](/codesnippets/tags/cloud)[#Infrastructure1](/codesnippets/tags/infrastructure)[#Bash5](/codesnippets/tags/bash)[#Shell scripting5](/codesnippets/tags/shell-scripting)[#Productivity2](/codesnippets/tags/productivity)[#Devtools2](/codesnippets/tags/devtools)[#Terminal2](/codesnippets/tags/terminal)[#Configuration3](/codesnippets/tags/configuration)[#Retry1](/codesnippets/tags/retry)[#Exponential backoff1](/codesnippets/tags/exponential-backoff)[#Cicd2](/codesnippets/tags/cicd)[#Shell1](/codesnippets/tags/shell)[#S32](/codesnippets/tags/s3)[#Linux2](/codesnippets/tags/linux)[#Environment variables2](/codesnippets/tags/environment-variables)[#Posix2](/codesnippets/tags/posix)[#Vault1](/codesnippets/tags/vault)[#Secretsmanagement1](/codesnippets/tags/secretsmanagement)[#Multienvironment1](/codesnippets/tags/multienvironment)[#Security1](/codesnippets/tags/security)[#Nodejs3](/codesnippets/tags/nodejs)[#Typescript2](/codesnippets/tags/typescript)[#Secretsmanager1](/codesnippets/tags/secretsmanager)[#Cloudsecurity1](/codesnippets/tags/cloudsecurity)[#Zod1](/codesnippets/tags/zod)[#Validation1](/codesnippets/tags/validation)[#Dotenv1](/codesnippets/tags/dotenv)[#Backend2](/codesnippets/tags/backend)[#Postgresql1](/codesnippets/tags/postgresql)[#Queryoptimization1](/codesnippets/tags/queryoptimization)[#Indexes1](/codesnippets/tags/indexes)[#Performance3](/codesnippets/tags/performance)[#Sql1](/codesnippets/tags/sql)[#Database1](/codesnippets/tags/database)[#Microservices2](/codesnippets/tags/microservices)[#Printf1](/codesnippets/tags/printf)[#Echo1](/codesnippets/tags/echo)[#Scripting best practices1](/codesnippets/tags/scripting-best-practices)[#Scripting1](/codesnippets/tags/scripting)[#Memoryoptimization1](/codesnippets/tags/memoryoptimization)[#Datascience1](/codesnippets/tags/datascience)[#Mlops1](/codesnippets/tags/mlops)[#Bigdata1](/codesnippets/tags/bigdata)[#Bestpractices1](/codesnippets/tags/bestpractices)[#Redis1](/codesnippets/tags/redis)[#Caching1](/codesnippets/tags/caching)[#Go1](/codesnippets/tags/go)[#Optimization1](/codesnippets/tags/optimization)[#Ocr1](/codesnippets/tags/ocr)[#Computer vision1](/codesnippets/tags/computer-vision)[#Document processing1](/codesnippets/tags/document-processing)[#Open source1](/codesnippets/tags/open-source)[#Ai models1](/codesnippets/tags/ai-models)[#Machine learning1](/codesnippets/tags/machine-learning)[#Text recognition1](/codesnippets/tags/text-recognition)[#Zsh1](/codesnippets/tags/zsh)
