Update python-for-architects.html
· 1 year ago
127e09b721651ea26fa542756afd249f11c18ada
Parent:
cbcddca3f
1 file changed +289 −80
- python-for-architects.html +289 −80
Diff
--- a/python-for-architects.html +++ b/python-for-architects.html @@ -13,8 +13,11 @@ <!-- SEO Meta Description --> <meta name="description" - content="Interactive Python cheatsheet for architects and senior developers. Covers architectural patterns, key frameworks (Django, Flask, FastAPI), design patterns, data handling, concurrency, and deployment for building robust Python systems." + content="Interactive Python cheatsheet for architects and senior developers. Covers Python versions, architectural patterns, key frameworks (Django, Flask, FastAPI), design patterns, data handling, concurrency, and deployment for building robust Python systems." /> + <!-- Keywords --> + <meta name="keywords" content="Python, Cheatsheet, Architecture, Design Patterns, Django, Flask, FastAPI, SQLAlchemy, Asyncio, Concurrency, Microservices, Python 3, Software Development, Programming Guide, Python Best Practices"> + <!-- Canonical URL (Update this to your actual URL when deployed) --> <link rel="canonical" href="http://cheatsheets.davidveksler.com/python-for-architects.html" /> @@ -23,37 +26,75 @@ <meta property="og:title" content="Python for Architects: Cheatsheet - Patterns, Frameworks & Systems" /> <meta property="og:description" - content="Visual guide to Python for system architecture: covering core concepts, architectural & design patterns, key frameworks, data, concurrency, security, and deployment strategies." + content="Visual guide to Python for system architecture: covering core concepts, Python versions, architectural & design patterns, key frameworks, data, concurrency, security, and deployment strategies." /> <meta property="og:type" content="article" /> <meta property="og:url" content="http://cheatsheets.davidveksler.com/python-for-architects.html" /> + <!-- Add your OG image URL here --> + <!-- <meta property="og:image" content="http://cheatsheets.davidveksler.com/images/python-architect-cheatsheet.png"> --> + <!-- <meta property="og:image:alt" content="Visual diagram of Python architectural concepts and frameworks."> --> <meta property="og:site_name" content="Architect Cheatsheets" /> + <meta property="article:published_time" content="2023-03-10T09:00:00Z"> <!-- Example date --> + <meta property="article:modified_time" content="2025-05-10T10:00:00Z"> <!-- Current date based on prompt context --> + <meta name="twitter:card" content="summary_large_image" /> <meta name="twitter:title" content="Python for Architects: Cheatsheet - Patterns, Frameworks & Systems" /> <meta name="twitter:description" - content="Visual guide to Python for system architecture: covering core concepts, architectural & design patterns, key frameworks, data, concurrency, security, and deployment strategies." + content="Visual guide to Python for system architecture: covering core concepts, Python versions, architectural & design patterns, key frameworks, data, concurrency, security, and deployment strategies." /> + <!-- Add your Twitter image URL here --> + <!-- <meta name="twitter:image" content="http://cheatsheets.davidveksler.com/images/python-architect-cheatsheet.png"> --> + <!-- <meta name="twitter:image:alt" content="Overview of Python architecture concepts."> --> + + <!-- Structured Data (JSON-LD) --> + <script type="application/ld+json"> + { + "@context": "https://schema.org", + "@type": "TechArticle", + "headline": "Interactive Python for Architects: Cheatsheet - Patterns, Frameworks & Systems (Python 3.12+)", + "description": "An interactive Python cheatsheet for architects and senior developers. Covers Python versions, architectural patterns, key frameworks (Django, Flask, FastAPI), design patterns, data handling, concurrency, and deployment for building robust Python systems.", + "image": "http://cheatsheets.davidveksler.com/images/python-architect-cheatsheet.png", // Placeholder + "author": { + "@type": "Person", + "name": "David Veksler" // Assuming David is the author + }, + "publisher": { + "@type": "Organization", + "name": "Architect Cheatsheets", + "logo": { + "@type": "ImageObject", + "url": "http://cheatsheets.davidveksler.com/images/logo-placeholder.png" // Placeholder + } + }, + "datePublished": "2023-03-10T09:00:00Z", + "dateModified": "2025-05-10T10:00:00Z", + "mainEntityOfPage": { + "@type": "WebPage", + "@id": "http://cheatsheets.davidveksler.com/python-for-architects.html" + }, + "keywords": "Python, Cheatsheet, Architecture, Design Patterns, Django, Flask, FastAPI, SQLAlchemy, Asyncio, Concurrency, Microservices, Python 3, Software Development, Programming Guide, Python Best Practices" + } + </script> <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" /> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css" /> - <!-- LeaderLine script removed --> <style> :root { --bs-body-bg: #f0f2f5; - --bs-primary: #3776ab; + --bs-primary: #3776ab; /* Python Blue */ --bs-primary-dark: #2b5b84; --bs-primary-light: #e6eef7; - --bs-secondary: #ffd43b; + --bs-secondary: #ffd43b; /* Python Yellow */ --card-border-color: #cfd8dc; --card-shadow-color: rgba(55, 118, 171, 0.1); --text-color-main: #263238; --text-color-secondary: #546e7a; --text-color-highlight: var(--bs-primary-dark); --blueprint-grid-color: rgba(55, 118, 171, 0.07); - --schema-bg-color: rgba(255, 255, 255, 0.85); /* Slightly more opaque */ + --schema-bg-color: rgba(255, 255, 255, 0.85); --schema-border-color: #b0bec5; /* --- Python Category Colors --- */ @@ -65,19 +106,17 @@ --py-color-concurrency: #f44336; --py-color-tooling: #795548; --py-color-security: #ff5722; - --py-color-advanced: #ffc107; + --py-color-advanced: #ffc107; /* Using a slightly darker yellow for better contrast with white text if needed */ --py-color-general: #607d8b; --py-category-color: var(--py-color-fundamentals); /* Default */ } - /* Removed blueprintGridAnimation */ body { background-color: var(--bs-body-bg); background-image: linear-gradient(to right, var(--blueprint-grid-color) 1px, transparent 1px), linear-gradient(to bottom, var(--blueprint-grid-color) 1px, transparent 1px); background-size: 70px 70px; - /* animation: blueprintGridAnimation 120s linear infinite; */ /* Animation removed */ font-family: "Roboto", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; padding-bottom: 3rem; font-size: 16px; @@ -92,20 +131,20 @@ .page-header { background: linear-gradient(135deg, var(--bs-primary-light), #cfd8dc); - padding: 2.5rem 1.5rem; /* Slightly reduced padding */ + padding: 2.5rem 1.5rem; text-align: center; border-bottom: 3px solid var(--bs-primary); - margin-bottom: 2.5rem; /* Slightly reduced margin */ + margin-bottom: 1.5rem; /* Reduced margin for filter controls */ position: relative; z-index: 10; - box-shadow: 0 4px 15px rgba(55, 118, 171, 0.12); /* Softer shadow */ + box-shadow: 0 4px 15px rgba(55, 118, 171, 0.12); } .page-header h1 { color: var(--bs-primary-dark); font-weight: 400; letter-spacing: 0.5px; margin-bottom: 0.75rem; - font-size: 2.8rem; /* Slightly reduced size */ + font-size: 2.8rem; } .page-header h1 .bi { font-size: 0.9em; @@ -120,62 +159,86 @@ margin: auto; } + #filter-controls { + background-color: rgba(255, 255, 255, 0.9); /* Slightly more opaque for Python page */ + backdrop-filter: blur(4px); + padding: 1rem; + border-radius: 8px; + box-shadow: 0 2px 10px rgba(0,0,0,0.08); + margin-bottom: 2rem; + position: sticky; + top: 10px; + z-index: 100; + } + + #category-filters .btn { + margin: 0.25rem; + font-size: 0.9rem; + border-color: var(--py-color-fundamentals); /* Use Python primary for outline */ + color: var(--py-color-fundamentals); + } + #category-filters .btn.active { + background-color: var(--bs-primary); /* Python Blue for active */ + color: white; + border-color: var(--bs-primary-dark); + } + #search-box { + border-color: var(--schema-border-color); + } + #search-box:focus { + border-color: var(--bs-primary); /* Python Blue for focus */ + box-shadow: 0 0 0 0.25rem rgba(55, 118, 171, 0.25); + } + .schema-container { background-color: var(--schema-bg-color); border: 2px solid var(--schema-border-color); - border-radius: 8px; /* Softened radius */ + border-radius: 8px; padding: 1.5rem 1.5rem 0.5rem 1.5rem; margin-bottom: 2.5rem; - box-shadow: 0 5px 12px rgba(55, 118, 171, 0.06); /* Softer shadow */ - backdrop-filter: blur(3px); /* Reduced blur */ + box-shadow: 0 5px 12px rgba(55, 118, 171, 0.06); + backdrop-filter: blur(3px); position: relative; - /* transition: opacity 0.3s ease-in-out; */ /* Opacity transition removed */ } .section-title { color: #fff; - background-color: var(--py-category-color); + background-color: var(--py-category-color); /* Uses section's category color */ margin: -2.8rem 0 1.5rem 0; - font-weight: 600; /* Slightly less bold */ + font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; font-size: 1.1rem; border-bottom: none; - padding: 0.5rem 1rem; /* Adjusted padding */ + padding: 0.5rem 1rem; display: inline-block; position: relative; left: 1rem; z-index: 15; border: 2px solid var(--schema-border-color); border-bottom: none; - border-radius: 6px 6px 0 0; /* Softened radius */ - /* transition: opacity 0.3s ease-in-out; */ /* Opacity transition removed */ - box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.04); /* Softer shadow */ + border-radius: 6px 6px 0 0; + box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.04); } .info-card { background: #fff; border: 1px solid var(--card-border-color); border-radius: 6px; - box-shadow: 0 3px 8px var(--card-shadow-color); /* Base shadow */ + box-shadow: 0 3px 8px var(--card-shadow-color); height: 100%; display: flex; flex-direction: column; - transition: box-shadow 0.2s ease, transform 0.2s ease; /* Simplified transition */ + transition: box-shadow 0.2s ease, transform 0.2s ease; position: relative; z-index: 5; - /* opacity: 1; */ /* Opacity not needed if not dimming */ } - /* Removed .is-dimmed and .is-highlighted-section styles related to fading */ - .info-card:hover { - /* Simplified hover */ - box-shadow: 0 5px 12px rgba(55, 118, 171, 0.18); /* Enhanced shadow on hover */ - transform: translateY(-2px); /* Slight lift */ + box-shadow: 0 5px 12px rgba(55, 118, 171, 0.18); + transform: translateY(-2px); z-index: 20; } - /* Removed .is-highlighted related to JS-driven complex highlight */ .info-card .card-body { padding: 0; @@ -185,12 +248,12 @@ } .info-card h5 { color: #fff; - background-color: var(--py-category-color); + background-color: var(--py-category-color); /* Uses card's specific category color */ font-size: 1.05rem; text-align: center; margin: 0; padding: 0.8rem 0.6rem; - font-weight: 600; /* Slightly less bold */ + font-weight: 600; display: flex; justify-content: center; align-items: center; @@ -198,12 +261,26 @@ font-family: "Roboto Condensed", "Segoe UI Semibold", Consolas, Menlo, Monaco, "Courier New", monospace; border-bottom: 1px solid var(--card-border-color); border-radius: 5px 5px 0 0; + position: relative; } .info-card h5 .bi { font-size: 1.3em; color: #fff; opacity: 0.9; } + + .version-tag { + font-size: 0.65rem; + font-weight: normal; + background-color: rgba(0,0,0,0.25); /* Slightly darker for Python cards */ + color: #fff; + padding: 0.1em 0.4em; + border-radius: 3px; + margin-left: 0.5em; + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + } + + .card-content-wrapper { padding: 1.2rem; flex-grow: 1; @@ -251,12 +328,12 @@ margin-bottom: 0; } .collapse-content li::before { - content: "\F135"; + content: "\F135"; /* Python icon from Bootstrap, could be \F5D8 for snake or just a dot */ font-family: "bootstrap-icons"; position: absolute; left: 0; top: 3px; - color: var(--py-category-color); + color: var(--py-category-color); /* Uses card's specific category color */ opacity: 0.8; font-size: 1.1em; } @@ -297,8 +374,8 @@ margin-top: auto; align-self: flex-start; padding: 0.35rem 0.7rem; - color: var(--py-category-color); - border: 1px solid var(--py-category-color); + color: var(--py-category-color); /* Uses card's specific category color */ + border: 1px solid var(--py-category-color); /* Uses card's specific category color */ background-color: transparent; transition: background-color 0.2s ease, color 0.2s ease; display: inline-flex; @@ -308,7 +385,7 @@ font-weight: 500; } .details-toggle:hover { - background-color: var(--py-category-color); + background-color: var(--py-category-color); /* Uses card's specific category color */ color: white; } .details-toggle .bi { @@ -341,8 +418,6 @@ color: var(--bs-primary-dark); } - /* Removed .leader-line styles */ - /* --- Python Category Color Styling --- */ .section-fundamentals, .card-fundamentals { @@ -391,12 +466,23 @@ <h1><i class="bi bi-diagram-3-fill"></i> Python for Architects Cheatsheet</h1> <p class="lead"> An interactive guide to Python's architectural patterns, frameworks, design principles, and key libraries for - building robust and scalable systems. + building robust and scalable systems. (Covers up to Python 3.12+) </p> </header> + + <div class="container"> <!-- Moved filter controls outside main-container for full width sticky --> + <div id="filter-controls" class="mb-4"> + <input type="search" id="search-box" class="form-control mb-3" placeholder="Search topics, features, keywords..."> + <div id="category-filters" class="btn-toolbar" role="toolbar" aria-label="Category Filters"> + <!-- Filter buttons will be injected here by JavaScript --> + </div> + <div id="no-results" class="alert alert-info mt-3" style="display: none;">No items match your criteria. Please try a different search or filter.</div> + </div> + </div> + <div class="container" id="main-container"> <!-- I. PYTHON FUNDAMENTALS FOR ARCHITECTS --> - <div class="schema-container section-fundamentals" data-section-id="section-python-fundamentals"> + <div class="schema-container section-fundamentals" data-section-id="section-python-fundamentals" data-section-name="Python Fundamentals"> <h2 class="section-title" id="section-python-fundamentals-title">Python Fundamentals for Architects</h2> <div class="row"> <div class="col-lg-4 col-md-6"> @@ -491,14 +577,14 @@ a duck..."). </li> <li><strong>Exception Handling:</strong> Building resilient systems with `try-except-finally`.</li> - <li><strong>Generators & Iterators:</strong> Memory-efficient processing of large data sequences.</li> - <li><strong>Decorators:</strong> Modifying function/method behavior (e.g., logging, auth checks).</li> + <li><strong>Generators & Iterators <span class="version-tag">Python 2.2+</span>:</strong> Memory-efficient processing of large data sequences.</li> + <li><strong>Decorators <span class="version-tag">Python 2.4+</span>:</strong> Modifying function/method behavior (e.g., logging, auth checks).</li> <li> - <strong>Context Managers (`with` statement):</strong> Automatic resource management (files, locks, + <strong>Context Managers (`with` statement) <span class="version-tag">Python 2.5+</span>:</strong> Automatic resource management (files, locks, connections). </li> <li> - <strong>Type Hinting (PEP 484):</strong> Optional static type checking for improved code quality and + <strong>Type Hinting (PEP 484) <span class="version-tag">Python 3.5+</span>:</strong> Optional static type checking for improved code quality and maintainability using tools like Mypy. <a href="https://peps.python.org/pep-0484/" target="_blank" rel="noopener noreferrer">PEP 484</a> </li> @@ -535,20 +621,20 @@ <h6>Frequently Used Modules</h6> <ul> <li><strong>`os`, `sys`:</strong> System interaction, environment variables, path manipulation.</li> - <li><strong>`json`, `xml.etree.ElementTree`:</strong> Data interchange formats.</li> + <li><strong>`json` <span class="version-tag">Python 2.6+</span>:</strong> Data interchange formats.</li> <li><strong>`datetime`, `time`:</strong> Date and time operations.</li> <li> <strong>`collections`:</strong> Advanced data structures (e.g., `deque`, `Counter`, `defaultdict`). </li> <li> - <strong>`multiprocessing`, `threading`, `asyncio`, `concurrent.futures`:</strong> Concurrency and + <strong>`multiprocessing` <span class="version-tag">Python 2.6+</span>, `threading`, `asyncio` <span class="version-tag">Python 3.4+/3.5+</span>, `concurrent.futures` <span class="version-tag">Python 3.2+</span>:</strong> Concurrency and parallelism. (See Concurrency section) </li> <li><strong>`socket`:</strong> Low-level networking.</li> - <li><strong>`logging`:</strong> Flexible event logging system.</li> - <li><strong>`argparse`:</strong> Command-line argument parsing.</li> + <li><strong>`logging` <span class="version-tag">Python 2.3+</span>:</strong> Flexible event logging system.</li> + <li><strong>`argparse` <span class="version-tag">Python 2.7/3.2+</span>:</strong> Command-line argument parsing.</li> <li> - <strong>`pathlib`:</strong> Object-oriented filesystem paths. + <strong>`pathlib` <span class="version-tag">Python 3.4+</span>:</strong> Object-oriented filesystem paths. <a href="https://docs.python.org/3/library/pathlib.html" target="_blank" rel="noopener noreferrer" >Pathlib</a > @@ -561,7 +647,7 @@ </div> <!-- II. ARCHITECTURAL PATTERNS --> - <div class="schema-container section-architecture" data-section-id="section-python-arch-patterns"> + <div class="schema-container section-architecture" data-section-id="section-python-arch-patterns" data-section-name="Architectural Patterns"> <h2 class="section-title" id="section-python-arch-patterns-title">Architectural Patterns in Python</h2> <div class="row"> <div class="col-lg-4 col-md-6"> @@ -921,7 +1007,7 @@ </div> <!-- III. KEY PYTHON FRAMEWORKS --> - <div class="schema-container section-web" data-section-id="section-python-frameworks"> + <div class="schema-container section-web" data-section-id="section-python-frameworks" data-section-name="Python Frameworks"> <h2 class="section-title" id="section-python-frameworks-title">Key Python Frameworks</h2> <div class="row"> <div class="col-lg-4 col-md-6"> @@ -1019,11 +1105,10 @@ <div class="col-lg-4 col-md-6"> <div class="info-card card-web" id="card-fastapi"> <div class="card-body"> - <h5><i class="bi bi-speedometer2"></i> FastAPI</h5> + <h5><i class="bi bi-speedometer2"></i> FastAPI <span class="version-tag">Python 3.7+</span></h5> <div class="card-content-wrapper"> <p class="summary"> - Modern, high-performance web framework for building <span class="term">APIs</span> with Python 3.7+ - type hints. Based on <span class="term">Starlette</span> and <span class="term">Pydantic</span>. + Modern, high-performance web framework for building <span class="term">APIs</span> with Python type hints. Based on <span class="term">Starlette</span> and <span class="term">Pydantic</span>. <a href="https://fastapi.tiangolo.com/" target="_blank" rel="noopener noreferrer" >FastAPI Project</a > @@ -1233,7 +1318,7 @@ </div> <!-- IV. DESIGN PATTERNS IN PYTHON --> - <div class="schema-container section-designpatterns" data-section-id="section-python-design-patterns"> + <div class="schema-container section-designpatterns" data-section-id="section-python-design-patterns" data-section-name="Design Patterns"> <h2 class="section-title" id="section-python-design-patterns-title">Design Patterns in Python</h2> <div class="row"> <div class="col-lg-4 col-md-6"> @@ -1323,7 +1408,7 @@ <strong>Adapter:</strong> Convert the interface of a class into another interface clients expect. </li> <li> - <strong>Decorator:</strong> Attach additional responsibilities to an object dynamically. (Python's + <strong>Decorator <span class="version-tag">Python 2.4+</span>:</strong> Attach additional responsibilities to an object dynamically. (Python's `@` syntax is a form of syntactic sugar for decorators). </li> <li><strong>Facade:</strong> Provide a unified interface to a set of interfaces in a subsystem.</li> @@ -1399,7 +1484,7 @@ </div> <!-- V. DATA HANDLING & PERSISTENCE --> - <div class="schema-container section-data" data-section-id="section-python-data-handling"> + <div class="schema-container section-data" data-section-id="section-python-data-handling" data-section-name="Data Handling"> <h2 class="section-title" id="section-python-data-handling-title">Data Handling & Persistence</h2> <div class="row"> <div class="col-lg-4 col-md-6"> @@ -1499,7 +1584,7 @@ <h5><i class="bi bi-braces"></i> Data Serialization</h5> <div class="card-content-wrapper"> <p class="summary"> - Handling formats like <span class="term">JSON</span> (`json` module), + Handling formats like <span class="term">JSON</span> (`json` module <span class="version-tag">Py 2.6+</span>), <span class="term">Protocol Buffers</span> (`protobuf`), <span class="term">Avro</span> (`fastavro`), XML for data interchange. <a href="https://docs.python.org/3/library/json.html" target="_blank" rel="noopener noreferrer" @@ -1563,7 +1648,7 @@ </div> <!-- VI. CONCURRENCY AND PARALLELISM --> - <div class="schema-container section-concurrency" data-section-id="section-python-concurrency"> + <div class="schema-container section-concurrency" data-section-id="section-python-concurrency" data-section-name="Concurrency"> <h2 class="section-title" id="section-python-concurrency-title">Concurrency & Parallelism</h2> <div class="row"> <div class="col-lg-4 col-md-6"> @@ -1627,7 +1712,7 @@ <div class="card-content-wrapper"> <p class="summary"> <span class="term">`threading`</span> for I/O-bound tasks. - <span class="term">`multiprocessing`</span> for CPU-bound tasks to achieve true parallelism. + <span class="term">`multiprocessing` <span class="version-tag">Python 2.6+</span></span> for CPU-bound tasks to achieve true parallelism. <a href="https://docs.python.org/3/library/threading.html" target="_blank" rel="noopener noreferrer" >Threading</a >, @@ -1681,7 +1766,7 @@ </li> <li><strong>IPC Mechanisms:</strong> Pipes, Queues, shared memory.</li> </ul> - <h6>`concurrent.futures`</h6> + <h6>`concurrent.futures` <span class="version-tag">Python 3.2+</span></h6> <p> A high-level interface for asynchronously executing callables using thread pools (`ThreadPoolExecutor`) or process pools (`ProcessPoolExecutor`). Simplifies managing groups of threads @@ -1699,7 +1784,7 @@ <div class="col-lg-4 col-md-6"> <div class="info-card card-concurrency" id="card-asyncio"> <div class="card-body"> - <h5><i class="bi bi-hurricane"></i> Asyncio (async/await)</h5> + <h5><i class="bi bi-hurricane"></i> Asyncio (async/await) <span class="version-tag">Python 3.5+</span></h5> <div class="card-content-wrapper"> <p class="summary"> Asynchronous programming with <span class="term">`async/await`</span> syntax for concurrent @@ -1758,7 +1843,7 @@ </div> <!-- VII. TOOLING, TESTING & DEVOPS --> - <div class="schema-container section-tooling" data-section-id="section-python-tooling"> + <div class="schema-container section-tooling" data-section-id="section-python-tooling" data-section-name="Tooling & DevOps"> <h2 class="section-title" id="section-python-tooling-title">Tooling, Testing & DevOps</h2> <div class="row"> <div class="col-lg-4 col-md-6"> @@ -1847,7 +1932,7 @@ <strong>Pylint:</strong> More extensive checks, including code smells and potential bugs. Highly configurable. </li> - <li><strong>Mypy:</strong> Static type checker for type-hinted code.</li> + <li><strong>Mypy <span class="version-tag">Python 3.5+ (for hints)</span>:</strong> Static type checker for type-hinted code.</li> </ul> <h6>Formatters</h6> <ul> @@ -1877,7 +1962,7 @@ <div class="card-content-wrapper"> <p class="summary"> WSGI/ASGI servers (<span class="term">Gunicorn</span>, <span class="term">Uvicorn</span>), - <span class="term">Docker</span>, Kubernetes, CI/CD (GitHub Actions, Jenkins), virtual environments. + <span class="term">Docker</span>, Kubernetes, CI/CD (GitHub Actions, Jenkins), virtual environments (<span class="term">venv</span> <span class="version-tag">Py 3.3+</span>). <a href="https://gunicorn.org/" target="_blank" rel="noopener noreferrer">Gunicorn</a>, <a href="https://www.uvicorn.org/" target="_blank" rel="noopener noreferrer">Uvicorn</a> </p> @@ -1938,7 +2023,7 @@ </div> <!-- VIII. SECURITY CONSIDERATIONS --> - <div class="schema-container section-security" data-section-id="section-python-security"> + <div class="schema-container section-security" data-section-id="section-python-security" data-section-name="Security"> <h2 class="section-title" id="section-python-security-title">Security Considerations</h2> <div class="row"> <div class="col-lg-4 col-md-6"> @@ -2142,7 +2227,7 @@ </div> <!-- IX. ADVANCED TOPICS & PERFORMANCE --> - <div class="schema-container section-advanced" data-section-id="section-python-advanced"> + <div class="schema-container section-advanced" data-section-id="section-python-advanced" data-section-name="Advanced Topics"> <h2 class="section-title" id="section-python-advanced-title">Advanced Topics & Performance</h2> <div class="row"> <div class="col-lg-4 col-md-6"> @@ -2218,7 +2303,7 @@ <div class="card-content-wrapper"> <p class="summary"> Improve performance and reduce load by caching data. In-memory (<span class="term" - >`functools.lru_cache`</span + >`functools.lru_cache` <span class="version-tag">Py 3.2+</span></span >), distributed (<span class="term">Redis</span>, <span class="term">Memcached</span>), HTTP caching. <a @@ -2342,7 +2427,7 @@ </div> <!-- X. KEY CONSIDERATIONS FOR ARCHITECTS (General) --> - <div class="schema-container section-general" data-section-id="section-arch-considerations-general"> + <div class="schema-container section-general" data-section-id="section-arch-considerations-general" data-section-name="Architectural Considerations"> <h2 class="section-title" id="section-arch-considerations-general-title"> Key Considerations for Python Architects </h2> @@ -2438,7 +2523,8 @@ </div> <footer class="container text-center pb-3"> - <p class="mb-2">© <span id="currentYear"></span> Python Architect Cheatsheet Contributor</p> + <p class="mb-1">© <span id="currentYear"></span> Python Architect Cheatsheet Contributor</p> + <p class="mb-2" style="font-size: 0.8em;">Last Updated: <span id="lastUpdatedDate">May 10, 2025</span></p> <div> <a href="https://docs.python.org/3/" @@ -2473,8 +2559,131 @@ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> <script> document.addEventListener("DOMContentLoaded", () => { - // JavaScript for LeaderLines and dimming effects has been removed. - // The remaining JavaScript handles the collapse toggle icons and current year. + const mainContainer = document.getElementById('main-container'); + const searchBox = document.getElementById('search-box'); + const categoryFiltersContainer = document.getElementById('category-filters'); + const noResultsDiv = document.getElementById('no-results'); + const allSchemaContainers = Array.from(document.querySelectorAll('.schema-container')); + // const allInfoCards = Array.from(document.querySelectorAll('.info-card')); // Not directly used in this simplified version + + let activeFilter = 'all'; + + function initializeFiltersAndSearch() { + const allButton = document.createElement('button'); + allButton.type = 'button'; + allButton.classList.add('btn', 'btn-outline-secondary', 'filter-btn', 'active'); + allButton.textContent = 'All Categories'; + allButton.dataset.filter = 'all'; + categoryFiltersContainer.appendChild(allButton); + + const btnGroup = document.createElement('div'); + btnGroup.classList.add('btn-group', 'flex-wrap'); + btnGroup.setAttribute('role', 'group'); + + allSchemaContainers.forEach(section => { + const sectionId = section.dataset.sectionId; + const sectionName = section.dataset.sectionName || + (section.querySelector('.section-title') ? + section.querySelector('.section-title').textContent.trim() + .replace(' for Architects', '') + .replace(' in Python', '') + .replace(' & DevOps','') + .replace(' & Persistence','') + .replace(' & Parallelism','') + .replace(' & Performance','') + .replace(' (General)','') + : 'Unnamed Section'); + const button = document.createElement('button'); + button.type = 'button'; + button.classList.add('btn', 'btn-outline-secondary', 'filter-btn'); + button.textContent = sectionName; + button.dataset.filter = sectionId; + btnGroup.appendChild(button); + }); + categoryFiltersContainer.appendChild(btnGroup); + + searchBox.addEventListener('input', applyFiltersAndSearch); + + categoryFiltersContainer.addEventListener('click', (event) => { + if (event.target.classList.contains('filter-btn')) { + document.querySelectorAll('#category-filters .filter-btn').forEach(btn => btn.classList.remove('active')); + event.target.classList.add('active'); + activeFilter = event.target.dataset.filter; + applyFiltersAndSearch(); + } + }); + } + + function applyFiltersAndSearch() { + const searchTerm = searchBox.value.toLowerCase().trim(); + let itemsFound = 0; + + allSchemaContainers.forEach(section => { + const sectionId = section.dataset.sectionId; + let sectionHasVisibleCards = false; + + const cardsInSection = Array.from(section.querySelectorAll('.info-card')); + + cardsInSection.forEach(card => { + const cardTitle = card.querySelector('h5') ? card.querySelector('h5').textContent.toLowerCase() : ''; + const cardSummary = card.querySelector('p.summary') ? card.querySelector('p.summary').textContent.toLowerCase() : ''; + const cardDetailsCollapse = card.querySelector('.collapse-content'); + const cardDetailsText = cardDetailsCollapse ? cardDetailsCollapse.textContent.toLowerCase() : ''; + const versionTag = card.querySelector('.version-tag') ? card.querySelector('.version-tag').textContent.toLowerCase() : ''; + + const cardTextContent = `${cardTitle} ${cardSummary} ${cardDetailsText} ${versionTag}`; + + const matchesSearch = searchTerm === '' || cardTextContent.includes(searchTerm); + const matchesFilter = activeFilter === 'all' || sectionId === activeFilter; + + if (matchesSearch && matchesFilter) { + card.closest('.col-lg-4.col-md-6').style.display = ''; + card.style.display = 'flex'; + sectionHasVisibleCards = true; + itemsFound++; + } else { + card.closest('.col-lg-4.col-md-6').style.display = 'none'; + card.style.display = 'none'; + } + }); + + if ((activeFilter === 'all' || sectionId === activeFilter) && sectionHasVisibleCards) { + section.style.display = ''; + } else if (activeFilter !== 'all' && sectionId !== activeFilter) { + section.style.display = 'none'; + } else if (!sectionHasVisibleCards && searchTerm !== '') { + section.style.display = 'none'; + } else if (!sectionHasVisibleCards && activeFilter !== 'all') { + section.style.display = 'none'; + } + else if (!sectionHasVisibleCards && activeFilter === 'all' && searchTerm !== '') { + section.style.display = 'none'; // Hide if "All" categories but search yields no cards in section + } + else if (activeFilter === 'all' && !sectionHasVisibleCards && searchTerm === '') { + //This case should not hide the section if no search term, but can happen if section is empty + } + else { + // Default fallback if a section has no visible cards after filtering/searching + section.style.display = 'none'; + } + + + // If "All Categories" is selected and there's a search term, only show sections with matching cards + if (activeFilter === 'all' && searchTerm !== '') { + if (sectionHasVisibleCards) { + section.style.display = ''; + } else { + section.style.display = 'none'; + } + } else if (activeFilter === 'all' && searchTerm === '') { + section.style.display = ''; // Show all sections if "All Categories" and no search + } + + + }); + + noResultsDiv.style.display = itemsFound === 0 ? 'block' : 'none'; + } const collapseElements = document.querySelectorAll(".collapse"); collapseElements.forEach((collapseEl) => { @@ -2498,17 +2707,17 @@ collapseEl.addEventListener("show.bs.collapse", () => { updateIconAndButton(true); }); - // No need for positionLines on shown/hidden as lines are removed - // collapseEl.addEventListener('shown.bs.collapse', positionLines); collapseEl.addEventListener("hide.bs.collapse", () => { updateIconAndButton(false); }); - // collapseEl.addEventListener('hidden.bs.collapse', positionLines); } }); document.getElementById("currentYear").textContent = new Date().getFullYear(); + // Initialize and apply filters + initializeFiltersAndSearch(); + applyFiltersAndSearch(); // Apply initial filter ("All") }); </script> </body> -</html> +</html> \ No newline at end of file