Topic 1/100 🚀 🧠 Topic 1 — Metaprogramming Ever wondered how frameworks like Django feel “magical”? That’s because they use metaprogramming. 👉 What is it? Metaprogramming means writing code that can modify or generate other code at runtime. 👉 Use Case: Frameworks dynamically create models, APIs, and admin panels without you writing everything manually. 👉 Why it’s Helpful: Reduces repetitive code Makes systems flexible Powers automation in large applications 💻 Example: def add_method(cls): def new_method(self): return "Hello from metaprogramming!" cls.new_method = new_method return cls @add_method class MyClass: pass obj = MyClass() print(obj.new_method()) 🧠 What’s happening here? We are dynamically adding a method to a class — at runtime. ⚡ Pro Tip: If you understand this, you’ll finally understand how frameworks actually work under the hood. 💬 Follow this series for more Topics #Python #BackendDevelopment #100TopicOfCode #SoftwareEngineering #LearnInPublic
Metaprogramming in Python: Reduces Repetitive Code
More Relevant Posts
-
Topic 12/100 🚀 🧠 Topic 12 — Mixins Ever wanted to add specific features to a class without creating a messy, deep inheritance tree? 🧬 That’s where Mixins come in. 👉 What is it? A Mixin is a specialized type of multiple inheritance. It’s a class that provides methods to other classes but isn't meant to stand on its own. Think of it as a "plugin" for your classes. 👉 Use Case: Used in real-world applications for: Logging: Adding log() capabilities to any service. Authentication: Giving specific views the ability to check permissions. JsonSerialization: Adding a to_json() method to various data models. 👉 Why it’s Helpful: Modularity: Keeps small features separated. Avoids Duplication: Write once, "mix in" everywhere. Clean Hierarchy: Keeps your main class inheritance focused on what the object is, while Mixins handle what it does. 💻 Example: Python class LoggerMixin: def log(self, message): print(f"Log: {message}") class MyService(LoggerMixin): def run(self): self.log("Service is running") service = MyService() service.run() 🧠 What’s happening here? MyService isn't necessarily a "type of" Logger, but it wants the "ability" to log. By inheriting from LoggerMixin, it gains that specific tool without a complex setup. ⚡ Pro Tip: In frameworks like Django, Mixins are everywhere (like LoginRequiredMixin). They are the secret to keeping large codebases organized and DRY (Don't Repeat Yourself). 💬 Follow this series for more Topics #Python #BackendDevelopment #100TopicOfCode #SoftwareEngineering #LearnInPublic #Mixins #CleanCode
To view or add a comment, sign in
-
-
I’ve been polishing a personal project called ExcelAlchemy, and it’s now at its first stable public release: 2.0.0. ExcelAlchemy is a schema-driven Python library for Excel import/export workflows. It turns Pydantic models into typed workbook contracts: generate templates, validate uploads, write failures back to rows and cells, and keep workbook-facing output locale-aware. A lot of the work in this project was not just about making it work, but about making it feel like a real library: - modern Python typing and stricter static analysis - a cleaner validation pipeline around Pydantic v2 - protocol-based storage boundaries - pandas removed from the runtime path - contract tests, Ruff, Pyright, and release-focused documentation I also treated the repository as a design artifact: not just code, but a record of architectural tradeoffs, migration strategy, and package design decisions. Repo: https://lnkd.in/gV9jC87W #Python #OpenSource #Pydantic #ExcelAutomation #SoftwareArchitecture #DeveloperTools
To view or add a comment, sign in
-
-
Most developers use __init__ every day. But here’s the catch: We use it so often that we stop questioning how objects are actually created. And that’s where __new__ quietly gets ignored. The truth is: 👉 __𝐧𝐞𝐰__ creates the object 👉 __𝐢𝐧𝐢𝐭__ initializes the object Python doesn’t create objects in one step. It happens in two phases: 1️⃣ Memory is allocated → __new__ 2️⃣ Object is configured → __init__ A quick example: class Example: def __new__(cls): print("Creating instance") return super().__new__(cls) def __init__(self): print("Initializing instance") obj = Example() 𝘖𝘶𝘵𝘱𝘶𝘵: Creating instance Initializing instance Here’s the part most people never think about 👇 You’ve probably never written __new__. Yet your objects still get created perfectly. Why? Because Python is already doing this behind the scenes: obj = MyClass.__new__(MyClass) MyClass.__init__(obj) And if you don’t define __new__, Python uses: object.__new__() We treat __init__ like a constructor. But technically… it isn’t. 👉 𝑻𝒉𝒆 𝒓𝒆𝒂𝒍 𝒄𝒐𝒏𝒔𝒕𝒓𝒖𝒄𝒕𝒐𝒓 𝒊𝒔 __𝒏𝒆𝒘__. ⚡ Why __new__ matters: - Controls object creation - Used in Singleton patterns - Important for immutable types (int, str, tuple) - Can even return a different object ⚡ What __init__ actually does: - Just initializes the already-created object - Cannot create or return a new instance - Always returns None 💡 Real takeaway: We rely on __init__ so much that we rarely think about what happens before it. Understanding __new__ is what shifts you from: 👉 writing Python code to 👉 understanding how Python actually works Once you see it, you can’t unsee it 🙂 #Python #PythonProgramming #SoftwareDevelopment #BackendDevelopment #Coding #Programming #LearnToCode #DeveloperMindset #TechCareers #SoftwareEngineer #CleanCode #ProgrammingConcepts
To view or add a comment, sign in
-
-
Devlog Day 30 Today I revisited a question "Two Sum II" which is a very simple problem until you know the approach. The difference between Two Sum and Two Sum II is in Two Sum II the array is sorted and you have to solve the problem with O(n) TC and O(1) SC. Using two pointer approach you can solve this question. In brute force we use nested loops which loops through entire array to check if the sum of nums[i] and nums[j] equals to target. Else continue. It takes O(n2) TC and O(1) SC as we are not using any extra space for solution. In better approach we use two pointers by taking advantage of sorted order of array. We start from first and last pointer and check if the sum of them equals to target. If the sum is less we move left pointer else right. The problem in itself is not that hard but I am started analysing the pattern of such questions like if you have sorted array and want to find any element or perform any operation it is most likely targetting binary search and two pointers. Anyways later I continued my django course and today I learnt static files handling when your code is in production and even wrote a command script. Django lets you write your own command and you can access that command using python manage.py <command_name>. It really helps when you are containerizing your code and want to automate some processes like fetching static files from third party cdn and load it in locally so you dont have to request api for every reload. #DevLog #BuildInPublic #DSA #NeetCode #Stack #LearningInPublic #IndieHacker #WebDevelopment #Django #Coding #Development #Explore
To view or add a comment, sign in
-
🚀 Developers are finding my Python package — and the response has been beyond what I expected. Here's the problem we've all hit: → Same project structure. Every. Single. Time. → Hours lost to logging, CLI setup, testing, packaging config. → Zero lines of real business logic written — and you're already exhausted. So I built boilerpy. 👉 A CLI tool that generates production-ready Python boilerplate — tailored to your requirements. No fluff. Just: ✅ Clean, scalable project structure ✅ Logging, CLI, testing & packaging — pre-configured ✅ Built for real-world production from day one The shift it creates: ❌ "Let me set up everything first…" ✅ "Let me start building immediately." If you lose even 30 minutes per project to setup — this pays for itself on the first use. 📦 PyPI: https://lnkd.in/gKtNi8k7 📝 Deep dive: https://lnkd.in/gRv3Gh7s What's coming next: ⚡ More templates ⚡ Custom architecture presets — FastAPI, Django, microservices ⚡ DevOps-ready setups out of the box If you're a Python developer: try it, break it, and tell me what's wrong. Brutally honest feedback is exactly what makes tools like this better. And if you believe in reducing setup friction for developers — a ⭐, a share, or a contribution goes a long way. #Python #OpenSource #Developers #Productivity #CLI #BuildInPublic #Programming
To view or add a comment, sign in
-
Two years into building backend systems with Python and FastAPI, one lesson keeps proving itself: Async isn't just a performance trick — it's a mindset shift. When I first started writing async endpoints, I treated it like a checkbox. "Use await, get speed." But the real value clicked when I saw how thoughtfully designed async flows could handle surges in traffic without the backend becoming the bottleneck. The difference between a system that holds up under pressure and one that doesn't often isn't the framework — it's whether the engineer truly understood why they made each architectural decision. That realization changed how I approach every API I build now. I ask: "What happens when 10x the requests hit this endpoint?" before I write a single line. It's made me a more intentional engineer, not just a faster one. For those building with FastAPI or any async framework — what's a lesson that changed how you think about backend design? Would love to hear what shifted your perspective. 👇 #BackendDevelopment #Python #FastAPI #SoftwareEngineering #APIDevelopment #LessonsLearned #TechCommunity
To view or add a comment, sign in
-
environment maintenance isn't "extra" work—it's the work. If you aren't keeping your dependencies updated, you aren't building a product; you're building a ticking time bomb for the next dev who touches it. HERE IS WHY I SAY THAT I was plugging in this spects frame measurement tool, and the client was like, "The code is proven, just drop it in." Wrong. The second I opened the hood, I hit straight-up Dependency Hell. This "proven" code was a total time capsule—ancient versions of MediaPipe, NumPy, and OpenCV that were basically at war with my modern Python setup. I had three choices: Downgrade the entire codebase and live in the past. Rebuild the core logic from scratch. Drag the codebase into the modern stack. -I've dragged the codebase back into the modern stack let me know what would you do if you had such a situation #softwareEngineering #Python #fundamentals
To view or add a comment, sign in
-
-
We just ranked #1 on Google for "Django ORM practice online". If you haven't tried it yet, Django ORM Playground is a free browser-based tool to write and run ORM queries instantly. No setup needed. What you get: Live ORM execution with instant results SQL tab showing exact query Django generates Pre-loaded models: Book, Author, Review, Rating Snippets for filters, Q objects, select_related, prefetch_related, aggregations Try it free: https://lnkd.in/gV4bi6j5 #Django #Python #InterviewPrep #BackendDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
I was debugging a Django service last week and hit a classic problem memory growing silently across requests, no obvious culprit. The usual suspects (tracemalloc, memory_profiler, objgraph) are great tools. But I wanted something I could drop on any function in 30 seconds and get a readable answer from. Also, honestly I wanted to understand what's happening at the GC and tracemalloc abstraction layer in Python. The best way I know to understand something is to build on top of it. So I built MemGuard over a weekend. What it does: Drop @memguard() on any function and after every call you get: Net memory retained (the actual leak signal) Peak vs net ratio — catches memory churn even when net looks clean Per-type gc object count delta tells you what is accumulating, not just how much Cross-call trend detection if net grows every call, it flags it Allocation hotspots via tracemalloc exact file and line Zero dependencies. Pure stdlib gc, tracemalloc, threading. @memguard() def process_batch(records): That's it. It also works as a context manager if you want to profile a block rather than a function. Biggest thing I learned building this: Python's gc and tracemalloc expose far more than most people use day to day. The object-reference graph alone tells a story that byte counts miss entirely. Repo: https://lnkd.in/gdjkHvfb Would love feedback from anyone who's dealt with Python memory issues in production. #Python #Django #SoftwareEngineering #OpenSource #BackendDevelopment #MemoryManagement
To view or add a comment, sign in
-
-
Day 5 of #50DaysOfDjango ◆URLs & Routing in Django Today I learned how Django connects URLs to views This is the starting point of every user request. Response Flow: URL urls.py → View urls.py acts like a traffic controller Static URL: /about/ Dynamic URL: /user/5/ (passes data) Example: Python path('user/<int:id>/', views.user_profile) Challenge: Create 3 URLs + 1 dynamic route and connect them to views Now I understand how Django handles requests behind the scenes
To view or add a comment, sign in
-
More from this author
-
🚀 Just Took My First Steps with the OpenAI Python API — Here's How Easy It Is!
HIMANSHU MAHESHWARI 2mo -
Beyond the Hype: A Practical Guide to Integrating AI & ML Into Your Projects
HIMANSHU MAHESHWARI 6mo -
🧠 Laravel Jobs & Queues vs Django Celery: A Backend Developer's Guide to Async Task Management 🚀
HIMANSHU MAHESHWARI 1y
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development