<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Surendra Miriyala on Medium]]></title>
        <description><![CDATA[Stories by Surendra Miriyala on Medium]]></description>
        <link>https://medium.com/@miriyalasurendra99?source=rss-918f081a6ff1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*iy8kQuGGlCGsJ9qEIKbl4w.jpeg</url>
            <title>Stories by Surendra Miriyala on Medium</title>
            <link>https://medium.com/@miriyalasurendra99?source=rss-918f081a6ff1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 14:24:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@miriyalasurendra99/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Making GitHub Copilot Smarter with a Structured Approach]]></title>
            <link>https://medium.com/@miriyalasurendra99/making-github-copilot-smarter-with-a-structured-approach-7dbc29fe9910?source=rss-918f081a6ff1------2</link>
            <guid isPermaLink="false">https://medium.com/p/7dbc29fe9910</guid>
            <dc:creator><![CDATA[Surendra Miriyala]]></dc:creator>
            <pubDate>Sun, 22 Mar 2026 14:23:56 GMT</pubDate>
            <atom:updated>2026-03-22T14:23:56.139Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been using GitHub Copilot for the past few months, and recently I completed the <strong>Anthropic Agent Skills certification</strong>.</p><p>In my day-to-day work, I use Copilot extensively for tasks like Lambda development, writing unit tests, generating PR descriptions, and documentation. While it was helpful, I noticed one challenge — I had to repeatedly give the same instructions (coding standards, testing rules, documentation format, etc.).</p><h3>The Realization</h3><p>Over time, I realized that instead of repeating prompts again and again, we can <strong>structure our instructions</strong> in a way that Copilot can reuse them.</p><p>So I came up with an approach inspired by agent-based systems:</p><ul><li>Define <strong>standards</strong> once</li><li>Create reusable <strong>skills (prompts)</strong></li><li>Organize workflows like <strong>hooks and execution steps</strong></li></ul><h3>The Approach</h3><p>I created a simple structure in the project:</p><pre>.ai/<br>  standards/<br>  skills/<br>  hooks/<br>  prompts/</pre><pre>.github/<br>  copilot-instructions.md</pre><h3>Example Structure</h3><pre>.ai/<br>├── standards/<br>│   └── project.md<br>├── skills/<br>│   ├── dev/<br>│   │   └── unit-test.md<br>│   ├── docs/<br>│   │   └── pr.md<br>│   └── review/<br>│       └── code-review.md<br>├── hooks/<br>│   └── pre-pr.md<br>└── prompts/<br>    └── full-flow.md</pre><h3>Sample Files</h3><h3>standards/project.md</h3><p>Defines coding and development rules:</p><ul><li>Follow PEP 8</li><li>Use class-based design</li><li>Add logging and exception handling</li><li>Use pytest for unit testing</li></ul><h3>skills/dev/unit-test.md</h3><p>Reusable skill for generating tests:</p><pre># Skill: Unit Test Generator</pre><pre>Generate pytest unit tests.</pre><pre>Constraints:<br>- Follow PEP 8<br>- Cover positive and negative scenarios<br>- Include edge cases<br>- Mock external services</pre><h3>skills/docs/pr.md</h3><p>Reusable skill for PR documentation:</p><pre># Skill: PR Generator</pre><pre>Generate PR description.</pre><pre>Include:<br>- Summary<br>- Changes<br>- Testing<br>- Impact</pre><h3>hooks/pre-pr.md</h3><p>Workflow step before PR:</p><pre>Validate code<br>Ensure tests exist<br>Generate PR description</pre><h3>prompts/full-flow.md</h3><p>Full automation prompt:</p><pre>Generate code<br>Generate unit tests<br>Review code<br>Generate PR description</pre><h3>How It Helps</h3><p>Now instead of writing long prompts, I just give a simple instruction like:</p><ul><li>“Generate unit tests using project standards”</li><li>“Generate PR description based on changes”</li><li>“Execute full workflow”</li></ul><p>Copilot automatically:</p><ul><li>Follows coding standards</li><li>Applies constraints</li><li>Generates structured output</li></ul><h3>Example Usage in VS Code</h3><h3>Generate Unit Tests</h3><pre>Use unit-test skill from .ai and generate test cases</pre><h3>Generate PR Description</h3><pre>Use PR skill and generate description</pre><h3>Full Workflow</h3><pre>Execute full-flow prompt from .ai/prompts</pre><h3>Benefits I Observed</h3><ul><li><strong>Saves time</strong> — no need to repeat instructions</li><li><strong>Reusable prompts</strong> — for repetitive tasks</li><li><strong>Standardized output</strong> — consistent code and documentation</li><li><strong>Better results</strong> — even with a single request</li><li><strong>Improved productivity</strong> in daily development work</li></ul><h3>Key Insight</h3><p>By defining: standards,constraints,reusable prompts<br>we can guide AI better. Instead of giving instructions every time,<br>we <strong>teach Copilot once and reuse it everywhere</strong></p><h3>Conclusion</h3><p>This approach helped me use GitHub Copilot more effectively in my daily workflow.</p><p>Now with a <strong>single request</strong>, I can get:</p><ul><li>clean code</li><li>proper unit tests</li><li>structured PR documentation</li></ul><p>All aligned with project standards. If you are using Copilot regularly, I highly recommend trying this structured approach. It can significantly improve both <strong>productivity and consistency</strong> in your development workflow 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dbc29fe9910" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Jenkins to Access AWS Accounts Securely Using IAM Roles]]></title>
            <link>https://medium.com/@miriyalasurendra99/setting-up-jenkins-to-access-aws-accounts-securely-using-iam-roles-9c7dcb6fd7ef?source=rss-918f081a6ff1------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c7dcb6fd7ef</guid>
            <dc:creator><![CDATA[Surendra Miriyala]]></dc:creator>
            <pubDate>Sun, 26 Oct 2025 12:43:13 GMT</pubDate>
            <atom:updated>2025-10-26T12:43:13.291Z</atom:updated>
            <content:encoded><![CDATA[<p>This document explains how to configure <strong>cross-account IAM roles</strong> to allow Jenkins to securely access and manage resources across multiple AWS accounts (e.g., Dev, QA, UAT, Prod).</p><p>By setting up trusted IAM roles and policies, Jenkins can automate AWS deployments without using long-term credentials. This approach follows the <strong>principle of least privilege</strong>, enhances <strong>security</strong>, and simplifies <strong>multi-account automation</strong>.</p><ul><li>Enable Jenkins to assume IAM roles across AWS accounts securely.</li><li>Centralize access management using cross-account IAM trust relationships.</li><li>Automate AWS stack deployments via Jenkins pipelines.</li></ul><h3>Prerequisites</h3><ul><li>AWS accounts for different environments (Dev, QA, UAT, Prod)</li><li>Jenkins EC2 instance running in one AWS account (UAT in this example).</li><li>IAM and EC2 administrative access.</li><li>AWS CLI configured on the Jenkins server.</li></ul><h3>1️. Setting up IAM Roles for Cross-Account Access</h3><h3>Step 1.0 — Create Cross-Account Role Trust Relationship</h3><ol><li><strong>Create a cross-account role</strong> with a <strong>trust relationship</strong> with the <strong>UAT account</strong> (where Jenkins is hosted).</li><li>Edit this role’s <strong>permissions</strong> so it can access the required resources in the respective environment account.</li><li><strong>Note:</strong> This role must be created in <strong>each environment account</strong> (Dev, QA, UAT, Prod, CT) — that is, the account where resources need to be created or managed by Jenkins.</li></ol><h3>Step 1.1 — Create a Cross-Account Role</h3><ol><li>Sign in to the <strong>AWS Management Console</strong> of the target account (the one Jenkins needs to access).</li><li>Navigate to <strong>IAM → Roles → Create role</strong>.</li><li>Under <strong>Trusted entity type</strong>, choose <strong>AWS account</strong>.</li><li>Select <strong>Another AWS account</strong>, and enter the <strong>Account ID of the Jenkins (UAT) account</strong>.</li><li>In the <strong>Permissions policies</strong> step, attach a policy based on the required access.</li></ol><ul><li>Example: AdministratorAccess (for full access, or a custom policy for restricted access).</li></ul><p>6. Add relevant <strong>tags</strong> for identification.</p><p>7. Review and <strong>Create the role</strong>.</p><p>8. Repeat the same steps for all target accounts (Dev, QA, UAT, Prod, CT).</p><p><strong>Example Role Names:</strong></p><ul><li>DevCrossAccountRole</li><li>QACrossAccountRole</li><li>UATCrossAccountRole</li><li>PRODCrossAccountRole</li><li>CTCrossAccountRole</li></ul><h3>Step 1.2 — Create an EC2 Service Role for Jenkins</h3><ol><li>Sign in to the <strong>AWS account</strong> where the <strong>Jenkins EC2 server</strong> exists (UAT).</li><li>Go to <strong>IAM → Roles → Create role</strong>.</li><li>Under <strong>Trusted entity type</strong>, choose <strong>AWS service</strong> and select <strong>EC2</strong>.</li><li>Attach permissions required for the Jenkins server to operate.</li></ol><ul><li>Example: Basic EC2 permissions and sts:AssumeRole for cross-account access.</li></ul><p>5. Add a descriptive role name (e.g., JenkinsEC2ServiceRole).</p><p>6. Click <strong>Create role</strong>.</p><h3>Step 1.3 — Update the Jenkins Role to Allow Cross-Account AssumeRole</h3><ol><li>Go to <strong>IAM → Roles → JenkinsEC2ServiceRole</strong>.</li><li>Under the <strong>Permissions</strong> tab, click <strong>Add inline policy</strong>.</li><li>Switch to the <strong>JSON</strong> tab and add the following policy:</li></ol><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;AllowCrossAccountAssumeRole&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;sts:AssumeRole&quot;,<br>      &quot;Resource&quot;: [<br>        &quot;arn:aws:iam::&lt;dev-AccountID&gt;:role/&lt;DevCrossAccountRole&gt;&quot;,<br>        &quot;arn:aws:iam::&lt;qa-AccountID&gt;:role/&lt;QACrossAccountRole&gt;&quot;,<br>        &quot;arn:aws:iam::&lt;uat-AccountID&gt;:role/&lt;UATCrossAccountRole&gt;&quot;,<br>        &quot;arn:aws:iam::&lt;prod-AccountID&gt;:role/&lt;PRODCrossAccountRole&gt;&quot;,<br>        &quot;arn:aws:iam::&lt;ct-AccountID&gt;:role/&lt;CTCrossAccountRole&gt;&quot;<br>      ]<br>    }<br>  ]<br>}</pre><p>4. Click <strong>Next</strong>, give the policy a descriptive name (e.g., CrossAccountAssumeRolePolicy), and click <strong>Create Policy</strong>.</p><p>5. Attach the following existing or custom policy for EC2 instance connect access (optional but useful for BP node installations):</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;AllowEC2InstanceConnect&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: [<br>        &quot;ec2-instance-connect:SendSSHPublicKey&quot;,<br>        &quot;ec2:DescribeInstances&quot;,<br>        &quot;iam:GetSSHPublicKey&quot;,<br>        &quot;iam:UploadSSHPublicKey&quot;<br>      ],<br>      &quot;Resource&quot;: &quot;*&quot;<br>    }<br>  ]<br>}</pre><h3>Step 1.4 — Attach the IAM Role to the Jenkins EC2 Server</h3><ol><li>Go to <strong>EC2 Console → Instances → Select Jenkins Instance</strong>.</li><li>Click <strong>Actions → Security → Modify IAM Role</strong>.</li><li>Select the <strong>JenkinsEC2ServiceRole</strong> created earlier.</li><li>Click <strong>Update IAM Role</strong>.</li></ol><h3>2️. Grant Jenkins Sudo Access (No Password Required)</h3><ol><li>Connect to the Jenkins EC2 server using SSH.</li><li>Edit the sudoers file using:</li></ol><p>sudo visudo</p><p>3. Add the following line below the root user entry:</p><p>jenkins ALL=(ALL:ALL) NOPASSWD: AL</p><p>4. This allows the Jenkins user to run commands with sudo privileges without requiring a password.</p><p>5. Save and exit (Esc → :wq → Enter).</p><h3>3️. Configure Jenkins Job to Assume IAM Role</h3><p>Inside the Jenkins pipeline or shell script, use the following commands to assume the IAM role dynamically and set temporary credentials as environment variables:</p><pre>ASSUME_ROLE_OUTPUT=$(sudo -S -k aws sts assume-role --role-arn $rolearn --role-session-name jenkins)</pre><pre>ASSUME_ROLE_ENVIRONMENT=$(sudo -S -k echo $ASSUME_ROLE_OUTPUT | jq -r &#39;.Credentials | <br>.[&quot;AWS_ACCESS_KEY_ID&quot;] = .AccessKeyId |<br>.[&quot;AWS_SECRET_ACCESS_KEY&quot;] = .SecretAccessKey |<br>.[&quot;AWS_SESSION_TOKEN&quot;] = .SessionToken |<br>del(.AccessKeyId, .SecretAccessKey, .SessionToken, .Expiration) |<br>to_entries[] | &quot;export \(.key)=\(.value)&quot;&#39;)</pre><pre>eval &quot;$ASSUME_ROLE_ENVIRONMENT&quot;</pre><p>This ensures Jenkins uses <strong>temporary AWS credentials</strong> when deploying resources in target accounts.</p><h3>Outcome</h3><ul><li>Jenkins now assumes roles across AWS accounts securely.</li><li>No hard coded credentials are stored in Jenkins.</li><li>Cross-account access is fully audit able through IAM trust relationships.</li><li>Automation is consistent and secure across all environments.</li></ul><h3>Key Benefits</h3><ul><li><strong>Improved Security</strong>: Eliminates long-term credentials.</li><li><strong>Centralized Management</strong>: Control access through IAM trust and policies.</li><li><strong>Automation Efficiency</strong>: Enables seamless deployments from Jenkins across AWS accounts.</li><li><strong>Scalability</strong>: Easily extendable for future accounts or environments.</li></ul><h3>Conclusion</h3><p>By implementing cross-account IAM roles and configuring Jenkins EC2 roles properly, we can achieve a <strong>secure, scalable, and automated deployment pipeline</strong> across multiple AWS environments.</p><p>This setup is ideal for teams managing <strong>multi-account AWS infrastructure</strong> who want to maintain <strong>security best practices</strong> without sacrificing automation flexibility.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c7dcb6fd7ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Python Version Migration Imperative: 3.9 ➜ 3.13]]></title>
            <link>https://medium.com/@miriyalasurendra99/the-python-version-migration-imperative-3-9-3-13-0ad787464566?source=rss-918f081a6ff1------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ad787464566</guid>
            <dc:creator><![CDATA[Surendra Miriyala]]></dc:creator>
            <pubDate>Tue, 07 Oct 2025 16:11:08 GMT</pubDate>
            <atom:updated>2025-10-07T19:24:19.646Z</atom:updated>
            <content:encoded><![CDATA[<p>The choice of Python version is no longer just about features — it directly affects <strong>security, performance, and long-term maintainability</strong>. If your project still runs on Python 3.9 or older, this is your urgent call to action.</p><p>As of <strong>October 2025</strong>, Python 3.9 has officially reached <strong>End-of-Life (EOL)</strong>. Running EOL software exposes your applications to <strong>unpatched vulnerabilities</strong> and complicates dependency management.</p><p><strong>Status of Python versions:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*X-q5FNahbIAJYDGFmutt3w.png" /></figure><h3>Section 1: Decoding the Python Lifecycle Chart</h3><p>Here’s the latest status of Python versions:</p><ul><li>🔴 <strong>Red (EOL):</strong> No more support or security updates. Using these versions is a <strong>major security risk</strong> (Python 3.9 and earlier).</li><li>🟡 <strong>Yellow (Security Fixes Only):</strong> Only critical patches. Versions 3.10, 3.11, 3.12 are nearing end-of-life.</li><li>🟢 <strong>Green (Active Support/Bug Fixes):</strong> Fully supported, actively receiving <strong>bug fixes and security patches</strong> (Python 3.13).</li></ul><h3>Section 2: Why Lambda Migration to Python 3.13 is Necessary</h3><p>AWS Lambda functions are <strong>tied to specific Python runtimes</strong>. Using an unsupported runtime can cause:</p><ul><li><strong>Runtime failures </strong>if dependencies are incompatible.</li><li><strong>Security risks</strong> due to unpatched Python vulnerabilities.</li><li><strong>Dependency limitations</strong> as modern libraries drop support for older Python versions.</li></ul><p>Migration means:</p><ol><li>Updating your Lambda runtime to a supported version (Python 3.13).</li><li>Ensuring dependencies are compatible with the new runtime.</li><li>Updating CI/CD pipelines to install packages using the correct pip version.</li><li>Rebuild &amp; Deploy<strong>:</strong> Validate deployment in a lower environment before production rollout.</li></ol><p><strong>Why Python 3.13 ?</strong></p><ul><li>Active bug-fix support till October 2029.</li><li>Better performance, memory efficiency, and async improvements.</li></ul><h3>Section 3: Jenkins Pipeline &amp; Lambda Update Recommendation</h3><p><strong>Problem:</strong> Your Jenkins pipeline installs dependencies using the wrong Python version.</p><ul><li><strong>Lambda Runtime:</strong> python3.9</li><li><strong>Pipeline Script:</strong> pip3.13 install -r requirements.txt</li></ul><p>This mismatch can cause runtime errors due to incompatible packages.</p><p><strong>Fix:</strong> Update your Jenkins pipeline:</p><pre>// Fix for Python 3.13 Lambda runtime<br>sh &#39;pip3.13 install -r requirements.txt&#39;</pre><p>Next Step: Plan the Lambda upgrade to<strong> </strong>Python 3.13 before Python 3.9 is fully deprecated.</p><h3>Section 4: Updated Dependencies for Python 3.13</h3><p>Example requirements.txt for Python 3.13:</p><pre># Python 3.13 compatible dependencies<br>pytest==8.4.0<br>sqlalchemy==2.0.41<br>boto3<br>sqlacodegen<br>pandas==2.3.0<br>numpy==2.3.0<br>requests<br>psycopg2-binary==2.9.10<br>zeep==4.3.1<br>openpyxl==3.1.5</pre><h3>Section 5: Testing &amp; CI/CD Validation</h3><p>Before final rollout, validate the migration through automated testing and CI/CD:</p><ul><li><strong>Unit &amp; Integration Tests:</strong><br> Run all existing pytest or unittest test cases under Python 3.13.<br> Ensure modules, imports, and package versions behave as expected.</li><li><strong>Pipeline Validation in Jenkins:</strong></li><li>Trigger builds using <strong>Python 3.13</strong> runtime.</li><li>Verify test results, coverage, and dependency installation logs.</li><li>Confirm Lambda packaging and deployment stages succeed without runtime warnings.</li><li><strong>Post-Deployment Verification:</strong><br> Validate logs in CloudWatch to ensure Lambda executes as expected with the new runtime.</li></ul><h3>Section 6: Conclusion</h3><p>Do not let your projects sit on a deprecated Python runtime.</p><ul><li>Set Python 3.13 as your migration target.</li><li>Update pipelines, dependencies, and Lambda functions accordingly.</li><li>Regularly review your Python versions to stay ahead of deprecation&#39;s.</li></ul><p><strong>Reference: </strong><a href="https://devguide.python.org/versions/">https://devguide.python.org/versions/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ad787464566" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Parallel Execution in AWS Lambda using Python’s ThreadPoolExecutor]]></title>
            <link>https://medium.com/@miriyalasurendra99/parallel-execution-in-aws-lambda-using-pythons-threadpoolexecutor-54c028ae9788?source=rss-918f081a6ff1------2</link>
            <guid isPermaLink="false">https://medium.com/p/54c028ae9788</guid>
            <dc:creator><![CDATA[Surendra Miriyala]]></dc:creator>
            <pubDate>Sun, 21 Sep 2025 15:55:26 GMT</pubDate>
            <atom:updated>2025-09-23T07:26:06.817Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, for a project, we implemented <strong>parallel execution</strong> inside an AWS Lambda function.<br> The Lambda receives multiple records as part of an event. Instead of processing them one by one (serially), we used multi threading to split them into smaller batches and process them in parallel.</p><p>This reduced the Lambda execution time significantly → which in turn made it more cost-effective since AWS Lambda billing is directly tied to execution time.</p><p><strong>Parallel Execution in Lambda</strong></p><p>AWS Lambda charges you based on: Execution duration (in milliseconds) and Allocated memory.</p><p>Processing records in parallel maximizes Lambda’s efficiency by significantly reducing execution duration. This directly lowers cost — especially for high-volume workloads — and improves throughput for downstream systems.</p><p><strong>How We Implemented It</strong></p><p>We used the following concepts in Python:<br>1. yield → to split incoming records into chunks (batches)<br>2. Multithreading → to process batches at the same time<br>3. ThreadPoolExecutor → to manage worker threads efficiently<br>4. as_completed → to get results as soon as each batch is finished<br>5. uuid → to assign a unique ID to each batch for logging</p><ol><li><strong>yield:<br></strong>Instead of returning everything at once, yield gives one piece at a time.<br>We use it to split records into chunks efficiently.</li></ol><pre>def chunk_records(records, size):<br>    for i in range(0, len(records), size):<br>        yield records[i:i+size]</pre><p>Example:<br> Input → [1,2,3,4,5,6] with size=2<br> Output → [1,2], [3,4], [5,6]</p><p><strong>2. Threading:<br></strong>Threading means running multiple tasks concurrently within the same process.</p><p>Useful for I/O-heavy tasks (API calls, DB queries, file reads).<br>Doesn’t create new processes (lightweight).</p><p><strong>3. ThreadPoolExecutor:<br></strong>A thread pool is a collection of threads that are created in advance and can be reused to execute multiple tasks. <br>The concurrent.futures module in Python provides a ThreadPoolExecutor class that makes it easy to create and manage a thread pool.</p><pre>from concurrent.futures import ThreadPoolExecutor<br>executor = ThreadPoolExecutor()</pre><p><strong>4. executor.submit():</strong><br>Schedules a function to run concurrently in a thread.Returns a Future object that can be used to check status or get the result later.</p><p><strong>5. as_completed():</strong><br>Instead of waiting for all tasks, as_completed gives you results as soon as each one finishes.<br>That way, you can start processing fast tasks without waiting for slow ones.</p><p><strong>6. uuid:<br></strong>Each batch gets a unique ID so we can log and debug them individually.</p><pre>import uuid<br>print(uuid.uuid4())<br># Example output: 3fa85f64-5717-4562-b3fc-2c963f66afa6</pre><p><strong>Example — Processing API Records in Parallel</strong></p><p>Imagine an API gives us<strong> </strong>1000 records. We want to process them in batches of 100.</p><pre>import requests<br>import uuid<br>import time<br>from concurrent.futures import ThreadPoolExecutor, as_completed<br><br><br>class RecordChunker:<br>    @staticmethod<br>    def chunk_records(records, chunk_size):<br>        &quot;&quot;&quot;Yield successive chunks of given size.&quot;&quot;&quot;<br>        for i in range(0, len(records), chunk_size):<br>            yield records[i:i+chunk_size]<br><br><br>class BatchProcessor:<br>    def process_records_batch(self, records_batch, batch_id):<br>        batch_success, batch_failures = [], []<br><br>        for record in records_batch:<br>            try:<br>                if record[&quot;id&quot;] % 2 == 0:<br>                    batch_success.append(record[&quot;id&quot;])<br>                else:<br>                    batch_failures.append(record[&quot;id&quot;])<br><br>                print(f&quot;[BatchID={batch_id}] Processed record ID={record[&#39;id&#39;]}&quot;)<br>            except Exception as e:<br>                batch_failures.append(record.get(&quot;id&quot;, &quot;UNKNOWN&quot;))<br><br>        return batch_success, batch_failures<br><br><br>if __name__ == &quot;__main__&quot;:<br>    print(&quot;Fetching dummy data from API...&quot;)<br><br>    records = []<br>    for _ in range(10):<br>        response = requests.get(&quot;https://jsonplaceholder.typicode.com/posts&quot;)<br>        response.raise_for_status()<br>        records.extend(response.json())<br><br>    print(f&quot;Fetched {len(records)} records.&quot;)<br>    chunks = list(RecordChunker.chunk_records(records, chunk_size=100))<br><br>    batch_data = [(chunk, str(uuid.uuid4())) for chunk in chunks]<br>    print(&quot;batch data : &quot;,batch_data)<br><br>    total_success, total_failures = [], []<br><br>    with ThreadPoolExecutor(max_workers=30) as executor:<br>        future_to_batch = {<br>            executor.submit(BatchProcessor().process_records_batch, chunk, batch_id): batch_id<br>            for chunk, batch_id in batch_data<br>        }<br><br>        print(f&quot;Submitted {len(future_to_batch)} batches to ThreadPoolExecutor&quot;)<br><br>        for future in as_completed(future_to_batch):<br>            batch_id = future_to_batch[future]<br>            b_success, b_failures = future.result()<br><br>            total_success.extend(b_success)<br>            total_failures.extend(b_failures)<br><br>            print(f&quot;\n [BatchID={batch_id}] Completed&quot;)<br>            print(f&quot;   Success count: {len(b_success)}&quot;)<br>            print(f&quot;   Failure count: {len(b_failures)}&quot;)<br><br>    print(f&quot;Total Success: {len(total_success)}&quot;)<br>    print(f&quot;Total Failures: {len(total_failures)}&quot;)</pre><pre>Output: <br>Submitted 10 batches to ThreadPoolExecutor<br>[BatchID=uuid1] Success=51 | Failures=49<br>[BatchID=uuid2] Success=60 | Failures=40<br>...<br><br>Total Success: 510<br>Total Failures: 490</pre><p><strong>Benefits:<br> → </strong>Cost-effectiveness: Reduced operational costs by optimizing billed execution time.<br> → Enhanced scalability: Ability to efficiently process large-scale input datasets.<br> → Improved observability: Enhanced logging and debugging capabilities with unique identifiers for each batch.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54c028ae9788" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python PEP 8 Guidelines: Python Coding Standards & Best Practices]]></title>
            <link>https://medium.com/@miriyalasurendra99/python-pep-8-guidelines-python-coding-standards-best-practices-8dc5a46bc65a?source=rss-918f081a6ff1------2</link>
            <guid isPermaLink="false">https://medium.com/p/8dc5a46bc65a</guid>
            <dc:creator><![CDATA[Surendra Miriyala]]></dc:creator>
            <pubDate>Sun, 14 Sep 2025 19:34:18 GMT</pubDate>
            <atom:updated>2025-09-14T19:34:18.124Z</atom:updated>
            <content:encoded><![CDATA[<p>A few months ago, our client shared the official Python PEP 8 style guide and asked us to follow these standards in all future development.</p><p>When working on collaborative Python projects, code readability and consistency matter just as much as functionality. While working, I noted a few important points, and recently, I revisited the official PEP 8 guide to refresh and refine my understanding.</p><p>Here’s a simplified list of the key PEP 8 guidelines every Python developer should follow:</p><ol><li><strong>Indentation:<br></strong>a.Basic Indentation<br> Always use 4 spaces per indentation level (not tabs).<br>b.Continuation Lines<br> When a single statement is too long and you break it into multiple lines, Python allows you to use implicit line continuation inside parentheses (), brackets [], or braces {}.</li></ol><pre># Aligned with opening delimiter.<br>result = calculate_sum(num_one, num_two,<br>                       num_three, num_four)<br><br># Add 4 spaces (an extra level of indentation) to distinguish arguments from the rest.<br>def calculate_sum(<br>        num_one, num_two, num_three,<br>        num_four):<br>    print(num_one)<br><br># Hanging indents should add a level.<br>result = calculate_sum(<br>    num_one, num_two,<br>    num_three, num_four)</pre><p><strong>2. Maximum Line Length</strong><br> Keep Code lines under 79 characters for readability. Doc strings &amp; comments limit to 72 characters.</p><p><strong>3.blank lines: </strong><br> a. Surround top-level function and class definitions with two blank lines.<br> b. Method definitions inside a class are surrounded by a single blank line.<br> c. Use blank lines in methods to indicate logical sections.</p><pre>class MyClass:<br>    def method_one(self):<br>        pass<br><br>    def method_two(self):<br>        pass<br><br>    def process_data(data):<br>        cleaned = clean_data(data)<br>    <br>        transformed = transform_data(cleaned)<br>    <br>        return save_results(transformed)</pre><p>Before a top-level class or function definition Always leave 2 blank lines</p><pre>import os<br>import sys<br><br><br>class MyClass:<br>    pass</pre><p><strong>4. Imports:<br> </strong>Imports should usually be on separate lines and should be grouped in the following order:<br> a.Standard library imports.<br> b.Related third party imports.<br> c.Local application/library specific imports.<br>You should put a blank line between each group of imports.</p><pre># Standard library imports<br>import os<br>import sys<br>import datetime<br><br># Third party imports<br>import requests<br>import numpy as np<br><br># Local application/library specific imports<br>from main import main_class<br>from utils.helpers import process_data</pre><p><strong>6. Naming Conventions:</strong><br> a. Class names should normally use the CapWords convention.<br> b. Functions and variable names should use lowercase_with_underscores.<br> c. Constants should be written in ALL_CAPITAL_LETTERS with underscores separating words.</p><pre># Class name (CapWords)<br>class StudentProfile:<br>    pass<br><br><br># Function and variable names (lowercase_with_underscores)<br>def calculate_total_marks(marks_list):<br>    total_marks = sum(marks_list)<br>    return total_marks<br><br><br># Constant (ALL_CAPS with underscores)<br>MAX_STUDENT_LIMIT = 50</pre><p><strong>7. Docstrings:</strong><br> Write docstrings for all public modules, functions, classes, and methods,<br> Not required for non-public methods (_method), but use a comment instead.<br> <strong>a. One-line docstrings: </strong>keep opening and closing on the same line.</p><pre>def get_version():<br>    &quot;&quot;&quot;Return the current version of the application.&quot;&quot;&quot;<br>    return &quot;1.0.0&quot;</pre><p><strong>b. Multi-line docstrings:<br></strong> Place the opening “”” on its own line and the closing “”” on its own line as well.</p><pre>def process_data(data):<br>    &quot;&quot;&quot;<br>    Process the input data and return cleaned results.<br><br>    This function removes null values, applies transformations,<br>    and returns the processed dataset.<br>    &quot;&quot;&quot;<br>    pass</pre><p><strong>8. Comments:<br> → </strong>Comments must always be up to date with the code. Wrong comments are worse than no comments.<br> → Write comments as complete sentences, starting with a capital letter (unless it’s a variable name).<br> → Keep comments clear and easy to understand.</p><p><strong>a.Block Comments<br> </strong>Start each line with # + space and Use blank # lines to separate paragraphs.</p><pre># Calculate the area of a circle.<br># Formula: π * r^2<br>area = 3.14 * radius ** 2</pre><p><strong>b.Inline Comments<br> </strong>Place them on the same line as code, with 2 spaces before #.</p><pre>x = x + 1   # Compensate for zero-based index</pre><p><strong>By following these PEP 8 guidelines, we can achieve the following:<br>Readability :</strong> Code becomes easy to read and understand.<br><strong>Consistency :</strong> Everyone on the team writes code in the same style, making collaboration smoother.<br><strong>Maintenance :</strong> Clean and structured code is easier to fix, change, and update in the future.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8dc5a46bc65a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>