Do you want to look inside your Django requests?
How about all of your requests in development and see where they overlap?
If that sounds useful, you should definitely check out Colo.
It's a pretty incredible extension for your editor.
VS Code at the moment, more editors to come most likely.
We have Wilhelm Klopp on to tell us all about it.
This is Talk Python in May, episode 464, recorded May 9th, 2024.
Are you ready for your host, here he is!
You're listening to Michael Kennedy on Talk Python to Me.
Live from Portland, Oregon, and this segment was made with Python.
Welcome to Talk Python to Me, a weekly podcast on Python.
This is your host, Michael Kennedy.
Follow me on Mastodon, where I'm @mkennedy,
and follow the podcast using @talkpython, both on fosstodon.org.
Keep up with the show and listen to over seven years of past episodes at talkpython.fm.
We've started streaming most of our episodes live on YouTube.
Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.
This episode is sponsored by Sentry.
Don't let those errors go unnoticed.
Use Sentry.
Get started at talkpython.fm/sentry.
And it's also brought to you by us over at Talk Python Training.
Did you know that we have over 250 hours of Python courses?
Yeah, that's right.
Check them out at talkpython.fm/courses.
Well, welcome to Talk Python to Me.
Hello.
Yeah, excited to be here, Michael.
I've been listening to Talk Python like for, I can't even remember how long,
but I'm pretty sure it was before I had a first Python job.
So, yeah, a long, long time.
That's amazing.
Well, now you're helping create it.
Yeah, exactly.
We're going to talk about Colo, your Visual Studio Code, Django.
I don't even know what to call it.
It's pretty advanced, pretty in-depth.
Extension seems to be not quite enough.
So, what any project?
People are going to really dig that, people who Django.
And we'll see what the future plans are if we can talk you into other ones.
But for now, Django plus...
100%.
Yeah, Django plus VS Code is going to be super interesting.
When we get to that, of course, you must know the drill.
Tell us a bit about yourself.
Yeah, for sure.
So, my name is Will.
I've been using Django since...
Well, I guess I've been using Python since about 2013, I want to say.
So, a little over 10 years.
And, yeah, I just kind of fell in love with it.
Wanted to make websites.
Started using Django.
And, yeah, I guess never really looked back.
That was in school back then.
But kind of always had a love for tinkering and building side projects.
I actually studied...
I did a management degree in university.
But I really loved hanging out with all the computer science kids, all the computer science
students.
And I think a part of me really wanted to impress them.
So, I was always building side projects.
And one of them was actually a Slack app called Simple Poll.
And, yeah, we were trying to, like, organize something in Slack and really felt like the
need for polls.
So, built this little side project just, like, during university.
And then it became really, really popular.
And a few years later, it became my full-time job.
So, for the past, like...
Awesome.
Yeah.
Four years, I've been running Simple Polls, a Slack app, building out the team up to,
like, seven, eight of us.
And I had a great time doing that.
In the middle, I actually worked at GitHub for two years, working on Ruby and Rails.
And that was super fun.
Like, a great company, great people, huge code base.
Learned a lot there.
That was really fun.
But, yeah, I left after about two years to work full-time on Simple Polls.
So, Simple Polls have been running as a side project kind of in the background.
And actually, it's interesting, like, I think kind of the order of events, thinking back,
Microsoft was...
Acquired GitHub while I was there.
And then suddenly, all of my colleagues started talking about buying boats and leaving the company.
And I thought, hmm, I don't quite have boat money.
But how can I...
What's an ace I might have up my sleeve?
And it was Simple Poll, which had got, like, tons of users, but I never monetized it.
So, I set out to monetize it.
And then a year later, it was actually bringing in more revenue than my salary at GitHub.
So, I decided to quit.
So, that's kind of the Simple Poll backstories.
So, Simple Polls, a Django app, reasonably sized now, a bunch of people working on it.
And then, yeah, at some point in the journey of building Simple Poll, I kind of started playing around with Colo.
So, Colo also kind of, just like Simple Poll, started as a side project.
But now, not to make polls in Slack, but instead to improve my own developer experience building Simple Poll.
So, kind of built it as my own tool for making Django, working with Django more fun, give me more insight, give me access to some of the data that I felt was so close.
But that I had to just, like, manually get in there and print out.
So, the reason Colo started out as supporting just Django and VS Code is because that's what I was using.
And it was an internal side project.
And now, actually handed over Simple Poll to a new CEO.
I'm no longer involved day to day, and I'm working full-time on Colo.
Man, congratulations on, like, multiple levels.
That's awesome.
Thank you.
Yeah.
I want to talk to you a bit about Simple Poll for just a minute.
But before then, you pointed out, like, look, I made this side project.
And how many hours were you spending on it?
A week, maybe?
Oh, it was interesting.
So, honestly, like, so this was, like, right at the beginning, like, when it was first started.
Yeah, it's a good time.
It's a good question.
I always joke that the best thing about my management degree was that I had a lot of free time to, like, do, build side projects.
Honestly, I think it could have been, like, 20, 30, 40 hours a week.
Yeah.
That was, yeah.
I think, yeah, it definitely varied week to week.
And then later on?
Yeah.
And then while I was working, when I had a full-time job as a software engineer, yeah, that was a lot tougher.
It was, like, nights and weekends.
Rarely had energy during the week to work on it.
And then, honestly, like, since it was a real project with real users, I ended up spending a lot of the weekend doing, like, support.
Like, support stuff.
Yeah, absolutely.
Support.
And, like, then you charge, and then now you have finance stuff and, like, legal stuff to do.
So that wasn't super fun.
It really slows down the features and the creation of stuff, doesn't it?
Yeah.
I would say I probably spent fully 50% of my full-time job doing email support, that kind of stuff.
You know, just, like, there's tons of people taking courses and listening to podcasts.
Yeah, yeah, yeah.
And they'll have questions and thoughts.
And, you know, it's awesome.
But it also is really tricky.
So the reason I ask is I always find it fascinating.
You'll see, like, news articles.
I don't know.
They're always click-baity or whatever.
This person makes three times their job working 10 hours a week on this other thing.
Like, you make three times what you make for your job.
What are you doing at your job?
You know what I mean?
Right?
The ability to say you can make that step where you go from kind of tired at night's
extra time and squeezing on the weekends to full-time, full energy.
Yeah.
If it's already doing well, you know, on, like, a very thin life support, like, then give it
full-time and energy.
It's just, of course, it's going to be better, right?
It's so interesting.
I actually have a lot of thoughts about this.
Maybe I should write something about this at some point.
But yeah, I actually think running, like, a bootstrap side project kind of business as
you have a job can be really good because it really forces you to prioritize and build the
most important things.
Yeah.
It's kind of like having kids.
Oh, nice.
Yeah, yeah.
I need to try that someday.
Oh, you'll be real tired.
I tell you, you'll love to prioritize your time.
Yeah, I think it really forces you to prioritize.
So I actually sometimes recommend when folks ask me, like, for advice, like, should I quit my
job to go all in or not?
I actually sometimes think there's a lot of nice stability and that comes from having a
job.
Plus, it's actually really nice to have coworkers.
It's nice to have structure.
Like, you actually need to take all of that, well, work in a way on yourself.
Like, it's, you know, if you have to make your own structure, like, if you're building your
own thing, and that can actually be a bit tricky.
Like, I really struggled with that at the beginning.
So I think there's something to be said for, yeah, for spending, like, limited time on something,
basically, and prioritizing just the most important.
That's an interesting angle.
And I don't necessarily disagree with that.
That's interesting.
So for me, it was interesting, like, in terms of like, how much, like, you know, life support
energy you put in versus like, full time energy.
It was growing decently, like while I was still at GitHub.
And I thought, okay, I'm gonna go in on this full time.
And if I go from like, 10 hours a week, or less to like 40 hours a week, that would probably
4x the growth rate as well.
That's how it works.
Right?
And like, totally didn't.
Like, it totally didn't work.
In fact, like, the month after I left, I had like my first down month, where like the revenue
decreased.
And I was like, wait a minute, what's going on here?
How that doesn't make any sense.
That's not fair.
So I think that also points that like, there, yeah, you can definitely spend more hours on
something.
And it can be like the wrong things or not doubling down on something that's really working.
So, but overall, obviously, you at some point, like just being able to like test out more
ideas is like really valuable.
And for that, like, if you only have time to do support on your project, that's really working
well, and your full time job is the rest of the how you spend your week, then yeah, feels
like you should give yourself some time to build features and maybe quit the job.
Yeah.
It's also an interesting point about the structure, because not everyone is gonna get up at eight
o'clock, sit at their desk, and they're gonna be like, you know, I kind of can just
do whatever.
And it's, it's a, it's its own discipline, its own learned skill.
100%.
Yeah.
I remember like one of the first weeks after I was full time on simple call, I woke up in
the morning and said, well, the money's coming in.
I don't need to work.
I don't have a boss.
And I just sit in bed and watch YouTube videos all day.
And then I just felt miserable at the end of the day.
Like the, I was like, this is supposed to feel great.
Why all this freedom I've wanted and dreamt about for so long?
We're like, why does it not feel great?
Yeah.
It also, also feels like risk and more different kinds of responsibility.
All right.
So simple poll.
The reason I said it'd be worth talking about a little bit is, you know, Slack's a popular
platform and this is based on Django, right?
So simple poll is a full on Django app.
Yeah.
And it's funny.
Sometimes people joke that, I don't know if you've gone through the official Django tutorial,
but in there you actually make a polls app in the browser.
Sometimes people joke, wait, did you just turn this into like a Slack app?
And then you productize the getting started tutorial.
Yeah.
Exactly.
But yeah, like it turned out that like polls and then, yeah, getting, you know, your team
more connected and Slack and more engaged are like things people really care about.
So it came to the Slack, simple poll joined the Slack platform like at the perfect time and
has just been growing super well since then.
Tell people a little bit about what it takes technically to make a Slack app.
I mean, Slack is not built in Python as far as I know.
And it's probably JavaScript and Electron, mostly the people interact with, right?
So what is the deal here?
It's actually super interesting.
So the way you build like a Slack app, it's actually all backend based.
So when a user interacts in Slack, Slack sends your app, your backend, like a JSON payload
saying like this user clicked this button.
And then you can just send a JSON payload back saying, all right, now show this message.
Now show this modal.
And they have their own JSON based block kit framework where you can render different types
of content.
So you don't actually have to think about JavaScript or React or any of their stack at all.
It's basically all sending JSON payloads around and calling various parts of the Slack API.
So you can build a Slack app in your favorite language, any kind of exotic language if you wanted
to.
But yeah, I love Python.
So I decided to build it in Python and Django.
So yeah, actually building Slack apps is a really like pleasant experience.
What's the deployment backend story look like?
Is it a pass sort of thing?
Serverless?
VMs?
At the time, it was Heroku.
Simbup was running on Heroku.
And then I think a few years ago, we migrated it to AWS.
So now it's running on AWS and ECS.
Nice.
Okay.
So Docker for the win.
Right on.
How does it work in TalkBison?
I'm curious.
How, what's, where are you deployed?
It's all DigitalOcean.
And then I have one big, like eight, eight CPU server running, I think, 16 different Django
apps.
Not Django, sorry.
Docker apps.
No, sorry.
Docker apps that are all, all doing like, you know, some of them share database that's in
Docker and some of them do sort of have their own self-contained pair of like web app and
database and so on.
But it's all, it's all Docker on one big server, which is fairly new for me.
And it's, it's glorious.
It's glorious.
That's awesome.
Very cool.
Yeah.
All right.
So again, congrats on this.
Very, very neat.
Let's talk Colo.
Let's do it.
I first came across this, I've come across it independently twice.
Once when the Django chat guys recommended that I talk to you because they're like,
Will's doing cool stuff.
You should definitely talk to him.
This Django thing for VS Code is super cool.
But also I can't remember there's somebody on your team whose social media profile I came
across and I saw this and I'm like, oh, this is, this is pretty neat.
I think we even covered it on the Python Bytes podcast.
Oh, no way.
Let's see.
Yeah, sure.
In January we did.
So that's what we talked about a little bit, but this just looks like such a neat thing.
And it's, I encourage people to, who may be interested in this, to visit colo.app because
it's a super visual sort of experience of understanding your code, right?
Would you agree?
Yeah.
I mean, a hundred percent.
Yeah.
A funny thought.
I hadn't really thought that a podcast is going to be a hard way to describe the visual
beauty and magic that Colo can bring to your code.
But yeah, a hundred percent.
Yeah.
So Colo like very much started as like the idea of, Hey, like I should be able to see
like how my code actually flows.
I think like all of us, as we build software, as we write our Python code, we have this kind
of like mental model of how all the different functions like fit together.
How like a bit of data ends up from like the beginning, like to the end, like it passes through
maybe a bunch of functions.
It passes through a bunch of like classes, a bunch of loops.
All the state gets like modified and we have this kind of like mental picture of all of
that in our head.
And the kind of very beginning of Colo, the question I asked myself was like, is there a
way we can just like visualize that?
Is there a way we can just actually print that out onto a screen?
So if you go to colo.app, it kind of looks like this funny sun chart with like lots of kind
of a sunny tree chart with lots of nodes going from the center and like going off into the
distance, which I think is like, yeah, similar to like what folks kind of might already have
in their head about like how the code flows.
Maybe another way to describe it is imagine like you enable a debugger at the beginning
of every function and at the end of every function in your code and you print out like what was
the function name?
What were the input arguments?
What was the return value?
And then you arrange all of that in a graph that then shows which function called which other
function.
It almost looks like what you get out of profilers.
Right.
You know, where you say like, okay, this function took 20%, but if you expand it out, I'll say,
well, really spent 5% there, 10% there, and then a bunch of it.
And you can kind of traverse that.
100%.
Yeah.
I'm guessing you're not really interested in how long it took, although maybe you can probably
get that out of it.
It's the important is more what is the dependency?
What are the variables being passed and like understanding individual behavior, right?
Or maybe.
Yeah.
What do you think?
Yeah, 100%.
I think like, it's interesting because Colo actually uses under the hood, like a bunch
of the Python profiling APIs.
And I think people often think of Colo as a profiler.
We do actually have a traditional profiling based chart, which puts the timing at the center.
But you're absolutely right that the focus of our like main chart, the one that we're both
looking at that has like this idea of the function overview and like which function calls which.
The idea there is like absolutely the hierarchy and seeing like giving yourself that same mental
model that someone who's worked on a code base for three months has in their head immediately
like yourself by just looking at it.
This portion of Talk Python to me is brought to you by Sentry.
Code breaks.
It's a fact of life.
With Sentry, you can fix it faster.
As I've told you all before, we use Sentry on many of our apps and APIs here at Talk Python.
I recently used Sentry to help me track down one of the weirdest bugs I've run into in a long
time.
Here's what happened.
When signing up for our mailing list, it would crash under a non-common execution pass, like
situations where someone was already subscribed or entered an invalid email address or something
like this.
The bizarre part was that our logging of that unusual condition itself was crashing.
How is it possible for our log to crash?
It's basically a glorified print statement.
Well, Sentry to the rescue.
I'm looking in the crash report right now, and I see way more information than you'd expect
to find in any log statement.
And because it's production, debuggers are out of the question.
I see the traceback, of course, but also the browser version, client OS, server OS, server
OS version, whether it's production or Q&A, the email and name of the person signing up.
That's the person who actually experienced the crash.
Dictionaries of data on the call stack and so much more.
What was the problem?
I initialized the logger with the string info for the level rather than the enumeration.info.
which was an integer based enum.
So the login statement would crash saying that I could not use less than or equal to between
strings and ints.
Crazy town.
But with Sentry, I captured it, fixed it.
And I even helped the user who experienced that crash.
Don't fly blind.
Fix code faster with Sentry.
Create your Sentry account now at talkpython.fm/sentry.
And if you sign up with the code TALKPYTHON, all capital, no spaces, it's good for two free
months of Sentry's business plan, which will give you up to 20 times as many monthly events
as well as other features.
Usually in the way these charts turn out, you can notice that there's like points of interest.
Like there's one function that has a lot of children.
So that clearly is coordinating like a bunch of the work where you can see kind of similarities
in the structure of the some of the subtrees.
So you know, oh, okay, maybe that's like a loop and it's the same thing happening a couple
times.
So you can essentially, I get this overview and then it's fully interactive and you can
dive in to like what exactly is happening.
Yeah.
Is it interactive?
So I can like click on these pieces and it'll pull them up.
We actually, and this is what's, it'll be live by the time this podcast goes live.
We actually have a playground in the browser.
This is also super fun.
We can talk about this.
Let me drop you a link real quick.
This will be at play.colo.app.
So with this, yeah, this is super fun because this is fully Python just running in the browser
using Pyodide and like WebAssembly.
Nice.
Okay.
But yeah, so this is the fully visual version where you can, yeah, it defaults to loading
like a simple Fibonacci algorithm.
Yeah.
And you can see like what the cola visualization of Fibonacci looks like.
And you can actually edit the code and see how it changes with your edits and all of that.
We have a couple other examples.
Wow.
The pandas one and the whack-a-mole one are pretty intense.
They're pretty wild pictures.
They look like sort of Japanese fans or whatever.
You know, those little paper ones.
We once had a competition at a conference to see who could make like the most fun looking
algorithm and visualize it with Kolo.
But yeah, like it's fun.
Like visualizing code is really great.
That's awesome.
So this is super cool.
It's just all from scratch.
It's besides Pyodide here.
Not like VS Code in the browser or anything like that.
I think it's using Monaco in this case or CodeMirror.
But otherwise, this is all is Pyodide and a little bit of React to like pull kind of the
data together.
Uh-huh.
But yeah, we're really, yeah.
Wow.
It's otherwise homemade.
This is kind of like the kind of what Kolo has been for like the past like two years or so has been this kind of side project for our SimplePol to help like just visualize and understand code better.
The SimplePol code base, to be honest, has grown so large that like there's parts of it that I wrote like five years ago that I don't understand anymore.
And it's like annoying to get back to that and having to spend like a day to re-familiarize myself with everything.
It's a lot nicer to just like to actually kind of explain like end to end how it works.
You install like in a Django project, you install Kolo as a middleware.
And then as you just browse and use your Django app and make requests, traces get saved.
So Kolo records these traces.
They actually get saved in a local SQLite database.
Then you can view the traces, which includes the visualization, but also like lots of other data.
Like you can actually see in the version you have there.
Like we show every single function call, like the inputs and outputs for each function call.
So that main idea of Kolo is to like really show you everything that happened in your code.
So in a Django app, that would be like the request, the response, like all the headers, every single function call, input and output, outbound request, SQL query.
So really the goal is to show you everything.
You can view these stored traces either through VS Code.
And this is also will be live by the time this episode goes live through like a web middleware version, which is a bit similar to Django debug toolbar.
Not sure if you've played around much with Django debug toolbar.
Yeah, a little bit.
Yeah.
And those things are actually pretty impressive.
Right.
I played out with that one in the pyramid one.
And yeah, you can see more than I think you would reasonably expect from just a little thing on the side of your web app.
Yeah, yeah, exactly.
And that's very much our goal to like very kind of deep insight.
In our minds, this is almost like a bit like old news.
Like we've been using this for like a few years, basically.
And then at some point, like last year, we started playing around with this idea of like,
OK, so we have this trace that has information about like pretty much everything that happened in like a request.
Is there any way we could use that to solve this like reasonably large pain point for us, which is like writing tests?
I'm actually curious.
Do you enjoy writing tests?
I'll tell you what I used to actually.
I used to really enjoy writing tests.
I used to enjoy thinking a lot about it.
And then as the projects would get bigger, I'm like, you know, this is these tests don't really cover what I need them to cover anymore.
And they're kind of dragging it down.
And then, you know, the thing that really kind of knocked it out for me is I'd have like teammates and they wouldn't care about the tests at all.
So they would break the tests or just write a bunch of code without tests.
And I felt kind of like like a parent cleaning up after kids.
You're like, why is it so?
Can we just pick up?
Like, why are there dishes here?
You know, just going around.
I'm like, this is not what I want to do.
Like, I want to just write software.
And like, I understand the value of tests, of course.
A hundred percent.
At the same time, I feel like maybe higher order integration tests often, for me at least, serve more value.
Because it's like, I could write 20 little unit tests or I could write two integration tests.
And it's probably going to work.
I'm actually completely with you on that.
Okay.
Right on.
The bang for the buck of integration tests are like great.
Like really, really useful.
You can almost think of tests as having like two purposes.
One being like, well, actually, I think this would be too simple in explanation.
Let me not make grand claims about all the uses of tests.
I think the use of it that most people are after is this idea of like, what I've built isn't going to break by accident.
Yeah.
Like you want confidence that any future change you make doesn't impact a bunch of unrelated stuff that it's not supposed to impact.
I think that's what most people are after with tests.
And I think for that specific desired result, like integration tests are the way to go.
And there's some cool writing about this from, I wrote a little blog post about Kolo's test generation abilities.
And in there, I linked to a post from Kent C. Dodds from the JavaScript community who has a great post about, I think it's called write tests, not too many, mostly integration.
Kind of after this idea of like,
Nice.
Yeah, yeah, yeah.
Eat not too much, mostly vegetables.
I think that's the, yeah, exactly.
Exactly.
Yeah.
I'm a big fan of that.
And actually it's interesting.
I've speaking to a bunch of folks over the past like year about tests.
A lot of engineers think about writing tests as vegetables.
And obviously some people love vegetables and some of us love writing tests, but it seems like for a lot of folks, it's kind of like a obviously necessary part of creating great software, but it's maybe not like the most fun part of our job.
Or you pick up some project, you're a consultant, or you're taking over some open source project.
You're like, this has no tests.
Right.
It's kind of like running a linter and it says there's a thousand errors.
You're like, well, we're not going to do that.
Yeah.
We're just not going to run the linter against it because it's just too messed up at this point.
Right.
It's interesting.
You mentioned the picking up like a project with no tests, because I think within the next three months, we're not quite there yet.
But I think in the next three months with Colo's test generation abilities, we'll have a thing where, yeah, all we need is a Python code base to get started.
And then we can bring that to like a really respectable level of code coverage just by using Colo.
Okay.
How?
I was kind of describing a second ago how like we, SimplePol has tons of integration tests.
SimplePol actually is about 80,000 lines of application code, not including migrations and like config files.
And then it's about 100,000 lines of tests.
And most of that is integration tests.
So SimplePol very well, very well tested.
Lots of, you know, really mostly integration tests.
But it is always a bit of a chore to like write them.
So we started thinking about like, hmm, this like Colo tracing we're doing, can that help us with making tests somehow?
And then we started experimenting with it.
And like to our surprise, it's actually, yeah, I'm still sometimes surprised that it actually works.
But basically the idea is that if you have a trace that has, that captures everything in the request, you can kind of invert it to build a integration test.
So let me give an example of what that means.
The biggest challenge we found with creating integration tests is actually the test data setup.
So getting your application into the right shape before you can send a request to it or before you can call a certain function.
That's like kind of the hardest part.
Writing the asserts is almost like easy or even like fun.
Right.
There's the three A's of unit testing.
Range, assert, and act.
Wait, arrange, act, and assert.
Exactly.
The first and the third one that you kind of have data on, right?
Exactly.
Yeah.
So we're like, wait a second.
We actually can like kind of extract this, like the act.
So like the setting, sorry, the arrange, setting up the data, the act, like actually making the HTTP request.
And then the assert, like to ensure the status change or that the request go to 200 or something.
We actually have the data for this.
It's reasonably straightforward.
Like if you capture in, you know, just your like normal, like imagine you have a local to-do app and you browse like a to-do kind of demo, simple to-do app.
And you browse to the homepage and the homepage maybe lists the to-dos.
And if you've got Kolo enabled, then Kolo will have captured the request, right?
So like the request went to the homepage and it returned a 200.
So that's already like two things we can now turn into code in our integration test.
So first step being, well, I guess this is the act and the assert in the sense that the assert is the 200.
And then the act is firing off a request to the homepage.
Now the tricky bit, and this is where it gets the most fun, is the arrange.
So if we just put those two things into our test, in our to-imaginary test, there wouldn't have been any to-dos there, right?
So it's actually not an interesting test yet.
But in your local version where the trace was recorded, you actually had maybe like three to-dos already in your database.
Does that make sense so far?
Yeah, yeah, absolutely.
On the homepage, like your to-do app might make a SQL query to like select all the to-dos or all the to-dos for the currently logged in user.
And then Kolo would store that SQL query, would store that select, and would also store actually what data the database returned.
This is actually something where, yeah, Kolo goes beyond a lot of the existing kind of like debugging tooling that might exist.
Like actually showing exactly what data the database returned in a given SQL query.
But imagine we get like a single to-do returned, right?
We now know that to replicate this like trace in our test, we need to start by seeding that to-do into the database.
That's where like the trace inversion comes in.
If like a request starts with a select of like the to-do table, then the first thing that needs to happen in the integration test is actually a like creating like an insert into the database for that to-do.
And now when you fire off the request to the homepage, it actually goes through your real code path where like an actual to-do gets loaded and gets printed out onto the page.
So that's like the most basic kind of example of like how can you turn like a locally captured trace of a request that like made a SQL query and return 200 into like an integration test.
Yeah, that's awesome.
One of the things that makes me want to write fewer unit tests or not write a unit test in a certain case is I can test given using mocking, given my, let's say SQLAlchemy or Beanie or whatever Django Rm model theoretically matches the database.
I can do some stuff, set some values and check that that's all good.
But in practice, if the shape, if the schema in the database doesn't match the shape of my object, the system freaks out and crashes and says, well, that's not going to work, right?
There's no way.
And so it doesn't matter how good I mock it out.
It has to go kind of end to end before I feel very good about it.
Oh, yeah.
Okay.
It's going to really, really work, right?
Exactly.
That's an interesting story.
Like you're saying to like, let's actually see if we can just create the data, but like let it run all the way through, right?
I'm totally with you.
And I think I've often seen like unit tests pass and say, I mean, there's like lots of memes about this, right?
How like unit tests say everything is good, but the server is down.
Like, how is that possible?
I think in Django world, it's reasonably common to write integration tests like this, as in like the actual database gets hit.
You have this idea of like the Django test client, which sends like a, you know, real in air quotes, HTTP request through the entire Django stack, as opposed to doing the more unit test approach.
So it hits the routes.
It hits like all of the, that sort of stuff all the way.
Yeah.
And the template.
Yeah.
And then at the end, you can assert based on like the content of the response, or you can check, like, imagine if we go back to the to-do example, if we're testing like the add to-do endpoint or form submission, then you could make a database query at the end.
And Colo actually does this as well, because like, again, we know like that you inserted a to-do in your request.
So we can actually make an assert.
This is a different example of the trace inversion.
If there's an insert in your request that you've captured, then we know at the end of the integration test, we want to assert that this row now exists in the database.
So you can assert at the very end to say, does this row actually exist in the database now?
So it's a very nice kind of reasonably end to end, but still integration test.
It's not like a brittle click around in the browser and kind of hope for the best kind of thing.
It's like, as we said at the beginning, I think like integration tests just get you great bank for your buck.
They really do.
It's like the 80-20 rule of unit testing for sure.
Yeah.
Talk Python to me is partially supported by our training courses.
If you're a regular listener of the podcast, you surely heard about Talk Python's online courses.
But have you had a chance to try them out?
No matter the level you're looking for, we have a course for you.
Our Python for Absolute Beginners is like an introduction to Python, plus that first year computer science course that you never took.
Our data-driven web app courses build a full PyPI.org clone along with you right on the screen.
And we even have a few courses to dip your toe in with.
See what we have to offer at training.talkpython.fm or just click the link in your podcast player.
So is this all algorithmic?
Yep.
Great question.
Is it LLMs?
Like how much VC funding are you looking for?
Like, you know, like if you've got LLMs in there, like they're coming out of the woodwork.
No, I'm just kidding.
No, how does this happen?
It's actually all algorithmic and rule-based at the moment.
So this idea of a select becomes like an insert and an insert becomes like a select assert.
We were surprised how far we could get with just rules.
The benefit we have is that we kind of have this like full-sized SimplePol Django code base to play around with.
And yeah, like generating integration tests in SimplePol just like fully works.
There's a bunch of tweaks we like had to make to as soon as I guess you work in kind of like outside of a demo example.
You want like time mocking and HTTP mocking and you want to use your like factory boy factories.
And maybe you have a custom unit test like base class and all of this.
But yeah, it like it actually works now.
I gave a talk at DjangoCon Europe last year.
It's kind of like a bit of a wow moment in the audience where, yeah, you just click generate test and it generates you like a hundred line integration test and the test actually passes.
So that was like people started just started clapping, which was a great feeling.
I'm still a bit surprised that it works on it.
But yeah, no LLM at all.
I do think like LLMs could probably make these tests like even better.
Or you know how I was saying a second ago, like in three months, we could go take a code base from like zero test coverage to maybe like 60%, 80%.
I imagine if we made use of LLMs, that would help make that happen.
Yeah.
You could talk to it about like, well, these things aren't covered.
Right.
What can we do to cover them?
Yeah.
I don't know if you maybe could do fully, fully automated.
Just push the button and let it generate it.
But, you know, it could also be like a conversational, not a conversation, sort of a guided.
Let's get the rest of the test.
You know, like, okay, we're down to 80.
We've got 80%, but there's the last bit are a little tricky.
Like what ones are missing?
Right.
So how do you think we could do this?
Is that, no, no, you need to, that's not really the kind of data we're going to pass.
You know, I don't know.
It seems something like that.
Right.
I really like that.
I had not thought about like a conversation as a way to generate tests, but that makes so much sense.
Right.
It kind of bringing the developer along with them where it's gotten too hard or something, you know?
Yeah.
There's something cool about just clicking a button and see how much code coverage you could get to.
But chatting to it.
I think also, honestly, like so far, like our test generation logic is a bit of a black box.
It just kind of like works.
Yeah.
Until the point where like it doesn't.
So we're actually kind of in the process of like shining a bit more of a light into like,
like essentially the like internal data model that Colo keeps track of to know what the database state should be like in this arrange part of the integration test.
And yeah, we're actually like in the process of like, yeah, talking to a bunch of users who are already using it and also finding like companies who want to increase their increase their test coverage or who have problems with their testing and want to improve that.
And kind of working closely with them to make that happen.
That's kind of a huge focus for us as we figure out, like, how do we want to monetize Colo?
Like so far, Colo has just been kind of supported by SimplePool as a side project, but we're kind of making it real, making it its own business.
So and we think the test generation is going to play a big part in that.
Right.
Like that could be a certainly a premium team feature sort of thing.
Exactly.
Yeah.
Enterprise.
Enterprise version comes with auto testing.
Yeah, exactly.
Something like that.
Yeah.
If there's anyone listening and like they're keen to increase their code coverage, please email me.
Maybe we can leave my email in the in the notes or something like that.
Yeah, I'll put your contact info in the show notes for sure.
It's actually really nice.
It's just W at Colo dot app.
Oh, very nice.
So yeah, if anyone's listening and wants to kind of like increase their code coverage or has a lot of code bases that have zero coverage that would benefit from getting to like some level of coverage, we'd love to help you and talk to you.
Even if the solution doesn't like involve using Colo, just really, really keen to talk to anyone about like Python tests and what can be done there.
So yeah, please hit me up.
Awesome.
Yeah, I'll definitely put some details in the show notes for that.
I have some questions as well.
Please.
Yes.
Right here.
I'm looking at the web page and the angle bracket title is Colo for Django.
But in the playground thing you sent me, it was on plain Python code.
It was on algorithms.
It was on pandas, which I thought was pretty interesting how much you could see inside pandas.
Makes me wonder, you know, if you look at the web frameworks, there's two or three more that are pretty popular out there and they all support middleware.
Yeah, 100%.
So Colo kind of started as like this like side project for our Django app.
And I think that that's why we kind of went there first.
It's kind of the audience we know best.
You can do dogfood as well.
Yeah.
Exactly.
Dogfooded.
Lily, who's an engineer on the team, and who's been building a lot of the Python side of Colo, is like a core contributor to Django.
So Django is like really where we're home.
And to be honest, I think when building a new product, it's kind of nice to keep the audience somewhat small initially.
Keep like building for very specific needs as opposed to going like very wide, very early.
That was kind of very much, very much the intention.
But there's no reason why Colo can't support Flask, FastAPI, the scientific Python stack.
As you can see in the playground, it does totally work on plain Python.
It's really just a matter of honestly, like FastAPI support would probably be like a 40 line config file in our code.
And there's actually, yeah, we're thinking of ways to make that actually a bit more pluggable as well.
There's only like so many things we can reasonably support well ourselves.
I was going to say, if somebody else out there has an open source project, they want it to have good support for this, right?
Like, hey, I run HTTPX or I run Litestar or whatever.
And I want mine to look good here too, right?
Totally.
So the thing you can do already today is there's a little bit of config you can pass in.
And actually, if you look back on the pandas example, you'll see this.
By default, Colo actually doesn't show you library code if you use it in your own code base.
But you can tell it, show me everything that happened, like literally everything.
And then it will do that for you.
So in this example you're looking at, or if anyone's looking at the playground, if you look at the pandas example, it'll say like include everything in pandas.
And that'll give you like a lot more context.
The thinking there is that most people don't really need, like the issues you're going to be looking at will be in your own code or in your own company's code base.
You don't really need to look at the abstractions, but you totally can.
But yeah, to answer the question, like we have this like internal version of a plugin system where, yeah, like anyone could add FastAPI support or like a great insight into PyTorch or what have you.
The way it all works technically really is it's totally built on top of this Python API called set profile.
I'm not sure.
Have you used, have you come across this before?
It's a bit similar to set trace actually.
Yeah, I think so.
I think I've done it for some C profile things before.
I'm not totally sure.
Yeah.
It's a really neat API to be honest, because Python calls back to your, like the callback that you register on every function, enter and exit.
And then Colo essentially looks at all of these functions, enters and exits and decides which ones are interesting.
So the matter of like supporting say FastAPI is basically just telling Colo, these are the FastAPI functions that are interesting.
This is the FastAPI function for, for like an HTTP request that was served.
This is the HTTP response or similarly for SQLAlchemy.
This is the function where the query was actually executed and sent to the database.
This is the variable, which has the query result.
Like there's a little bit more to it.
And I'm definitely like, yeah, generalizing, but it's kind of like in principle, it's as simple as that.
It's like telling Colo, here's the bits of code in a given library that are interesting.
Now just kind of like display that and make that available for the test generation.
Excellent.
Yeah, I totally agree with you that getting focused, it probably gets you some more full attention from the Django audience.
And the Django audience is quite a large and influential group in the Python web space.
So that makes a ton of sense, especially since you're using it.
By the way, it was Lily's Mastodon profile, I believe, that I ran across that I first discovered Colo from.
So of all the places, yeah.
Or a post from her or something like that.
That's awesome.
Cool.
All right.
So let's talk about a couple other things here.
Let's do it.
For people who haven't seen it yet, like you get quite a bit of information.
So if you see like the get request, you actually see the JSON response that was returned out of that request.
And it integrates kind of into your editor directly, right?
If you've seen CodeLens before, it's kind of like CodeLens, right?
Yeah, this is another thing which I think is pretty novel with Colo.
Like I think it's reasonably common for existing debugging tools to show you like, oh yeah, this is the headers for the request.
Or this is like the response status code.
But especially working with the Slack API in SimplePol, you're constantly looking at payloads and what were the values for things and what are you returning.
In production, you don't directly get to even make those or receive those requests, right?
There's some like system in Slack who was like chatting with your thing.
You're like, well, what is happening here, right?
Not that you would actually run this in there, but you know.
I mean, it's funny you mentioned this because there is one experiment we want to run of kind of actually enabling these extremely deep and detailed Colo traces in production.
We haven't explored this too much yet.
And I think we're going to focus a little bit more on the test generation.
But you could imagine like a user who's using, who's on the Talk Python site and they've got some incredibly niche error that no one else is like encountering.
And you've tried to reproduce it, but you can't reproduce it.
Maybe there's a little bit of information in like your logging system, but it's just not enough.
And you keep adding more logging and you keep adding more logging and it's just not helping.
Like imagine a world where you can say just for that user, like enable Colo and enable like these really deep traces.
And then you can see whenever the user next interacts, like the value for every single variable, for every single code path that executed for that user.
That's just like, yeah.
I think one of our users described it as like a debugger on steroids.
Yeah, yeah.
It's pretty interesting.
Sounds a little bit like what you get with Sentry and some of those things, but maybe also a little bit different.
So, you know, you could do something like, here's a dear user with problem.
Here's a URL.
If you click this, it'll set a cookie in your browser and then all subsequent behavior, it just, it's on it.
You know what I mean?
It's like recording it.
Yeah.
That'd be pretty interesting.
Yeah.
I think it makes sense in the case, like if a user, it could even be an automated support thing, right?
Like if a couple of sites have this where you can like do like a debug dump before you submit your support ticket.
This is almost like that.
And then as an engineer who's tasked with digging into that user's bug, you don't have to start with like piecing together.
What was this variable at this time when they made that request three days ago?
You like, you can just see it.
If an error ever encounters an exception on your site, you just set the cookie.
Right.
Everything else they do is now just recorded until you turn it off on them.
Oh my gosh.
You're giving me so many good ideas.
That'd be fun, right?
Start writing this stuff down.
Hey, let's record it.
It'll be fine.
That's awesome.
Yeah.
There's a bunch of stuff that's interesting.
People can check it on the site.
It's all good.
However, we talked a little bit about the production thing.
Like another thing you could do for production, this requires both a decent amount of traffic and maybe you could actually pull this off on just a single server.
But you could do like, let's just run this for 1% of the traffic so that you don't kill the system.
But you get, you know, if that's why you have enough traffic is like statistically significant sampling of what people do without actually recording a million requests a day or something insane.
A hundred percent.
I think there's really something there.
Or like I could go on about this whole idea of like runtime data and like improving software understanding for days because I just think like it's really this like missing layer, right?
Like all of us constantly imagine like what is like we play computer looking at our code, imagining what the values can be.
But like, yeah, say you're looking at some complex function in production and you want to understand how it works.
Like how useful would it be if you could see like the 10, the last 10 times it was called, like what were the values going into it and what were the values coming out of it?
Like that would be, I just think like, why do we not have this already?
Like why does your editor not show you for every single function in the code base?
Give examples of like how it's actually used like in production.
Yeah.
And then use those to generate unit tests.
And if there's an error, use that to generate the edge case, like the negative case, not the positive case, unit test, right?
There you go.
Exactly.
It's all like kind of hanging together.
Like, yeah.
Yeah.
Once you have the data, you have interesting options.
Yeah.
Business model.
This is not, this, I maybe should have started sooner with this, but it's not entirely open source.
It may be a little, little bits and pieces of it, but in general, it's not open source.
That's correct.
Yeah.
No, I'm putting that out there as a negative, right?
This looks like a super powerful tool that people can use to write, write code it.
And that's fine.
Yeah.
I think the open source question is super interesting.
Like it's always been like something we've thought about or, or considered.
I think there is, yeah, with, with developer tools, I think business models are always super interesting and we want to make sure that we can have a business model for Colo and like run it as like a sustainable thing, as opposed to it just being like a simple pole side project kind of indefinitely.
Be great if Colo could like support itself and yeah, have a business model.
I think that's how it can like really fulfill its potential in a way, but that's not to say that like Colo won't ever be open source.
Like I think there's a lot to be said for open sourcing it.
I think especially like the, the capturing of the traces is maybe something like I could see us open sourcing.
I think the open source community is fantastic.
I do also think it's not like a thing you get for free, right?
Like as soon as you say, Hey, we're open source, you open yourself up to contributions, right?
And to like the community actually getting involved and that's great, but it also takes time.
And I think like, that's a path I would like to go down when we're a little bit clearer on like what Colo actually is and like where it's valuable.
If that makes sense.
Yeah, sure.
If it turns out that no one cares about like what, how, like how to visualize code, then like, that's a great, like learning for us to have made, but I'd rather get there without like a lot of work in the middle that we could have kind of avoided, if that makes sense.
So for sure.
It feels like once we have a better sense of the shape of Colo and what the business model actually looks like, then we can be a bit more.
Yeah.
We can invest into open source a little bit more, but to be honest, like based on how everything's looking right now.
I would not be surprised at all.
If like big chunks, it was like Colo becomes open core or big chunks of it are like open source.
It makes sense to me.
It is fully free at the moment.
So I should, that's worth calling out.
There's no cost or anything.
You can also like, you know, you download the Python package and guess what?
You can look at all of the code.
Like it actually is all of theirs.
It is all kind of visible.
That kind of leads into the next question is I've never used GitHub Copilot and a few of those other things because it's like here, check this box to allow us to upload all of your code and maybe your access keys and everything else.
That's interesting.
So we can one trainer models and two, you know, give you some answers.
And that just always felt a little bit off to me.
What's the story with the data?
At the moment, Colo is like entirely like a local product, right?
So it's all local.
Like you don't have to, you can get like all of the visualization, everything just by using local Colo in VS Code.
We do have a way to like upload traces and share them like with a colleague.
This is actually also something I think is like kind of playing with the idea of like writing a little like Colo manifesto.
Like what are the things that we believe in?
One of them that I believe in, and this goes back to the whole like runtime layer on top of code.
And like there's this whole dimension, this like third dimension to code that we're all simulating in our heads.
I think like it should totally be possible to not just like link to a snippet of code like on GitHub, but it should be possible to have a like link like a URL to a specific execution of code, like a specific function and actually talk about that.
It's kind of wild to me that we don't have this at the moment.
Like you can't send a link to a colleague saying, hey, look at this execution.
That looks a bit weird.
We ran this in continuous integration and it crashed, but I don't understand.
Let's look at the exact.
Right.
The whole deal.
You can link to like CI runs.
You can link to like sentry errors.
But like if you're just seeing something slightly weird locally or like even something slightly like weird in production where there's no area, you can't really like link link to that.
Anyway, like this is kind of a roundabout way of me saying that like I think that totally should be a thing.
Like you should be able to link like generically to like an execution of a function or execution of a request.
Like that would totally have to live somewhere.
Right.
So this is where there's some idea of like Colo cloud comes in and this is where you could like connect your repository.
And then Colo would like as part of that, you know, just like GitHub does have access to your code and like show you the code in like the Colo cloud.
So I think there's definitely like useful things that are possible there.
But at the moment, it's a fully local experience.
Like your code doesn't ever leave your system.
You can if you want to like upload traces and then Colo stores the like trace data, not the code, just the trace data.
But yeah, very local experience right now.
Yeah.
A little SQLite database.
Exactly.
Yep.
Yeah.
SQLite's pretty awesome.
It's a credible piece of software.
Yeah, it really, really is.
Let's close out our conversation here with a little bit of a request from Michael.
Right now it's VS Code only.
Any chance for some PyCharm in there?
This is our top request, like PyCharm support.
Yeah.
And we've decided super small team, like we want to kind of support everyone.
But we've been working very heavily actually the past few months on a web-based version, which is, I'm happy to say, like very much nearing completion.
And there's a few bits and pieces where like it's really nice to be integrated super deeply into the editor, like the code lenses and all of that.
And I think there's a chance we'll have that for PyCharm eventually as well.
But we actually found that like building out this web version, there's a few things that are actually much nicer when you have the full control over the UI in terms of like browsing around a trace, highlighting little bits of code.
So for example, in Colo, like a given function call, we call a frame.
And you can look at a given frame, both in VS Code, but also in the web version and see the code and see all of the data that passed through the code.
But something we can do in the web version we can't do in VS Code is actually show where the current function was called from and actually show like a preview of that code.
In VS Code, you can't really show like, you can link to it.
Yeah, you can layer multiple files together or a difference.
Yeah, exactly.
Yeah.
There's actually a lot of, like I was surprised by how many different novel, like kind of ways we had in the web that we just never even considered with like a direct editor integration in terms of displaying this runtime data.
So like long story short, like you, you know, you want a PyCharm integration.
Let me give you something even better.
Yeah.
A web version.
So would that work like you run a certain command or something when you run your web app and then it just generates the SQLite file and then you could just explore it with a web view or what are you?
Yeah, it's actually kind of cooler than that.
So if you're using Django or in the future, like other things with a typical middleware, you would just like go to your, you would just go to localhost 8000 slash Colo.
Yeah, yeah, yeah.
Kind of like you do for open API docs.
Yep.
And then the whole experience is just there.
If you're not using a middleware, we'll have a command like Colo serve or something like that.
And that'll host the same experience for you.
Just make sure it's off by default or it only responds on localhost or something like that.
Yeah, exactly.
Don't let people ship it on accident.
That would be bad news.
No production use of this.
Yeah.
I mean, people already know about the Django debug settings, but I guess you could sort of layer onto that, right?
Probably.
Yeah, I think we actually do that at the moment.
But yeah, it's worth remembering.
I know.
I'm just thinking of like, oh, this is really cool to explore.
A hundred percent.
CNN.com is awesome.
Look what it's doing.
Look at all these requests and all this.
Yeah, exactly.
A hundred percent.
Yeah.
Oh, and the API key is so interesting.
Anyway, that's a bit of a side conversation.
So let's just wrap it up with final call action.
People are interested.
What do they do?
Yeah, colo.app and check it out.
We have the Playground link there.
Play.colo.app.
Easiest way to kind of see what Colo is and what Colo does.
But we'll say the most powerful way to actually see Colo in action is to use it on your own code base.
So seeing the visualization and the test generation capabilities is just like, yeah, the most useful when you use it on your code base.
So hopefully the Playground can entice that a little bit.
And yeah, really the main, most important thing for us right now is, yeah, chatting to folks who want to increase their test coverage, want to like build automated testing as part of their workflow.
And yeah, work very closely with you to make that happen.
So if that's you, please email me at w at colo.app.
You need that pause for the W. That's right.
The two ads.
Awesome.
Will, thanks for being on the show.
Congrats on both of your projects.
They look really neat.
Thanks so much for having me.
Yeah.
So excited to have been on.
Yeah, you bet.
Bye.
This has been another episode of Talk Python to Me.
Thank you to our sponsors.
Be sure to check out what they're offering.
It really helps support the show.
Take some stress out of your life.
Get notified immediately about errors and performance issues in your web or mobile applications with Sentry.
Just visit talkpython.fm/sentry and get started for free.
And be sure to use the promo code talkpython, all one word.
Want to level up your Python?
We have one of the largest catalogs of Python video courses over at Talk Python.
Our content ranges from true beginners to deeply advanced topics like memory and async.
And best of all, there's not a subscription in sight.
Check it out for yourself at training.talkpython.fm.
Be sure to subscribe to the show.
Open your favorite podcast app and search for Python.
We should be right at the top.
You can also find the iTunes feed at /itunes, the Google Play feed at /play,
and the direct RSS feed at /rss on talkpython.fm.
We're live streaming most of our recordings these days.
If you want to be part of the show and have your comments featured on the air,
be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
This is your host, Michael Kennedy.
Thanks so much for listening.
I really appreciate it.
Now get out there and write some Python code.
I'll see you next time.