<?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 David Jetelina on Medium]]></title>
        <description><![CDATA[Stories by David Jetelina on Medium]]></description>
        <link>https://medium.com/@DJetelina?source=rss-4e3c0bfa0881------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*OrjtGWlx3JtxHWtIcpfvsg.jpeg</url>
            <title>Stories by David Jetelina on Medium</title>
            <link>https://medium.com/@DJetelina?source=rss-4e3c0bfa0881------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 17:10:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@DJetelina/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 a Python library — how the ecosystem changed in 2.5 years]]></title>
            <link>https://medium.com/@DJetelina/making-a-python-library-how-the-ecosystem-changed-in-2-5-years-a3b5eb16d7df?source=rss-4e3c0bfa0881------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3b5eb16d7df</guid>
            <category><![CDATA[packaging]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[David Jetelina]]></dc:creator>
            <pubDate>Tue, 18 Dec 2018 14:08:43 GMT</pubDate>
            <atom:updated>2018-12-18T14:08:43.931Z</atom:updated>
            <content:encoded><![CDATA[<h3>Making a Python library — how the ecosystem changed in 2.5 years</h3><p>I created my first python library in August 2016, mostly to learn how to make one — not just writing setup.py, but also to have docs to maintain, possibly users to make happy, crafting a README — everything that comes with the territory.</p><p>Maybe there were better ways back then, but let’s establish it as a baseline. Here’s a screenshot of the <a href="https://github.com/iScrE4m/pyCardDeck">repository</a>’s file layout and top of the README:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*AIn8Z02ZdybemqZ4mYx_yg.png" /></figure><p>Hopefully nothing far too surprising. Docs, examples, tests, some static analysis, packaging, dependencies, CI for supporting multiple python versions, setup.py bdist upload…</p><p>This is what I was ultimately happy with, however getting there was needlessly painful.</p><p>Recently I finally managed to find a reason to create another package (let’s ignore some abandoned projects and non opensource stuff). Compared to the first time, I now had not only previous experience, but I also had news to play with, that I wanted to test out. I was looking forward to leveraging PEP 518 (pyproject.toml) to build a package without most of the hassle, with a CLI to help me along the way. Here’s how it went.</p><h4>Poetry</h4><p>I have already replaced requirements.txt everywhere with <a href="https://medium.com/@DJetelina/pipenv-review-after-using-in-production-a05e7176f3f0">Pipenv</a>, but if you’ve been following the tools a little bit, you know that Pipenv is application only and doesn’t support multiple Python versions (at least not without hacking around a little bit) and Poetry was always named as it’s biggest competition, so I was really looking forward to trying it out and it <strong>did not disappoint</strong>. I am not a fan of the default file layout it generates for you, but if it ain’t broke… And it wasn’t, everything worked. Poetry is a huge improvement and makes it way easier to create your first python package.</p><p>Conclusion: <strong>BETTER</strong></p><p>However, PEP 518 (and/or PEP 517) is not fully supported by the rest of the ecosystem just yet, which essentially meant quite a few things changed when it came to other tools.</p><h4>Tox</h4><pre>whitelist_externals = poetry<br>skip_install = true<br>commands =<br>    poetry install -v<br>    poetry run pytest tests/</pre><p>After looking up the solution you see above, tox wasn’t much of an issue, but it defintely doesn’t feel right. Thankfully next pip release already has a fix for this implemented!</p><p>Conclusion: <strong>SAME</strong> (in a couple of days)</p><h4>Read the Docs</h4><p>Unfortunately, until issue <a href="https://github.com/rtfd/readthedocs.org/issues/4912">4912</a> on their github is resolved, there is no way to build a documentation of a python package without requirements.txt and setup.py , so an additional dependency you have to remember to keep updated is needed. It’s called <a href="https://github.com/orsinium/poetry-setup">poetry-setup</a>.</p><p>Oh and you know how there’s new Python versions, would you like to build your docs under python3.7, you know as Sphinx requires you to actually import the code? Only with <a href="https://github.com/rtfd/readthedocs.org/issues/4713#issuecomment-448074525">conda</a>. What about 3.6? Let me introduce you to .readthedocs.yml which you probably never knew even existed despite using RtD for a long time. You’ll need to put inside this:</p><pre>build:<br>  image: latest<br>python:<br>  version: 3.6<br>  setup_py_install: true</pre><p>Conclusion: <strong>WORSE</strong></p><h4>Travis CI</h4><p>Of course you’d like your CI to run tests on the newest Python version, perhaps more than on some old version. Well, you can, but it’s not as simple as adding 3.7 to the list of supported pythons in your configuration yaml file. You have to be explicit about linux distro and require sudo in the job: <a href="https://github.com/travis-ci/travis-ci/issues/9069#issuecomment-425720905">https://github.com/travis-ci/travis-ci/issues/9069#issuecomment-425720905</a></p><p>Just a fun fact, Xenial is not even the newest LTS of Ubuntu, so expect this explicit dist requirement to eventually break, possibly before April 2021 when it’s LTS support ends.</p><p>Conclusion: <strong>WORSE</strong></p><h4>Sphinx</h4><p>The golden standard of writing python docs. Maybe it’s just me, but Sphinx isn’t aging well. The problem is when I wrote this down as a note, I didn’t write down what exactly made me feel that way and if I can guess what it was. Perhaps it was type hints not really being natively supported. Or the overall feel of a tool that isn’t made for this decade (darn you my millennial-ish brain). Maybe it was me really wanting a theme that supports both light and dark theme. Possibly just me being bad with autodoc. And then there’s the possibility that I just see Read the Docs and Sphinx as a single tool and I’m just taking it out on Sphinx.</p><p>My point is, docs are hard. And it didn’t get any better. At least not with Sphinx.</p><p>Conclusion: <strong>WORSE</strong> (or at least my notes said so, for whatever reason)</p><h4>Reno</h4><p>This is an odd one, I bet the vast majority never heard of Reno and I wouldn’t either if I didn’t attend a talk about it at EuroPython 2018. Reno stands for Release Notes and it’s part of OpenStack, in a way.</p><p>In my previous package, there’s no changelog. And changelogs are cool — or at lest I like reading them. Reno makes it… Not so painful? Make kind of sense? I recommend watching the <a href="https://www.youtube.com/watch?v=tEOGJ_h0Lx0">talk</a> about it if you’re interested in learning how it works, I’ll just relay my experience. Huge tl;dw is: Through git tags and history it keeps track of special generated yaml files that have lists of ReST text under different keys — this can then be nicely integrated with Sphinx. And that’s why I didn’t experiment with Sphinx alternative this time — I really wanted to try it out. And it was good. Apart from writing ReST inside of YAML file. There are some quirks, but I quite enjoy maintaining a changelog now.</p><p>Conclusion: <strong>COOL</strong></p><p>And that’s about it. If you are wondering what package I experienced this all with, it’s called <a href="https://github.com/iScrE4m/pyArtifact">pyArtifact</a> (how original and totally not ambiguous! 🤫). Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3b5eb16d7df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pipenv review, after using it in production]]></title>
            <link>https://medium.com/@DJetelina/pipenv-review-after-using-in-production-a05e7176f3f0?source=rss-4e3c0bfa0881------2</link>
            <guid isPermaLink="false">https://medium.com/p/a05e7176f3f0</guid>
            <category><![CDATA[pipenv]]></category>
            <category><![CDATA[packaging]]></category>
            <category><![CDATA[programmin]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[review]]></category>
            <dc:creator><![CDATA[David Jetelina]]></dc:creator>
            <pubDate>Tue, 15 May 2018 01:42:32 GMT</pubDate>
            <atom:updated>2018-05-15T17:57:08.278Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*PPIp7twJJUknfohZqtL8pQ.png" /></figure><p>If you are not subscribed to /r/Python on reddit, you’ve probably missed <a href="https://www.reddit.com/r/Python/comments/8jd6aq/why_is_pipenv_the_recommended_packaging_tool_by/">this</a> thread discussing the current state of <a href="https://github.com/pypa">Python Packaging Authority</a>, <a href="https://github.com/pypa/pipenv">pipenv</a> and <a href="https://github.com/sdispater/poetry">poetry</a>. It wouldn’t be all that interesting, if it wasn’t for the involvment of both authors of pipenv and poetry and PyPA representative. If you don’t mind looking through piles of emotions to find some interesting points, go ahead and read it.</p><p>The current state of python’s packaging is awful, I don’t think there’s anyone who could disagree with that. This problem is recognized and there are many attempts at trying to solve the mess. Pipenv was the first and it has gained a lot of traction, however it doesn’t sit well with everyone. And it’s also not suited for every project — like libraries.</p><p>I’ve been using Pipenv for quite a while now and I managed to introduce it to our team’s codebase. We’ve been working with Pipenv since around November 2017, I personally created my first issue on it’s GitHub back in May 2017 and here’s my experience:</p><h4>The multiple environment problem</h4><p>As issue number <a href="https://github.com/pypa/pipenv/issues/368">#368</a> I first started discussing multiple environments (e.g. Python 2.7 next to 3.6 for tests). I resolved my use case, but the issue is still being somewhat actively discussed through issue <a href="https://github.com/pypa/pipenv/issues/1050">#1050</a>. The tl;dr is — supporting multiple environments goes against Pipenv’s (therefore also Pipfile’s) philosophy of deterministic reproducible <strong>application</strong> environments. So if you want to use Pipenvfor a library, you’re out of luck. That means many projects just can not use Pipenv for their dependency managment.</p><p>The longer version shows Kenneth Reitz (an amazing part of the Python community and my personal inspiration) being stark and not very open to the community’s needs . I recommend <a href="https://github.com/pypa/pipenv/issues/1050">reading the issue #1050</a> completely, to make an opinion for yourself. While his approach can be understood, it also helps understand why some people look at Pipenv with poor taste in their mouth. As much as I hate to, there’s no way to review Pipenv without commenting on it’s author and I apologize in advance, I’ll mention Kenneth again.</p><h4>The stability problem</h4><p>Unfortunately more than once, I came to work to see failed tests, that ran just fine the day before. And it was almost always Pipenv causing the issues. While the team was almost always very quick to fix the issues, if we were to encounter a critical bug in production and to deploy a hotfix, our CI’s would be failing and we’d have lost time identifying the issue and having to lock Pipenv to a previous version hoping it would work then.</p><p>If those were honest mistakes in a proper release process, I wouldn’t be too harsh, however it’s the release process that’s at fault here. Because there is none. Kenneth (here goes the second mention) fairly often goes on commit streaks in master branch, releasing along the way. We’ve all been there, having ten commits in a row fixing or reverting previous changes. However, not many of us are maintaining a <a href="https://github.com/pypa/pipenv">GitHub project</a> with almost 11 000 stars, a project with 170 000 downloads per month, a project officially recommended by python.org. That is quite a few people relying on the tool and as we all know: “With great power…”.</p><p>Next time another problem like this occurs, I’ll just pin Pipenv to a last working version, which I should have maybe done from the start, and leave it until I’m forced to update.</p><h4>The good</h4><ul><li>Pipfile and Pipfile.lock really are superior to requirements.txt. By a ton.</li><li>While I disliked it at first, having flake8 and security check builtin in a single tool is great</li><li>Installing (exclusively) from a private respository works very well. Instead of replacing a dotfile somewhere in the system, specifying the repository in Pipfile is great</li><li>Creating a new Pipfile is very easy</li><li>No problems introducing Pipenv to it’s new users</li><li>No problems installing from a mixture of indexes, git repositores…</li><li>With --sequential it is actually deterministic, as advertised</li><li>Virtualenv is much easier to get into and understand</li><li>Dependencies can be installed into system (e.g. in Docker) — our case.</li><li>At no point did anyone in the team even mentioned getting rid of Pipenv — which is a lot better than it sounds</li></ul><h4>Conclusion</h4><p>Pipenv is not perfect and I don’t know if it’ll ever be, but I’ve been happy with it and I do recommend it to other teams. However, I don’t think pipenv is the goal.</p><p>We as a community need a tool that works for both libraries and applications. Something that Pipenv specifically does not want to be. The last thing the python community needs is choice (2vs3). As Zen of Python says: “There should be one — and preferably only one — obvious way to do it.”. If we end up with multiple tools for multiple purposes, people will find a way to abuse all of them to do all of it anyway and things won’t be pretty.</p><h4>… what about Poetry?</h4><p>I wish I knew. I haven’t had much time to experiment since I started working on our team’s current (GDPR related) project. It does look exciting though!</p><h4>Edit:</h4><p>A very interesting and mostly constructive discussion was born under this article on reddit (<a href="https://www.reddit.com/r/Python/comments/8jhtkh/pipenv_review_after_using_it_in_production/">here</a>). I’ll edit in the “best of”, but since I’m human, therefore imperfect, I’d recommend you to go ahead and <a href="https://www.reddit.com/r/Python/comments/8jhtkh/pipenv_review_after_using_it_in_production/">read it</a> yourself :).</p><ul><li>Some applications are intended to run under multiple python environments too, like CLI apps, GUI-based apps and others. I am a backend developer, therefore my view on Application vs Library is flawed by that perspective. Those applications are out of luck as much as libraries when it comes to using pipenv. (credit to <a href="https://www.reddit.com/r/Python/comments/8jhtkh/pipenv_review_after_using_it_in_production/dz0f5k1/">kurashu89</a>, <a href="https://www.reddit.com/r/Python/comments/8jhtkh/pipenv_review_after_using_it_in_production/dz0joj2/">kihashi</a> and <a href="https://www.reddit.com/r/Python/comments/8jhtkh/pipenv_review_after_using_it_in_production/dz0ldpt/">dirn</a>)</li><li>setuptools and the rest of the already existing tools can already do pretty much everything the tools that will come after it. What the previous tools do not excel at is frendliness, barrier of entry, knowledge barrier.</li><li>Pipenv has a lot more flaws than I highlighted in this review, but I didn’t list them because they didn’t bother me as much. Mainly because many of those are not set in stone, or are being worked on actively.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a05e7176f3f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The mystery of DevOps]]></title>
            <link>https://medium.com/@DJetelina/the-mystery-of-devops-2bbc0dc0104b?source=rss-4e3c0bfa0881------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bbc0dc0104b</guid>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[David Jetelina]]></dc:creator>
            <pubDate>Wed, 22 Nov 2017 17:57:11 GMT</pubDate>
            <atom:updated>2017-11-22T17:57:11.275Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first heard the word DevOps, it meant a position in a team. Somebody, who is there to take care of the configurations and deployment etc., but still is part of a development team. From there on, my mind was slightly adjusting what the position meant and I grew closer and closer to the idea of being DevOps.</p><p>I am the type of developer that goes on the wild roads of discovering new technologies. Hey guys, here’s our first Docker image, this is how we build it, this is our future. Hey guys, this is what I’ve learned about Kubernetes and this is how I’m using it. Hey guys, I did a thing on our Jenkins server. Hey guys, here’s how we will deploy our docker images to the shared development environment.</p><p>And so I thought — “I am 60% DevOps, 40% programmer in my current position. Sometimes I miss writing code, but this is fun too. Maybe in future, I might look into DevOps positions instead of programming. Let me see what people expect from DevOps outside of my team.” The first thing to do — google it!</p><h4>Let’s google — “What is DevOps”</h4><p>The very first google hit has an excerpt starting with:</p><blockquote>DevOps is a term for a group of concepts</blockquote><p>Wait, what? Are my positions just a concept? Weird. Later in that same article <a href="https://theagileadmin.com/what-is-devops/">here</a> is:</p><blockquote>DevOps is the practice of operations and development engineers participating together in the entire service lifecycle, from design through the development process to production support.</blockquote><p>Great, now DevOps is the cooperation between developers and sysadmins itself? So, no position for me to apply for? Now my mind starts to wander.. is there a DevOps-master, same like Scrum-master position maybe? Let’s read on (the highlighted text only, you know, we’re living in a fast age):</p><blockquote>DevOps is also characterized by operations staff making use many of the same techniques as developers for their systems work.</blockquote><p>So is it just sysadmins becoming more agile? I obviously needed to do more thorough research. My first draft of this article contained the whole journey, but it was too boring. For every article/person discussing the subject, there is a slightly different opinion.</p><h4>Conclusion?</h4><p>While there seems to be an increase of DevOps positions opened, it looks like DevOps really shouldn’t be about a position. Some people claim that DevOps position goes against the DevOps philosophy. Interesting, huh? So it seems like instead of looking for a position in DevOps, I should be widening my skills, reaching more into ops and understanding ops and all of that should be focused on business, so I can make my company more money.</p><p>I can’t really draw a conclusion from this statement though. I have no idea where my first view, on what DevOps is, came from. After spending few hours researching the topic, I am not much smarter than I was before.</p><p>I have two personal takeaways:</p><ol><li>I will stop using the term DevOps, it has a different meaning to different people. I’ll be explicit in what I mean instead.</li><li>I already did a bit, but even more so now — I will shift my developer mindset. Networking etc. are not something I’m supposed to deal with, but I will not shield myself from it. I will embrace it, because development is becoming (the more experienced I get) less and less about writing code and is far more complex and far-reaching, than “it works on my machine”.</li></ol><p>The second takeaway is a tough one. In my surroundings I see a shift towards — “You shouldn’t care where your application will be running, just create a container” or “X as a service” — but those providing these services (Kubernetes, ELK, OpenStack) also subconsciously expect you to understand how their infrastructure works. When you are using anything as a service, you only get to experience it as a user. Maybe that’s just my surroundings, but it’s a trap that will be hard not to fall into.</p><p>If you have any thoughts you’d like to share, please do! This is a cry for help from a guy who gets lost everytime he wanders into the “woods”.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bbc0dc0104b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programmer Tim and new things.]]></title>
            <link>https://medium.com/@DJetelina/programmer-tim-and-new-things-a2236d3b6cca?source=rss-4e3c0bfa0881------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2236d3b6cca</guid>
            <category><![CDATA[team-collaboration]]></category>
            <category><![CDATA[team-building]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[David Jetelina]]></dc:creator>
            <pubDate>Tue, 22 Aug 2017 08:54:16 GMT</pubDate>
            <atom:updated>2017-08-22T08:54:16.520Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<p>Once upon a time, in a parallel dimension, there was a developer called Tim. In Tim’s world, databases were relatively new and cool, they were not yet adopted by the majority. Up to this point, his company was using files to store all the data — files like csv, or just individual files for each record using the path to give the data structure.</p><p>One day, Tim was told that they needed to set up a database, not for the whole project, but for this one small part. He was the most likely to enjoy exploring something new, so he dove into it. Quite obviously, he liked the idea of databases. When he was done with his assignment, he knew that the idea had potential and he couldn’t wait to tell the rest of the team so they could start using it. To his surprise, nobody in his team was really interested in them. So whenever a database related issue came up, he was the one to deal with it.</p><p>After months of being annoying, saying how databases are amazing, there turned out to be another use case for databases and his superior decided that it’d be nice if more things started using databases, so finally the green light lit up. Tim thought :</p><blockquote>I can’t wait for others to offer me their point of view once they understand the concept! We can surely improve the way I did things!</blockquote><p>So he began mentoring each of team members on databases, everyone had their task assigned and he was there to teach them on that assignment. For some reason though, not everyone wanted to work on it right away and when they did, they didn’t care to learn about the technology, they just wanted to finish it and move on to their familiar territory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EKdJm45N99F_XJ9UKJC7Yw.jpeg" /></figure><p>When everything was done, Tim was disappointed, he didn’t get any new insights from his colleagues, nobody even tried to improve on the way he did things. They took his word for granted, did it just the way he suggested they do it and that was that. Months passed and Tim was swamped by different tasks that would last for quite a while while new ticket appeared saying something needs to be done with databases. Everyone avaoided that ticket, they wanted Tim to do it when he will be able to. When Tim asked why won’t they try and to it, they tried to be funny, saying that they are using databases just because they are new and that they seriously don’t see any advantages over csv files.</p><p>Being Tim sucks. And it’s not just new technologies. We as developers need a bit of confrontation of our views, we know that our way most likely isn’t the most optimal and that every point of view might bring something useful. So when you as a team do something, don’t let one person be the only person to do it. Don’t depend, challenge his views and move forward — as a team.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2236d3b6cca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python and Chunked transfer encoding]]></title>
            <link>https://medium.com/@DJetelina/python-and-chunked-transfer-encoding-11325245a532?source=rss-4e3c0bfa0881------2</link>
            <guid isPermaLink="false">https://medium.com/p/11325245a532</guid>
            <category><![CDATA[https]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[wsgi]]></category>
            <dc:creator><![CDATA[David Jetelina]]></dc:creator>
            <pubDate>Wed, 16 Aug 2017 18:40:14 GMT</pubDate>
            <atom:updated>2017-11-08T14:41:51.496Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<h4>Update</h4><p>Problem solved in upcoming uWSGI release, yay!</p><h3>Armin Ronacher on Twitter</h3><p>Good news: automatic chunked input handling based on wsgi.input_terminated in uwsgi is incoming! https://t.co/1FJdrtQI8D</p><h4>Original</h4><p>The best way to tell my story is to tell you what my day looked like. I recently implemented a <a href="https://medium.com/@DJetelina/what-is-rpc-and-how-it-works-c0749a6562db">RPC handler</a> in Flask — today was the day we were finally deploying it to production. Everything worked great in development environment, so I was mostly looking forward to it being out there, I was proud.</p><p>Then sysadmin showed me an error in the log that I haven’t seen before.</p><pre>RuntimeError: Parser error: &lt; XML_ERR_DOCUMENT_END &gt;</pre><p>Panic. SOMETHING IS WRONG. WHY IS THIS ALWAYS HAPPENING TO ME! Yes, the RPC we use is a bit different from classic XML-RPC, but should be compatible, so I expected things to be very similiar. Well they weren’t. At first I suspected the caller that they have something different in production config, as it wasn’t our call of the RPC that caused this.</p><h4>request.data</h4><p>After few hours of tring out different things, I learned that flask.request.data was empty, because the content-type wasn’t known to it. How did this not happen in dev? Well the library calling it is smart and remembers from previous response if it the server can accept this content-type - it might have happened, but we didn’t see the error and the library adjusted, leaving us thinking it was working.</p><p>Simple fix right? Flask puts the raw body into request.stream a file-like object — surely we can read from a file right? WRONG!</p><h4>Content-Length</h4><p>Fast forward about 4–5 hours of me asking all the people for help and always coming out with request.stream empty we found out that werkzeug (a layer below Flask) has this cute thing in it:</p><pre><em>if </em>content_length <em>is None</em>:<br>    <em>return safe_fallback and </em>_empty_stream <em>or </em>stream</pre><p>Great. So our libary is not sending Content-Length header with the request right? Let me just file an issue… Nope, it was pointed out to me that there’s this wizardry chunked transfer encoding going on and that it doesn’t use Content-Length, as it’s sending the body chunk by chunk and that there has to be another way to do this. Easy for them to say this right? Their handler for aiohttp was working perfectly.</p><h4>wsgi.input_terminated</h4><p>If I was paying more attention I’d notice the line above the return empty stream one:</p><pre><em>if environ</em>.get(<strong>&#39;wsgi.input_terminated&#39;</strong>):<br>    <em>return </em>stream</pre><p>But things aren’t that simple with me, I had to google for quite a while, find a proposal for this to be implemented in werkzeug, then I facepalmed. Easy then! Let’s just set that to True and get the stream. Except that all the stream is is environ[‘wsgi.input’] from which I’ve already tried reading and came up short-handed. I had to find something that supports input_terminated.</p><p>I’ll save you the search. <a href="https://twitter.com/mitsuhiko/status/888511038265716742">Here’s a funny twitter thread</a> that’s not that old (21st July) by Armin Ronacher (Creator of Flask), David Lord (maintainer of Flask) and Graham Dumpleton. If you don’t want to read it, here’s tl;dr:</p><blockquote>Never became adopted</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g-_Ckwj6uZ4dd_lBLgwT5Q.jpeg" /></figure><p>So how did I deal with this? I decided to go around Flask and Werkzeug, locked myself into uWSGI (until I figure out how to do it others) and just used uwsgi.chunked_read() to retrieve the request body. But I have the feeling that something that’s a part of HTTP1.1 specification should not be this problematic. I am still not exactly which technology is to blame, but let’s deal with this, shall we? Tell me how I can help and let’s do this.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11325245a532" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is RPC and how it works]]></title>
            <link>https://medium.com/@DJetelina/what-is-rpc-and-how-it-works-c0749a6562db?source=rss-4e3c0bfa0881------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0749a6562db</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[rpc]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[explanation]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[David Jetelina]]></dc:creator>
            <pubDate>Thu, 27 Jul 2017 08:00:10 GMT</pubDate>
            <atom:updated>2025-01-07T13:40:36.525Z</atom:updated>
            <content:encoded><![CDATA[<p>When I got my current job, it didn’t take long for me to meet something called ‘fastrpc’ which is a technology my company <a href="https://github.com/seznam/fastrpc">open-sourced</a> (if you clicked be warned, it’s not the most friendly repository, or technology for that matter). It’s XML-RPC, but sent in binary, therefore fast. As a junior I understood neither of those words, so I was just content with considering it magic and focusing on the important.</p><p>So if you don’t know what any of this means, good! I’ll try and explain. RPC stands for Remote Procedure Call, to put it in our human language, it lets you call a function that you yourself didn’t define anywhere, on someone else’s server.</p><pre>&gt;&gt;&gt; magical_server.add(3, 4)<br>7</pre><p>The XML is there just to tell you what structure it uses to communicate. So while you think you might be calling a function add, in reality that is not what’s going on and you’re just somehow sending some XML. In case of JSON-RPCit’s JSON, FastRPC sends XML in binary and gRPC can support multiple things. Yes, it is just an alternative to communicating via REST API.</p><p>So how does it work? I wanted to have our FastRPC server run on something else than C metaserver-thingy which somehow injected itself into python and ran it, only supporting Python 2… And some folks made it work in Python frameworks Tornado and Aiohttp. Yes, that is correct, RPC uses HTTP to communicate, so any website can also be a RPC server — brilliant. As a Flask lover, without any need for async (that’s what Tornado and Aiohttp are for the non-pythonistas), I decided to write (copy and edit from aiohttp) a FastRPC server extension for Flask. Let’s dissect it and see what’s really happening.</p><p>Function handle() is what we are interested first, this is where incoming HTTP request comes in:</p><pre>accept_cts = self._get_accepted_content_types()<br>if not accept_cts.intersection(self.allowed_content_types):<br>    logging.warning(&#39;No supported content type requested: &quot;%s&quot;&#39;, accept_cts)<br>    return &#39;Content types in Accept not supported&#39;, 400</pre><pre>if request.headers[&#39;Content-Type&#39;] not in self.allowed_content_types:<br>    logging.warning(&#39;Content-Type &quot;%s&quot; is not supported&#39;, request.headers[&#39;Content-Type&#39;])<br>    return &#39;Content-Type not supported&#39;, 400</pre><pre>if fastrpc:<br>    args, method_name = fastrpc.loads(request.data)<br>else:<br>    args, method_name = xmlrpc.loads(request.data)</pre><pre>logging.info(&#39;Calling method %s with args: %s&#39;, method_name, args)</pre><pre>return self._create_response(method_name, args, accept_cts)</pre><p>Let’s try and not go to deep, judging from the method name and log message, we can assume that _get_accepted_content_types takes a loot at the incoming request and reads what the client says he’s gonna accept. I should now mention that I made the extension work without our internal fastrpc and that fastrpc itself is capable of handling XML-RPC. So there is a HTTP request with Accept header.</p><p>Then there’s Content-Type header — that probably tells us what type of data we should be reading. Good. Easy peasy so far, classic HTTP.</p><p>Hmm, fastrpc.loads() and xmlrpc.loads() doesn’t look like rocket sciente either. It’s just going to go through the data of the request and extract arguments and name of the method from the XML. So some XML parsing… Wait, is that it? Do we just then call the method with the arguments and return it back? Surely the magic I always thought this is must be somewhere!</p><p>This is the interesting part of _create_response :</p><pre>headers = {}<br>if FRPC_CONTENT_TYPE in accept_cts and fastrpc:<br>    use_binary = True<br>    headers[&#39;Content-Type&#39;] = FRPC_CONTENT_TYPE<br>else:<br>    use_binary = False<br>    headers[&#39;Content-Type&#39;] = RPC_CONTENT_TYPE</pre><pre>if fastrpc:<br>    body = fastrpc.dumps((response,), methodresponse=True, useBinary=use_binary)<br>else:<br>    body = xmlrpc.dumps((response,), methodresponse=True)</pre><pre>headers[&#39;Content-Length&#39;] = str(len(body))<br>resp = Response(body, headers=headers)<br>return resp</pre><p>So, if we have fastrpc and they accept fastrpc… Yeah that’s not interesting for our explanation of RPC servers. So we will return header with Content-Type we will be returning, okay. We will then dump our response into XML, sure. Then we’ll see what the Content-Lenth is and add that to the header and… That’s it. That’s RPC. No magic to be seen here. Now you hopefully understand.</p><blockquote>Congratulations! This pre-recorded congratulations assumes you have mastered the principles of porta… RPC.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0749a6562db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How change keeps me productive]]></title>
            <link>https://medium.com/@DJetelina/how-change-keeps-me-productive-618cdaefe56b?source=rss-4e3c0bfa0881------2</link>
            <guid isPermaLink="false">https://medium.com/p/618cdaefe56b</guid>
            <category><![CDATA[change]]></category>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[David Jetelina]]></dc:creator>
            <pubDate>Tue, 25 Apr 2017 02:03:39 GMT</pubDate>
            <atom:updated>2017-04-25T02:42:07.153Z</atom:updated>
            <content:encoded><![CDATA[<h4>What a great realization!</h4><p>I thought that when I play around with my shell, IDE, when I go out and explore new ways to do things, I’m mostly just procrastinating while maybe learning a little bit more. I often say:</p><blockquote>Every now and then it’s okay to spend an hour or two on my company’s time playing around with my configs, because it’s a long-term investment.</blockquote><p>But isn’t it just the lazy part of me manipulating myself into doing less work?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*14ivod80V-9jE52JtcgZ9w.jpeg" /><figcaption>What does this setting do? Oh that’s cool!</figcaption></figure><p>Today, my colleague went on a holiday for two weeks and I realized I could borrow his monitor. That means I spent about 15 minutes setting it up so it would be comfortable, then I remembered I wanted to try multiple workspaces on Ubuntu and after a while I had 12 screens over 4 workplaces to play around with. Pretty big difference compared to two screen at one workplace and loads of alt-tabbing.</p><p>And I know what you’re probably thinking, I too also read somewhere on the internet that more monitors don’t actually make you productive, because of X, Y and Z — but that’s not my point. I’m not trying to say that me having an additional monitor increased my productivity (even though it might have).</p><p>It was the act of change. When I’m trying something new, I usually want to play around with it and test it out. See if it fits me, if the learning curve is okay to get used to it, if it really is more comfortable</p><p>So I started working for a bit with my new setup and hours passed by and I had to go home. As I was leaving I realized that I did a lot more than I would have if nothing new had happened. Things started feeling fresh again, keeping me on my toes, forcing me to focus. And then it hit me.</p><p>I know it’ll be just as good tommorow, because the same thing happened when I tried zsh instead of bash, when I tweaked my PyCharm a bit, changed a few colors, automated something that was getting tedious, updated X to a new version… It has happened so many times before and it will happen again. I want to work more, I enjoy working more, when I see something new on the horizon — a brighter future. Even though it doesn’t always lead to the brighter future, very often the new thing I invest time into setting up turn out to be better than what I had before.</p><p>I recently learned, that I’m a very different personality type than most of my colleagues, so this isn’t a life advice — but if you’re anything like me, please let me know, what do you do to keep things fresh?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=618cdaefe56b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>