Have you heard about DuckDB?
Well, join me for an insightful conversation with Alex Monahan,
who works on documentation tutorials and training at DuckDB Labs.
We explore why DuckDB is gaining momentum among Python and data enthusiasts
from its in-process database design to its blazing fast columnar architecture.
We also dive into the indexing strategies, concurrency considerations,
and fascinating way that Mother Duck, the cloud companion to DuckDB,
handles large-scale data seamlessly.
Don't miss this chance to learn how a single pip install
could totally transform your Python data workflow.
This is Talk Python to Me, episode 491, recorded December 10th, 2024.
Are you ready for your host, please?
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 accounts over at fosstodon.org,
and keep up with the show and listen to over nine years of episodes at talkpython.fm.
If you want to be part of our live episodes, you can find the live streams over on YouTube.
Subscribe to our YouTube channel over at talkpython.fm/youtube,
and get notified about upcoming shows.
This episode is brought to you by Sentry.
Don't let those errors go unnoticed.
Use Sentry like we do here at Talk Python.
Sign up at talkpython.fm/sentry.
And it's brought to you by the Data Citizens Dialogues podcast from Colibra.
If you're ready for a deeper dive into the latest hot topics in data,
listen to an episode at talkpython.fm/citizens.
Alex, welcome to Talk Python to Me.
Howdy, thanks so much for having me.
Yeah, it's fabulous to have you here.
I'm really excited to talk about databases.
Databases are so important for making your app work well.
Making them fast surprises me how many people have slow databases.
It doesn't make sense.
We're pretty big fans of databases around here, for sure.
And fast ones as well, right?
As best we can.
That's right.
Well, DuckDB is certainly on the rise in terms of me hearing people talk about like,
oh, have you heard DuckDB?
Have you seen DuckDB?
Have you worked with it?
And I think it continues an interesting tradition of lots of low stress near your application type
of databases.
So it's going to be fun to dive into that for sure.
Before we do, tell us about yourself.
Sure.
Well, thanks so much for having me.
Huge fan of the show.
Really excited to be here.
So I appreciate that.
I work at MotherDuck.
I'm a forward deployed software engineer, which is kind of a made up title.
A couple of companies use it, but it's really a customer facing software engineer.
So working closely with folks to see how MotherDuck fits in with all the rest of their stack.
So MotherDuck is a cloud data warehouse with DuckDB at its core.
So absolutely a huge part of what we do.
I also work part time for DuckDB Labs, which is our partner organization.
And I do blogging and some developer advocacy types of things for them.
And so it's a separate company based in Amsterdam, the Netherlands.
And they are database experts and researchers.
And they're kind of the stewards of the open source project.
Yeah.
Awesome.
What is a forward deployed engineer do?
Do you get called into big companies who want to adopt the technology?
And they say, hey, could you help us do this quicker?
Or are they running in trouble?
And they're like, you said it was fast.
It's not fast.
Help.
Well, don't copy this every query.
So you'll be better.
There's quite a lot of variety.
I think there's definitely some aspects of, you know, hey, can you help me with this?
There's also aspects of as folks are getting started, they're kind of picking out the rest of the tools around the database.
So what BI tool should I use?
What orchestrator should I use?
And then, you know, we do get into some SQL optimization, stuff like that.
So that's kind of the customer facing side.
That's the majority of the role.
There's also troubleshooting that goes along with it, as well as kind of feeding things back into the company, being the voice of the customer saying, hey, we've had three people hit this.
Is there a way we can build something different?
Yeah.
Like everyone thinks they should do it this way.
We need to change our docs or they want this particular feature and we don't have it.
Yeah.
Yep.
It's a good cycle that we've got going.
It sounds really fun.
It's a lot of fun.
The variety is my favorite part.
And, you know, a lot of fun investigation, troubleshooting, you know, got to reframe it as a scavenger hunt.
You know, it's fun.
Yeah.
Every day is like a box of chocolates, huh?
Oh, yeah.
A little different all the time.
You know, you don't know what you're going to get.
I used to do in-person professional training.
You know, I'd travel to Chicago or New York or Beijing and I would show up Monday morning.
I mean, all right, folks, what are we, you know, what's the situation?
Obviously, I didn't know what we were going to talk about, but it was still, it was different every time.
Every week was different.
Sounds like it might be not so different from what you're doing.
Are a lot of these in-person things or are they mostly Zoom style?
It's Zoom style.
You know, just we work with a variety of folks, not, you know, like a couple of really giant customers.
So with that variety means that I couldn't fly fast enough.
Yeah, for sure.
Or, you know, issues I've had as well as like three people on the team are in this city.
Three people are in that other city and one is here.
It's like even if you flew somewhere, you would only be, you'd still be on Zoom.
So you might as well just be on Zoom.
Definitely, definitely.
Absolutely.
The world we live in.
Well, I mean, that's a blessing, honestly, to not have to fly to all these places as well as just be able to pop in and out, right?
I mean, this work from home story.
It's amazing.
It's only getting better all the time.
So let's talk DuckDB and databases.
I think maybe setting a bit of a mental model.
A lot of folks are familiar with SQLite, right?
Yep.
Absolutely.
And so SQLite is a library, not a server that you can use that then plugs into your application, works on a local file rather than a certain thing you run in another VM or however you, you know, there's not a managed SQLite.
Not that I know, I know maybe there's a managed SQLite, I don't know of one.
There are.
Are there?
Incredible.
Yeah, there's a bunch of cool stuff that you can do if you have a database that's just part of your application instead of somewhere else.
You know, another one that I just ran across is Mocha-py or there's no doubt, there's Dashpy, which is a Python wrapper around the, I think it's Rust Mocha caching thing.
But instead of being Redis or something like that, it's like an in-memory thing that you can run for sort of the same purpose.
So DuckDB sort of falls into that realm, right?
Yes.
I think it's an in-process database, just like you said.
So it's definitely a library.
You know, it's a import DuckDB.
So it's not in the Python standard library, but it is on PyPI, just pip install DuckDB.
It's pre-compiled, zero dependencies.
So it is super easy.
Basically, anywhere you can get to pip, you can get DuckDB run in.
So that could be your laptop.
That could be a big, beefy server.
It could be a Lambda function.
It could be inside of your orchestrator, you know, in a GitHub action.
Kind of slots in everywhere.
That's part of the magic.
Presumably, when you pip install DuckDB, it's just downloading a wheel for your architecture, for your platform?
Yep.
Pre-compiled all the combinations.
Yeah, that's really good.
Yeah, if you just sit on the DuckDB.org homepage, you can learn about it as it animates different messages to you.
It says DuckDB is a fast analytical database system, open source database system, in-memory database system.
We'll see what else.
Yeah.
Portable.
So, yeah, it works on most of the places, the main operating systems, right?
Yes.
Yep, it's all over.
Can I Raspberry Pi it?
I'd imagine the answer is yes.
Can I CircuitPython it?
Probably not, right?
I haven't checked that.
You can do iPhone and Android.
There's a Swift client, so you can build iPhone apps and Android works as well.
So, yeah, you could do that.
Works in your browser with WebAssembly.
It'll work with Pyodide in the browser as well.
So, it really goes all over.
Oh, that's really cool.
Yeah, one of the things that I said people are doing interesting stuff with, I had in mind, with SQLite is I saw some folks suggesting using SQLite in the browser instead of local storage and like the local, like all the JavaScript-y things.
And could I do that with DuckDB?
You could definitely do that with DuckDB.
I think the use case is slightly different, but that's sort of the benefit is you can use both.
So, definitely could talk a bit more about the differences, but I'd say in general, a good mental model for DuckDB is kind of a from scratch separate project from SQLite, but taking a lot of the lessons and learnings about what makes people love SQLite and bringing that into the analytical realm.
And that's really, instead of inserting and updating tons of tiny transactions all the time really fast, it's big bulk operations.
Aggregate a billion rows, join a billion rows to a billion rows, that type of thing.
Yeah, doing that in memory in JavaScript is not that great.
Doing that in memory in Python is not that great.
But it sounds a little bit more like vector programming in the sense of kind of like you would do with pandas or pollers, right?
You wouldn't loop over, you shouldn't loop over a pandas data frame processing each item.
You should issue vector operations that apply to every row, like multiply this column by two rather than for every C in column, you know, whatever, like looping it over.
Yes.
So, it is exactly what you said.
It's designed for that.
It's vectorized execution.
So, it's a little different than pandas.
It's, you know, pollers is a bit more similar.
Where instead, pandas will process a whole column at a time.
And that works a lot better than one row at a time until your columns get too big and then it crashes.
Yeah.
So, what DuckDB does is it does it in chunks of about 2,000 rows at a time.
And so, that way you get all the benefits of your modern CPU, you know, hierarchy, your caches, all that, where it's just pumping data through.
But you also conserve memory and you can not get into issues with that.
I will also say it's technically we are an in-process database, not an in-memory database.
Oh, sorry.
If I said in-memory, I meant in-process.
Yeah.
It is, you know, very much an interchangeable word like in English.
We just are very specific about it in database land.
No, you do.
And you do support in-memory databases.
Yes.
But that's not the same as in-process.
Yeah, sorry, in-process is what I meant.
Oh, no problem.
All I mean to say there is, you know, you don't need to limit yourself to your size of RAM.
You know, you can solve one terabyte problems on your laptop with DuckDB, no problem.
Really?
Yes, it handles larger than memory data, both streaming from disk.
So, it'll just read just the pieces it needs as it goes and even in the intermediates.
So, let's say you join two tables together and you, you know, multiply the number of rows.
It'll send things to disk as it gets memory pressure close to your memory limit.
So, it's a lot of effort has been put into that in the last year or so.
So, it's working pretty smooth now.
Yeah, I can imagine that that's super important.
So, I'm really looking forward to talking about schemas, indexes, those kinds of things,
which sound like they may play important roles here.
But you talked about these different ways in which you can use DuckDB.
Looking through the documentation, it looks like it works with not just Python, but quite a few platforms or languages.
Yes, somewhere north of 15.
So, Python is the most popular way to use DuckDB.
We've got some really tight integrations with data frame libraries, which we can definitely talk more about.
There's a lot of Java use out there.
So, JDBC, we've got a JDBC driver.
You can use it in JavaScript, both in the browser with Wasm or on the server with Node, popular Node package.
You can also do Go, Rust, C++, C.
I think there's like a community-driven Ruby client, you know, really all over the place.
So, .NET, C#, you can use it from .NET, all over.
Yeah.
Yeah, that's awesome.
And I'm guessing it's interchangeable, the file?
Yes.
So, just like SQLite files are designed to be read for a long time, they're very portable.
DuckDB just kind of reached the 1.0 milestone in June.
So, super excited about that.
And with that, you know, promised stability with the file format.
And that means that we expect for the next somewhere around five years to have your DuckDB files be totally compatible,
where you can read a five-year-old file five years from now type thing.
Yeah.
Which means you can, it's like SQLite in that you can fit all your tables and all the relationships between them all in one file.
So, that's one nice thing about SQLite.
You can email the whole database.
You can do the same with DuckDB.
But DuckDB is going to store it a lot more compactly if you've got a lot of data.
Oh, really?
Okay.
You guys have worked a lot on the file format.
It's, again, taking inspiration from SQLite, the format is very separate.
And in databases, you kind of have a pretty hard fork in the road pretty early on in your architecture,
which is you want to be row-based or do you want to be column-based?
Right.
And row-based is SQLite and column-based would be your pandas, your pollers,
and most of your cloud data warehouses, your snowflakes, that type of thing.
And once you go column-based, suddenly your compression is amazing because you store data that's very similar right next to each other.
So, you can really compress it.
You know, your dates are back-to-back.
Instead of, you know, a date column, string column, integer column in a row-based store, they don't compress well.
So, we can get somewhere around 5x the compression typically.
Okay.
That's really great.
And you could take this file and you could put it into S3 or use it with some sort of Jupyter Notebook, right?
And just, they could just grab the file and run with it.
And it's all the data, yeah?
Yes.
Object stores are really the name of the game there.
You can even work with a file on Object Store and read it without having to download the whole file first.
So, DuckDB supports something like SQLite in that it's got this attach syntax.
So, you can say, hey, I want you to attach this file and then just read the pieces of it that I actually query, which is pretty slick.
Yeah, that is super slick.
All right.
Let's, let me scroll down here.
And let's talk about maybe using it from Python.
Give us a sense of, like, what working with DuckDB is like here.
You bet.
So, you've got your pip install DuckDB, which will download that pre-compiled binary.
It's like 20 or 30 megabytes.
So, pretty close to instant.
Then import DuckDB, and then you can do DuckDB.SQL.
And then within that function, you just pass in a string of your SQL statement and it'll execute.
It's really that simple.
And so, it follows the DB API if you want.
So, you can get back your typical suples.
Or you can say .df at the end and get back a Pandas data frame.
Or .pl and get colors.
All kinds of stuff.
Yeah.
I saw that there's a lot of to and from the popular data science libraries, which seems really nice.
You work in your data science library or maybe run a query and get a subset of your data.
And then maybe plot that with PlotLayer, Altair, or pass it along to other things that expect the data frame, right?
Yes, exactly.
A lot of the DuckDB ethos is don't ask folks to ship their data necessarily somewhere else.
Don't ask them to change their workflow dramatically to use a database.
Meet folks right where they are.
And that means you can have one line of code be in your data frame library of choice.
Pandas, Polar, or Arrow.
And then a line of code in DuckDB.
And then you're right back in your data frame in the next line.
So, it fits really wherever you want.
It's a great fit if you want to throw some SQL at a problem.
Some problems are easier to formulate in SQL, I think, than in data frame libraries.
And vice versa.
But also, some libraries, it's harder to scale larger than memory.
And DuckDB does have a lot of nice performance under the hood.
So, maybe the hardest part of your workflow, you can slide in DuckDB and make the minimal change to get it working.
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 at 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 dot info, which was an integer-based enum.
So the logging 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.
It seems to me like maybe you put all of the data into DuckDB, and then you can ask questions which result in Python data science objects that then you can work on, where those questions result in, give me the stuff for this state or this time period or something like that where it's a reasonable amount of data.
But if you tried to just load it all, then it would say no.
I think that's a great way to go about it for sure.
You know, another common workflow is to do some, you know, similar things, but with Parquet files or CSVs or JSONs.
So in the same way you can store a lot of your data in DuckDB, you can periodically write chunks out to Parquet or read in from Parquet, all that type of stuff too.
Yeah.
Tell people what Parquet is.
I know it comes from PyArrow or the Arrow project, right?
Where does it come from?
I know they use it.
I don't know if they came up with it, but yeah.
They definitely collaborated and were a big part of it.
So it's a community developed open format.
It's Apache Parquet.
So it's a open source community driven and it's a columnar format.
So instead of storing things by rows, it's columnar storage and it's chunked columnar storage.
So it's sort of like somewhere around every million rows or so you kind of write out another chunk.
And it ends up being a really good format to store large amounts of data in the cloud.
And it's typically what's underneath a data lake or a data lake house.
The vast majority of those have Parquet under the hood.
I see.
We love the Parquet format at DuckDB.
We read it and write it.
We have a custom from scratch reader, custom from scratch writer for it.
We actually prefer our own format given the choice as well.
Parquet has been around for a decade or so at this point.
And we've added a few things over time into DuckDB that are new.
Yeah.
Parquet is one of those things that Pandas 2.0 supports it, right?
Polar supports it.
It's pretty universal.
So it might be a good way to get data from that you've worked on before into DuckDB.
Yes, it's great.
I think, you know, most universal CSV, most difficult, also CSV.
Parquet is a really great compromise there.
Yeah.
Hold on.
My computer is lagging.
It's distracting me.
I apologize.
One sec.
Scroll, scroll.
So DuckDB works well, it sounds like for the data science story, like it's built for the data science story.
If I was wanting to store relational data, you know, maybe I've already got DuckDB working for something.
I'm like, you know, do I necessarily want to bring SQLite into the story as well and have these two things?
Is it possible to, say, do relational type things with DuckDB?
Yes, that's a great question.
So I think DuckDB is trying to bring the best of both.
It is a full relational database.
And as well as supporting some of the, you know, data science workflows that you typically in the past would have been doing in a data frame.
So DuckDB is an analytical system, not transactional.
So it's not going to be the fastest at doing individual row operations, but it supports them all.
And it supports them with full asset transactions that you'd expect from a database where you won't get database corruption, even if your computer cuts out.
You know, it's got that kind of robustness that you expect from a database.
So part of the story, though, is that with an analytical database, it's typically not your only database unless you're doing data science work.
If you're building an application, you're going to want a transactional database for, you know, saving your, you know, when a customer places an order, you know, all that type of transactional stuff is still critical.
So typically DuckDB is going to be layered in addition.
And the interoperability story there with DuckDB is pretty, pretty fantastic.
You can actually read SQLite files directly with DuckDB.
And it's going to be, if you're doing any sort of advanced processing on them, it's going to be a lot quicker in DuckDB.
You can even read Postgres databases.
You can read MySQL databases.
Oh, wow.
There's a community extension to read BigQuery.
So it's really a universal Swiss Army knife in a lot of ways to read from those operational data stores, but to do those analytical tasks.
You know, look at all my orders.
What was the most popular five products?
You know, that's going to be a tough query for a transactional system, but bread and butter for DuckDB.
So when you say read from, let's say, Postgres, does that import it into a table in DuckDB or does it translate the queries over to the underlying data system?
What's happening there?
It's a great question.
We are communicating with Postgres, so we're not importing everything.
We're sending the query to it and we're reading all the data from Postgres.
Typically, that's going to be sparing the table or forming a view from Postgres.
And then after that point, bring it into the DuckDB engine for subsequent processing.
But you don't have to migrate all your data.
It's kind of a data virtualization is one of the buzzwords.
It's been around a little bit.
But, you know, it's getting to get some of the benefits of analytical performance without having to move your data first.
It'll definitely be more performant if you put it in an analytical format like Parquet, like DuckDB, like an analytical database.
But you get a big fraction of that benefit with the engine part, which is the vectorized engine of doing things 2,000 rows at a time instead of one row at a time.
That's a lot of it.
Yeah, that's a huge benefit.
It's almost like microservices for databases.
You can click the things together.
But the benefit would be, you know, that if you have an operational database, that is, it's getting read to and written to and read from in real time.
When you ask questions about it, it's using that real time data.
It's not, well, we did an export last night and here's what we know.
You can just get more live data, I guess.
Yes, that's definitely a use case for that.
You can kind of go either end of that spectrum.
You can use that as an easy way to import or you can pull it live or you can kind of do midway and say, for any data older than an hour, use what I extracted.
But grab the last hour right out of the operational database and get the best of both.
Oh, wow.
Okay.
Yeah, that'd be pretty wild, wouldn't it?
So you say that you all have the simplest or friendliest SQL syntax.
What's the story with that?
Sure.
I think a lot of that is around part of the origin story of DuckDB is reaching out to the data science community and hearing feedback that we've invented this entire other thing called data frames because we didn't love databases.
Yeah, exactly.
They didn't answer the questions we wanted or whatever.
Yeah.
Right.
It was, there was a lot of friction.
And, you know, if you've, you know, folks have installed Postgres and set it up, there's a lot more to it than, you know, import pandas as PD.
It's just a different level of hassle that you have to do.
The SQL syntax is no different.
You know, SQL is an old language, much older than Python.
And it's got a lot of very interesting behavior that, you know, by modern standards is very different.
So with DuckDB, we've really pushed the envelope in a lot of ways.
Nice.
Well, you know, many of the things that relational databases were built for and when they're designed, this was the 70s and they had different, you know, memory was expensive.
Disk was expensive.
So they made these trade-offs in that world, right?
Yes.
And it's absolutely.
There's definitely some aspects of SQL where it's been around a long time, so it'll be around forever.
But what DuckDB is trying to do is have it not be frozen in time forever and really push the whole language forward.
So there's a couple of cool ways.
The syntax itself is designed to be both easier to use and also push it into areas that are new and different for databases.
So easier to use, for example, in SQL, if you want to aggregate, you kind of typically need two ingredients.
You need an aggregation function like a sum or a max or an average.
And then you want to group by clause to say, what's the level of detail I want to group at?
Do I want to group by customer or customer and order?
You know, what level of detail am I looking at?
DuckDB can actually infer that level of detail with group by all and just say, whichever columns you're looking at, if you're looking at the customer ID and you're getting an average,
okay, I'll just aggregate it up at customer ID level for you.
And so it cuts out a whole clause of SQL.
You basically never have to worry about the group by clause ever again.
Just put the keyword all, you're good to go.
I love it because the group by clause is hard.
It's anytime you have to edit something in two places, just you're already in trouble, right?
I mean, just, you know, the don't repeat yourself is very valuable.
Yeah.
The joins and the group buys and the whole aggregation pipeline stuff, which is incredibly powerful,
especially in analytical databases like DuckDB, but also hard.
Yes, absolutely.
And I think obviously anything we can do to reduce the friction there is helpful.
So we are talking about the friendly SQL dialect.
I'll throw a teaser in there to say there are ways to use DuckDB without SQL as well in very Pythonic ways.
So you really can have it both ways if you want.
Okay.
What about ORMs?
Is there a concept of a ORM for DuckDB?
I'd have to check exactly which ones support it.
But I know at MotherDuck, we're working on a TypeScript ORM that'll support DuckDB SQLize.
I'd have to check which other ones are out there that support it.
But nothing in principle really stops it.
We support the fundamental things you need, like transactions, like, you know, all the other pieces you need.
Yeah.
Basically, if it runs on pure SQL, then, you know, you should...
ORMs are mostly about I'm querying against classes, and then I'm going to turn that into SQL for you.
And then the things that come back, I'm going to turn them into objects, right?
Like, I feel like both sides of that would be fine.
Yes.
And it is, you know, it's a relational database.
So it's not...
There are many...
It'll look a lot very similar to the ORMs themselves, so it should be very compatible.
Yeah, it seems possible.
It seems totally possible.
All right.
So maybe let's talk through a little bit of the ways of working with DuckDB through, maybe connecting, running some queries, updating.
But let me first ask you, what does a schema look like?
If, for example, if I'm going to work with Postgres or SQLite, I need to run create scripts to create the tables and the indices and that kind of stuff before I can even talk to it, generally speaking.
Is that needed for DuckDB?
It doesn't look like it from the examples that I've seen, but how does that work?
I think in those other databases, there are some ways where you don't necessarily have to do that, and DuckDB follows that same approach where it can automatically create tables for you based on the query that you pipe into it.
So you create a table as the result of another SQL statement, and it will just automatically create that table with the data types that you pass through.
So one key note, if folks really know a lot about SQLite, one of the defining characteristics of it is that it is very much non-typed as much as possible.
VectDB is very much more traditional in that it does have typing.
It does take full advantage of having nice numeric data types, date times that are true date times, not strings.
It'll do its best to auto-convert for you, but it really does make it very easy.
You can just create a table as, for example, create table as select star from this parquet file.
It can really be that easy.
It'll just auto-create the table based on the parquet file.
Okay.
Yeah, that's really neat.
And a lot of those have their columns have data types and stuff, right?
Yes.
And we have also invested quite a lot in our CSV reader as well.
So the CSV reader we consider to be up there with the best on the planet.
It auto-infers the data types by sniffing the CSV to really deduce it.
And it handles some seriously wacky CSV files.
Okay.
CSV files.
I mean, whatever you're imagining, it's worse.
It's worse than that.
But DuckTB is okay and ready to handle it and making it easy.
Because it really aligns with the DuckTB ethos, which is a database shouldn't be extra work.
It should be saving you work.
Yeah.
And most of the time, step one of a database is import your data.
And a lot of databases, that's not that easy to just import your data.
Especially if it's not exactly the format of that database, right?
It's like, well, okay, I have a .SQL file.
It's a bunch of update statements.
Sure, that's easy to import.
But here's my CSV and actually you need to transform it or whatever.
Yeah.
Yes, there's a long tail of complexity there, but DuckTB is really trying to handle that
and just make that first experience using a database just straight out of the box.
Really easy.
This portion of Talk Python to Me is brought to you by the Data Citizens Dialogues podcast.
If you're ready for a deeper dive into the latest hot topics in data,
you need to listen to the Data Citizens Dialogues podcast.
Brought to you by Colibra, the leader in data intelligence.
In every episode of Data Citizens Dialogues, industry leaders unpack data's impact on the world.
From big picture questions like AI governance and data sharing to more nuanced questions like,
how do we balance offense and defense in data management?
You'll hear firsthand insights about the data conversations affecting all kinds of industries.
With guests sharing unique stories from some of the world's largest companies,
such as Adobe, Fidelity, Deloitte, Hewlett-Packard, McDonald's, and even the United States Coast Guard,
you'll get an amazing look inside how these organizations handle their data.
My favorite episode is Solving Data Discovery with a self-service approach.
It's an interesting look inside creating a single source of truth at an online university.
Check them out and try an episode for yourself.
Find Data Citizens Dialogues at talkpython.fm/citizens.
That's talkpython.fm/citizens.
The link is in your podcast player's show notes.
Or just follow Data Citizens Dialogues on Apple, Spotify, YouTube, or wherever you get your podcasts.
Thank you to the Data Citizens Dialogues podcast for supporting the show.
So you have some interesting data ingestion.
This is a good thing, not a bad thing.
Data ingestion options.
You have a, it feels a little bit Pandas-like.
You have a read CSV, read Parquet, read JSON.
And then it's just, as you sort of hinted there, it's like part of the database now and you can ask it questions.
Yes, so you could absolutely do that just with the read CSV and it'll import there.
You can also even just read it without importing.
So for example, when we're running that read Parquet, it's lazily evaluated, much like Polars or some of the other more modern data frame libraries are,
where it's building up this relation object that says, once you look at the results, start by reading the Parquet file and then process the next few steps.
So you could do something like read Parquet, filter to these things, aggregate up on these columns.
And it will actually do all those operations together.
It'll optimize them to do them in the right order to pull the least amount of data.
And then only at that point will it, you know, materialize what it needs to.
So the examples that you're looking at on screen are, you know, DuckDB.SQL select star from a Parquet file.
You don't ever even have to read that part, you know, write that Parquet file into DuckDB format.
It's just going to read it and return the results to you straight as a pass through, as an engine.
Oh, that's really cool.
So if it were a million lines of that, I could just iteratively pull through it.
Yes.
It'll just chunk through it at nice low memory usage and just, you know, pass those results out to you.
And then if you process them also in batches, you can keep your memory, you're super low and take advantage of DuckDB being a streaming engine and not bring it on to memory.
Right.
Well, let's say I want to read a CSV file, but then put it into a persistent table in DuckDB.
What do I do for this?
Yes.
You could say create table as my improved CSV table as select star from path to my CSV file.
Will it copy over the schema?
It will infer the schema as best as it possibly can, and it will automatically define the schema for you.
Nice.
What's the nullability story in your schema?
I think...
Do you support nullability or are there things that cannot be null?
Yes.
It's more traditional in the database in that everything can have a null value in the column.
I think in Pandas, that was a little bit complicated by the fact that they were using NumPy in some cases, but extending beyond NumPy in others.
But in DuckDB, it's more of a traditional database story in that you can have a null value wherever you choose unless you define a table to say this column doesn't allow nulls.
Right.
You can do that if you want.
Yeah.
I remember that was one of the things that caught me out with SQLite.
I think it doesn't support...
I can't remember which way it went.
It's been a while.
It doesn't support non-nullable columns.
Like, everything is nullable or something like that.
And it was like, wait, why is this not failing when I put in this wrong data or something along those lines?
You know, SQLite is incredibly flexible and there's a lot of benefits to it.
At times, that can mean that things pop up later in the lifecycle than at the beginning, like you said.
So with SQLite, you can put a number in a string column and a string column and a number column, you know, and it'll mostly work until it doesn't work.
DuckDB will be much more explicit about that, but it offers a lot of tools where you can auto-convert or it'll auto-convert for you.
So you kind of get the benefits without the cost.
And it actually has what's called a union type where you can actually have one column that can have strings and numbers in it if you know that you're going to have a little bit of both.
So really, best of all worlds, I'd say.
Yeah, I think that's more common in the data science, data lake space.
You've got a bunch of data, you pull it in, and then you're going to clean it up and work on it.
Whereas in maybe a relational database powering a web API, like, nope, users always have an email.
That's just how it is.
Right.
Yes.
Okay.
So I'm looking at some code on your documentation here about getting started with Python for pandas.
And I need some help.
I need some help.
It says import DuckDB, import pandas as pd.
This is all normal.
And then it says pandas df, it's a variable, equals pd.dataframes.
So it creates one.
And here's where I need the help.
The next line is duckdb.sql, select star, in the quotes, pandas df.
How do those two things connect?
That's a great question.
Because you never, like, take the actual object of the data frame and show it to DuckDB in any way.
Like, you don't pass it to a function or set a property or nothing.
Exactly.
And this is the benefit of being an in-process database.
We are in the same memory space as Python, which means we can actually read the Python locals for its local variables.
And DuckDB has been built from the very beginning with this concept of interchangeability of storage format.
That's why you can read parquet files or read CSV files, because we treat them as first-class citizens in our database.
And data frames are no different.
What we'll do first when we see a select statement come in and it's got a table in there.
In this case, it's pandas df is the name of the table.
First thing we'll do is, hey, do we have a physical DuckDB table like that?
Is there a table of that name?
And if we don't find one, we don't give up.
We keep looking.
We say, okay, is there another object we know how to read with that name?
And so we look in Python's local variables.
There's a variable named pandas df.
And we check the class name.
What class is this?
Is it pandas?
Is it polars?
Is it Apache arrow?
And if it's one of those, we can treat it just like a table and then run SQL right on top of it.
Pretty wild.
It's pretty wild.
I think one of the real values there is that you don't have to do, presumably, I'm presuming, you don't have to do a data conversion from pandas into whatever in-memory thing DuckDB thinks is ideal and then back.
That's a great question.
So you definitely don't have to do it all at once.
So pandas, sometimes it is Python objects under the hood, whereas DuckDB is written in C++.
So it will change some things, but it'll do it in chunks like we're talking about.
So it won't be all up front.
But for things like polars and arrow, in most data types, it's zero copy where it's the same format.
DuckDB has slightly different data formats.
And Apache arrow is actually adjusted to align closer to DuckDB in some of their format, like how they store strings.
So DuckDB has really been one of the leading databases in terms of how it handles strings.
And Apache arrow is also making those changes.
Yeah, that's super cool.
You can't write back to these, can you?
You can't say, wait, you can't.
You can't.
You can say update, like the data frame variable, PD data frame set, whatever.
Yeah.
So if you're updating the data frame, you will overwrite the whole data frame.
But DuckDB table, you can run updates on that object for sure.
Yeah.
But you can write data frames for sure.
So you can replace the whole thing.
Right.
But I couldn't change the 172nd row of that data frame with a SQL query.
Or could I?
You would just be making a copy of the object.
Got it.
Yeah, that's what I thought.
You would make the changes, but then you would return as data frame and make a copy of it.
Correct.
We would return a different object in memory.
But functionally, it would be the same.
And DuckDB is fast enough where it would probably be quite performant still.
Yeah, probably fine.
Yeah.
Okay.
I'm not saying that it should be able to do.
I'm just trying to figure out how far down this.
How far down?
Yeah.
How far down does it go?
Yeah.
So it does the same kind of magic with the locals, with Pyro and Polars and so on.
Mm-hmm.
So there's different ways to get data back.
And it doesn't really matter where it came from, if it came from Pandas or DuckDB files itself,
or even just hard-coded SQL.
But you can say things like fetch all, which will return you Python objects, or .df will return
you a Pandas data frame or different things, right?
Yes.
Yep, we've got .pl for polars, .aero.
You could do NumPy arrays if you'd like.
We also support outputting to TensorFlow tensors and PyTorch tensors.
Wow.
Because those are NumPy under the hood in a lot of ways.
So we can output to that as well.
Okay.
That's super cool.
Do I need to be worried about little Bobby tables, SQL injections?
We could definitely pass in parameters that will get escaped properly and all that.
You know, with DuckDB, I think that in general, we take the approach of being
super flexible, but there's a lot of options to lock it down should you choose.
So the select star from any CSV file on my hard drive, you could turn that off if you want.
For example, likewise with the data frames, you can disable that also.
Yeah.
I guess what I'm asking more, is there a concept of a parameterized query or something like that?
Yes.
So you can follow the same Python DB 2.0 kind of API spec.
You could do .execute and pass in a query with placeholder parameters and then pass in those as arguments.
So you can absolutely do that.
It tends to be not good for bulk ingestion.
The reason for that is Python objects just have a lot more.
Oh, well, I lost your audio.
Did you possibly hit something that hit a mute button?
I did.
Sorry.
Okay.
Sorry.
Give us the...
You said it's not good for bulk ingestion.
Let's go from there.
Yep.
Sorry.
Oh, all good.
That's on me.
So you can insert straight from Python objects with parameters.
It works really great.
It's very convenient, but it's not great for bulk ingestion.
Inserting a million rows that way versus a million rows in a Pandas data frame, it's going to be a couple orders of magnitude faster to do it through a data frame.
Yeah.
Yeah, absolutely.
So if by default, if I just do WDB.sql, this is working in this correctly this time, in memory database.
But if you create a connection to a file, then that where you just call it whatever you want, right?
Like in your examples, you got file.db.
That will then start persisting to that file, right?
But it's pretty simple to do either.
Yes.
You're just changing the connection path.
And if you pass in no path, it'll be in memory.
Otherwise, you can point to a file.
And it's really that straightforward.
It'll save all your tables into that same file, nice and compressed in columnar format.
And then now the format is all stabilized.
You can throw that on an object store, share it with anybody, put it in your data lake, anywhere you want it to go.
Can I read from objects or can I give it an S3 connection?
Yes, indeed.
You can read from any of the major clouds.
So AWS, Google, Azure, you can read individual files or actually it'll understand hierarchies of files.
So if you have like a top level folder for a year and a folder for month and day, if you filter for I only want three days worth of data, DuckTB will only read three files.
So it's pretty slick.
Oh, wow.
That's wild.
Okay.
Yeah, that is really slick.
And you can even write out to those as well.
So you can actually write on object stores too.
That's amazing, actually.
And a lot of less hyperscale clouds, I don't know, I was almost calling them lesser clouds, but I think of almost as like even better clouds.
You know, DigitalOcean, Hetzner, Leno, some of these smaller places, a lot of them have their own object store.
And the object store API is just a different connection string for the S3 API, right?
So it sounds like you could probably get that to work as well.
Let's pass that.
I believe I've seen MinIO used, which is even like self-hosted if you want.
So if it handles MinIO, you can kind of put it wherever you want it.
Yeah, yeah, that's for sure.
MinIO is awesome.
I haven't got a chance to put MinIO into any useful work, but it's like a self-hosted S3 basically, right?
Which is really cool.
Yes.
Yeah.
So I don't know.
It seems like a really neat system.
But it's also, MinIO is complicated.
You know, it's not easy to set up and run.
It seems like there's a lot going on there.
So that's why I haven't done it yet.
I'm like, this looks amazing.
Oh, this looks complicated.
What else am I going to do today?
I think S3 is pretty great.
Drop a file, read a file.
So it's not a bad starting point for quite a while.
Yeah, absolutely.
So with this connection object, like if you want to have a persistent database, right?
You create a connection object and then it has basically the same API as the DuckDB itself.
So you can run SQL queries.
You can do table stuff on it and so on.
What's the concurrency story with this thing?
Like, so for example, what if I open, what if I try to use DuckDB in Flask and I have Flask running in G Unicorn and I say, G Unicorn, please use four worker processes.
And I try to talk to it.
It's a great question.
So am I going to be having a bad time or having a good time?
It depends a little bit.
It depends.
It depends a little bit.
So, but yes, it's, there's some trade-offs.
There's reasons that there are databases that are in process and that there are databases that are client server.
And so whenever you want to write data to DuckDB, you can only write data from within a single process.
And you'll open up a read-write connection and it will actually disallow any access from any other process.
And it'll be single process access while you're doing reads and writes.
It does handle multi-threading just fine.
So you can have multiple Python threads.
You get nice parallel performance that way.
No problem.
But it's all within the same memory space because you're using threads.
So we're pretty excited about free threading coming soon in Python.
Yes.
Yeah.
Well, that's going to knock out the need for the web, the web garden, not the web farm, the web garden,
where you've got a bunch of these copies of the web server running in parallel because they're all trying to have separate gills so they can be more concurrent.
That's not the only reason, but that's a big reason in Python.
That's definitely a big reason.
So that we're excited about.
If you want to be read-only, so since DuckDB is an analytical database and since we can read from files,
there are a lot of use cases that are read-only where if I'm reading from parquet files on an object store,
I might not be doing any write operations at all, at which point multi-process,
access is totally fine as long as you're in read-only mode for all of those processes.
I will add one big other thing to look into, though, is where I work, which is Mother Duck.
So we're a cloud serverless data warehouse built around DuckDB and we'll handle the concurrency side.
So it's really taking this amazing single-player DuckDB experience and bringing it into the cloud as a full multiplayer cloud data warehouse experience.
So you get concurrency, you get automatic managed storage, it's very efficient, and you also get access control and some of the things you associate with a large-scale database.
That's the story. If you need concurrency but you're using DuckDB, I think Mother Duck is a great option.
Right. So this is kind of DuckDB as a service. Is that right?
That's definitely a key piece of it. I think we have a... DuckDB is a huge part of what we do and it is the engine under the hood.
I think we are using that to really be meeting the use case of being not just sort of a cloud hosting for DuckDB, it's to really be a full data warehouse with DuckDB as the engine.
So a little bit of a distinction there, but just as a whole organization could kind of use it as opposed to just one person, you know, cloud hosting it, something like that.
Yeah. Well, it seems like a really, really great service. And I guess it's worth calling out that DuckDB, the thing that runs in your process, is available on as an MIT licensed thing, right? Which is, that's pretty amazing.
And you, I saw somewhere, I can't remember where I saw it, but it's something like, you'll promise to be MIT, to stay MIT. No rug pulling, the rugs will stay.
Yes. So it's a pretty cool kind of corporate structure. And if you can say a cool corporate structure, we'll see if we can get away with that. But as far as corporate structures go, it's pretty cool, right?
So there's actually three organizations at play. And one of them is a nonprofit foundation called the DuckDB Foundation. And they actually own the intellectual property for DuckDB.
And that is what ensures that it'll be MIT licensed forever, because it is not a company that owns DuckDB, which is amazing.
So there is like, it's not even possible to do a rug pull, even if somebody wanted, which nobody does, right? It's not even possible. It's against the law, which is pretty cool.
So yeah.
I guess maybe give people, I threw that out there. There might be people who don't know what that means.
Oh, what a rug pull is?
Yes, exactly. Yeah. What is that?
You know, certain products, once they're open source, they begin to, they get funded in certain ways to where they need to be, you know, selling it as a product.
And at times that means that either they don't always put everything back in open source, or there's different licensing models that get changed,
so that the license is a little bit more restrictive than it was in the past.
Kind of the typical maneuver there for a couple different companies has been around Amazon will just host your product.
And then it's very hard to have your own business if Amazon just hosts it.
So we're not in that situation with DuckDB because it's open source forever.
But also Mother Duck is not just wrapping DuckDB.
We're innovating at the, at that service layer, where with Mother Duck, one of its secret sauce ingredients is it's not just a cloud service.
When you connect to Mother Duck, you have DuckDB running locally and in the cloud.
And one query, one Python statement can actually run partially in the cloud and partially on your laptop.
Oh, wow. Okay.
And we actually can, we can choose the optimal location for that to run based on your query plan.
We actually do that as a part of the optimization to say, where's the most efficient place for this to run?
And that's some serious secret sauce that, you know, it's not just, just wrapping, you know, an open source solution and hosting it.
That gives some really nice benefits for things like the local development experience.
You can develop locally at light speed and then push to the cloud at the final step.
Or alternatively, kind of reverse the polarity.
Maybe your first step is to bring everything down locally in a cache and then do all kinds of data science processing on it.
So it's, it's very convenient to have both local and cloud.
I see.
Kind of like we talked about writing a query and then turn it into a data science object and then asking questions.
This is a little bit like distributed versus local, but staying within DuckDB.
It's definitely, you get to use server side computer, local compute, however you'd like.
Yeah.
Super cool.
I love the idea of it.
It's a lot of fun.
We're, we're, we're doing a lot of fun things and we, we, you gotta have fun with it as well.
You know, what do you call someone who works at mother duck?
A duckling.
That's the second most popular one.
We actually were mother duckers, Michael.
Oh, okay.
Mother duckers.
All right.
You gotta have fun with it.
Right.
Otherwise it's all just ones and zeros at the end of the day.
Right.
You have to have fun with it.
Yeah.
You have to have fun with it.
You should.
I don't know.
Ducklings.
But mother duckers is good.
Still.
I guess ducklings might send the wrong message.
They're all good.
Do you want to, do you want to like sort of a tough, tough persona or facade, or do you want
to like a, you know, coddled, whatever?
No, it's a great name.
It's, you know, like if you look at the branding on our website, you know, we're not going for
like, we're not like a super muscly duck, you know, at our level ranges.
We're definitely in the playful side.
And part of it is because we really think that back in the big data era, we believe the big
data era is over here at Mother Duck.
And the reason for that is you no longer need 50 servers to answer your questions.
It turns out laptops are pretty daggone fast now.
Yeah.
And you can do a lot.
Even, even if you're not able to handle it on a laptop, how about one giant node on AWS?
You can rent a node with multiple terabytes of RAM, of RAM.
I mean, you could do a lot, right?
So at that point, what is a single node?
You can kind of do, do almost anything that you need.
So as a result.
And single server versus distributed is way easier.
Yes.
It allows you to innovate a lot faster.
You can use better algorithms.
So in many cases, it's actually just plain old faster to do it that way.
A lot of benefits.
But what we realized fundamentally at Mother Duck is, in a lot of ways, DuckDB as well.
The scale of data shouldn't be the most important thing anymore.
It should be how easy it is to use.
You should be able to do select star from a CSV.
You know, it doesn't take scale to parse a CSV file in an intelligent way.
It takes elbow grease.
It takes innovation in terms of the algorithm.
But at the end of the day, it's not about how big is your CSV file.
It's about how long did it take me to get my job done.
And in Mother Duck, it's a similar kind of pragmatism.
And our branding, I think, does a really good job of showing that.
I think so.
Well, I asked you about half of what I said I was looking forward to asking about, which
was the table schemas, how to do that.
However, what about indexes?
Sure.
I think indexes are a great question.
So DuckDB does support indexes.
But in many cases, it's not necessarily something that you need.
And the reason for that is because of the workloads that it's best for, but also because of columnar
databases.
So when you have a columnar database, by default, it's going to create some rough indexes for you
automatically.
So every about 100,000 rows in DuckDB, we create an index there that says, what's the minimum value
in this chunk and then the maximum value in this chunk.
And what we'll do is then if you run a query that says select data from this week, we're going to check,
hey, which blocks have any data from this week?
And we can skip 90% of your data because we know that it doesn't match that filter.
But that's not like an individual row index.
It's an index for every 100,000 rows.
And it's for the analytical queries where you're looking at trends, where you're analyzing
large amounts of data, it tends to be really the optimal way to go about it.
And that's the way most systems do it.
There is an external index you can add.
It's an art index, an adaptive radix tri index, which is a pretty cool way of doing it.
It's a little different than the B tree in SQLite, but it allows for those vast point lookups
where if you want to grab one row, you can get a very quick mapping to that individual row.
It tends to be just less necessary in DuckDB to do that, but we have it if you need it.
I'm realizing that I need to learn more about databases, especially columnar ones, because
they're not matching my mental model as much as, say, for relational or document ones.
It's definitely a different world.
Different world.
And that's, I think, the fun of it is I think of databases as an infinitely deep rabbit hole
of really just fun optimizations, fun things to learn about.
So a lot of exciting stuff.
Yeah.
When you get that stuff right, it's like magic.
It's like, how could it possibly answer that so quickly?
At the same time, when it's wrong, it's really frustrating.
You know, you go to a website and you don't say, oh, you know, click this thing here.
And then you try to, and it just sits there and spins.
Like, I know this is happening without an index.
And I know this could be so easily fixed.
And it's just not.
Why, why is it so bad?
But, you know, you can make your stuff fast.
You can't make other people's stuff fast.
So I guess it's an advantage.
Makes you look good.
Yes.
So I think that the workloads are just so different, but the mental model, it does open doors in
a lot of ways.
So for example, if you want to get the average of like a billion rows at DuckDB, it's a couple
seconds.
Wow.
It's that fast.
You know, so just the things that you can do with that kind of tool, an analytical oriented
tool, really unlocks things you can do in an application sense.
So data apps, we think are a really interesting market for both DuckDB and MotherDuck, where,
you know, it's not just show me a little bit of data.
Maybe it's an event tracker, like a fitness tracker.
You know, I want to see the history of my bike rides for the last month.
And I want to see the trends, my moving averages, you know, highlight the outliers for me.
You know, there's a lot of heavy analytical work to be done in data apps that an analytical
database is really good for.
Yeah.
Give us some, I don't know how much you can share.
I know you interact with these customers quite a bit.
So, you know, but I don't know how much you can share.
Give us some senses of what people are doing.
Sure.
On the MotherDuck side or the DuckDB side?
Well, you know, give us a little example from each, maybe that you think is representative.
You bet.
I think on the DuckDB side, I think some of the very interesting things are when you use DuckDB
as a data processing engine, where each individual processing task is, you know, one node, but you're
doing a ton of them in parallel.
So some companies will actually take DuckDB and use it to transform one Parquet file into
an aggregated Parquet file.
And they'll just set it up on a trigger.
So when a Parquet file gets added, they'll automatically just create a little pipeline with DuckDB and
convert it into a much, you know, cleaner, more aggregated form.
And you could do that at huge scale.
So there's some companies that are doing huge amounts of data processing, you know, with
DuckDB.
Tons of tiny DuckDBs, a flock of tiny DuckDBs running behind the scenes.
So that's an interesting use case that, you know, DuckDB originated as a data science tool,
but I think the data engineering side of DuckDB is also very exciting, where it fits really well
in those pipelines.
On the MotherDuck side, I think what we see is a lot of cases where the transactional database,
you know, a lot of cases, it's Postgres.
It's got a really friendly SQL syntax, and it aligns very closely with DuckDB's SQL syntax,
where Postgres just is too slow for those kind of trend-oriented aggregates or join queries
that you want to run.
And MotherDuck ends up being a really great way to very easily get a lot more speed in those cases.
And that could be speed for data engineering tasks.
Like some folks are running data processing jobs with this tool called DBT, stands for Data Build
Tool, and it's a Python library.
And they were running these, you know, sets of computation and aggregations, and they would
take, you know, eight hours.
And if it starts running, you know, 2 a.m., by the time it errors out, you've lost your whole
day of your data analysis being up to date.
Yeah, you better get it right, right?
Better get it right.
Unfortunately, DBT does also stand for, you know, behavioral therapy of a certain kind.
So you've got to search for DBT data.
It's a tough acronym.
Yeah, it's a little short.
Yeah, DBT Python, that'll get you there too, yeah.
With MotherDuck and with DuckDB, you can take that, and instead of being eight hours, you can
run it in, you know, 15 or 30 minutes.
And just that scale of change means that, you know, it's just a far more delightful experience
to do those kind of data pipelines on an analytical tool as opposed to a transaction.
So that's one.
The other one is business intelligence tools.
In a lot of cases, those start to get really slow on a transactional database because if
you're looking at a graph, it's by most of the time, it's a trend.
And most of the time, it's looking at a lot of data to plot.
Even if it's just plotting a few points, it's looking at a lot of data to plot it.
And DuckDB is really excellent for that, and MotherDuck as well.
There's actually a lot of business intelligence tools where they are powered by DuckDB.
So Mode was acquired by ThoughtSpot.
They're powered by DuckDB.
Hex is a data science notebook.
They have DuckDB as a part of their architecture.
There's a couple others.
We talked about some of the data types.
What about JSON or document type of things, right, where you've got a little hierarchical
data?
You know, there's on one end of that spectrum, we have MongoDB.
That's all it does.
And on the other, you've got relational databases like Postgres that say, well, this column can
just be JSON arbitrary stuff.
Yes.
And we're in that space where we absolutely believe that's how most things are, a little
bit of both.
So there is a full JSON data type in DuckDB.
And so you can store any arbitrary document in there and then process it with some really
fast JSON processing.
We can also take JSON data and automatically split it out into columns if you want to unnest
it.
So you can kind of go back and forth there.
Oh, nice.
There are also specific DuckDB nested types if you want to enforce the typing at the column
level, but you want to be nested.
So you could say, I know these are going to be my keys.
I know this will be my structure.
You can store it all in one column and it'll be very, very quick to work with.
So you kind of have both.
You have the full flexibility with JSON and then you also can have nested types.
Can you query into them?
So if I have a JSON thing that's got like purchases and then it's got a bunch of purchase objects
and then like values, can I say, give me the ones that have over $100 purchases?
You can do much like Postgres and SQLite have the ability to extract pieces of JSON with
the path syntax of like go to this path and pull that value out.
You absolutely can do that in DuckDB as well and say, okay, navigate to the customer object
and then inside the customer object, go to this object and absolutely.
Yeah.
Super cool.
All right.
Well, I think there's probably more to dive into, honestly, but we've covered it.
I think we've covered it pretty well.
I think DuckDB is super exciting for the possibilities that it opens up.
You know, there might be a ton of people out there who haven't heard of it or really just
heard of it in passing and didn't really know.
This in process stuff that you can do, it really makes it quite accessible, quite easy,
lowers the bar to getting started, right?
You don't have to understand connections, security, servers, daemons, all of that.
So I'm excited to see where this goes.
It's already got a ton of traction.
So final call to action, maybe tell people who are in that group, what do they do?
You bet.
I think, you know, obviously, pip install DuckDB, give it a try.
It's anywhere you can use it.
MIT license, it really can fit anywhere that you're running Python.
A whole lot of other fun things you could do on top of it.
There's a new extension ecosystem.
So if it doesn't exist in DuckDB, but you'd like it to, you can actually build an extension
for DuckDB in a variety of languages.
And so we can all together make DuckDB into whatever we'd like.
So it's pretty neat.
Yeah.
Well, good work.
And I love to see the open source side and then maybe a strong company that's built around
it in a way that doesn't really undermine the open source value.
So MotherDuck, DuckDB, it looks like a really good relationship there.
So that's nice.
Yeah.
We even have two companies.
We got DuckDB Labs and MotherDuck.
Yeah, that's right.
Got the foundational side as well.
Yeah.
Awesome.
Well, Alex, thanks for being on the show.
And yeah, thanks for sharing all this stuff with us.
It's great.
Thanks for having me.
Cheers, folks.
Happy analyzing.
Yep.
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.
And it's brought to you by the Data Citizens Dialogues podcast from Colibra.
If you're ready for a deeper dive into the latest hot topics and data, listen to an episode
at talkpython.fm/citizens.
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.
You
you
Thank you.