r/Kotlin • u/NathanFallet • Jul 06 '25
From Python to Kotlin: Why We Rewrote Our Scraping Framework in Kotlin
From Python to Kotlin: Why We Rewrote Our Scraping Framework in Kotlin
When it comes to web scraping or browser automation, most people think of Python. We did too. It’s the go-to choice: widely adopted, quick to write, and supported by tons of libraries.
But using Python for a large scraping project turned out to be a mistake.
What Went Wrong With Python?
Although Python seems easy to write, maintaining a large codebase in it was a mess. We constantly ran into issues with typing, like the infamous:
'NoneType' object has no attribute 'xxx'The most painful issue, however, was related to asyncio and event loops. Part of our code needed to run on Windows (which may sound like a strange choice, but it actually helped us bypass bot detection — something far trickier on Linux).
That’s where Python’s Proactor event loop on Windows became a problem. Some system calls, even when used with async, would block the event loop entirely, tanking performance.
After spending countless hours debugging, we started questioning our choice of language.
Why not switch to something we actually enjoy working with? Something we already used elsewhere.
Why Kotlin?
All our backends and most other components were already written in Kotlin. We had even created zodable, a library that exports Kotlin models to Python using Pydantic. But it wasn’t enough.
Typing and concurrency feel way more natural and robust in Kotlin.
Personally, I love Kotlin because it’s a language designed with safety in mind. With static typing, null safety, and now upcoming rich compile-time errors, it catches problems before they reach production. Most bugs are surfaced at compile time. A massive win for developer productivity and app stability.
Compare that to Python or TypeScript, where you often don’t discover issues until the code is already running (if you’re lucky enough to catch them at all).
That’s why Kotlin is now my first choice for any new project, whether it’s a backend service, mobile app, or even… a web scraper.
Rewriting the Project in Kotlin
So, we went all in: we rewrote everything from scratch in Kotlin.
In just five days, we ported the entire library we had in Python. The result? No more concurrency headaches, and we caught a bunch of hidden bugs thanks to Kotlin’s type safety. Bugs that were silently lurking in the Python code and would’ve only surfaced at runtime.
It was such a success that we decided to open-source the core framework: kdriver, a browser automation and scraping library, written entirely in Kotlin.
Kotlin Beyond Mobile & Backend
Kotlin is growing fast. It started with Android, then spread to backends with Ktor, serialization, coroutines. And now we’re seeing it expand to new domains like: AI with Koog, scraping and automation with kdriver, and much more!
I dream of a world where Kotlin is the default for every serious project, not just mobile apps. A world without JavaScript outside of browsers. A world where you don’t need to worry about NoneType errors or untyped chaos.
Just Kotlin. Clean, safe, and multiplatform.
2
u/MrJohz Jul 06 '25
Here's a hint: if the sites you're scraping don't want you scraping them, maybe try not bypassing their bot detection systems and just respect their wishes? Presumably you're ignoring robots.txt as well?
It's nice that Kotlin makes it more convenient for you to waste other people's bandwidth and resources, but I'm struggling to sympathise much with your plight here.
1
u/Blakesly Jul 10 '25
This is very cool. currently, I'm using Playwright with Rebrowser, and for the most part, it's working well enough.
I'm not very knowledgeable about the topic, but what is motivation for making open source? From my understanding, the more people who use it, the more websites are going to try to update against it, leading to more work/cost for you.
Regardless, awesome project and will be giving it a go.
1
u/BeyondBlunders Apr 20 '26
I’m honestly not surprised. Concurrency in Python sucks. Bad isn’t even a good word to describe it. You can spend a lot of time on it and get it to work, but it simply isn’t a first class citizen in the was concurrency is handled in Kotlin.
-5
u/flavius-as Jul 06 '25
This reads to me like this:
We were incompetent on Linux, so we had to do it on windows with bad tooling with the hope that our incompetence would get masked by tools, only to figure out that moving to another tool (kotlin instead of python) will solve all our problems yet again.
Now I get it: kotlin is great and it's better for the reasons you mentioned.
But you haven't solved the core of the problem: the competence.
The very same root cause will come bite you again. You might be able to drag this out. Maybe a year, maybe two.
But a refactor is coming even in kotlin. Python just surfaced the root cause faster.
!Remindme 2 years
0
u/[deleted] Jul 06 '25
[deleted] — view deleted comment