- Podcasts
- Talk Python To Me
- #460: Dropbase: Build Internal Tools with Python
#460: Dropbase: Build Internal Tools with Python
Talk Python To Me
- May 2, 2024
- 52 min
- Episode 460
About this episodeSee the full show notes for this episode on the website at talkpython.fm/460
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#460: Dropbase: Build Internal Tools with Python
But they're the kind of same kind of thing. And so, you know, I think that's probably why VB6 with its kind of visual drag and droppy experience became real popular because you could drag a table on there and drag a data source, bind it to that and make a button click when somebody touches this thing.
We don't know sort of the final eventually where this will be. But the current version of this is we thought, you know what, I think we need to give users an editor, like a built-in editor, so they can just quickly, they can have the best experience building the app and the access to UI and context and state really quickly.
I think it's fine without. But it's kind of one of those things, like you're in there, and you've got these data sources, and maybe you're not super familiar with them. Maybe you can pull them together somehow. One of the things that I find myself struggling with is, let's say I want to build a demo. Let's say I haven't been exposed to the SendGrid API or the HubSpot API. Then I have to go to their documentation to figure out what's the package name so I can install it. How do I authenticate in? How do I call a few endpoints to do what I need to do? And I think in that case where it's not about your knowledge of Python, it really is about your knowledge of this other thing that you're using. In those cases, it seems that it could be extremely helpful for someone to build apps very quickly if they somehow had access to either quick documentation or you just suggested what you might want to do. Yeah, that's kind of what I was thinking as well. 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 speaking of that sort of external resources, you've got this Python function. And what can I put in there? Can I use external packages? Can I call out on the network to talk to some API endpoints? Can I spin up threads? Like what can I do? How much Python can I do there? Pretty much all of the above. So I'll elaborate what I mean by that. So the standard way that you would connect to some of these services, these third party services, is you'll make like an HTTP request. Like get requests, post requests. So you can just like import requests, basically. PIP install requests and then just do it over the standard Python, basically Python package. Now, it is way more convenient when you use an SDK provided by one of these third parties. So if you want to use Stripe, if you're able to just import Stripe, it'll make your life a lot easier, very nicely, Pythonic, everything set up. So in DropBase, you can install anything that you can install via PyPI. We have a file called custom requirements. And if you just list them out, when you set up DropBase, we'll basically install all those for you. And then when you write a function, you can just basically import Stripe directly in the function without pip installing it again, and then you just use it. So that's really nice. But basically anything. I think you were doing a previous uv. You were talking. Yeah, yeah. I was talking to Charlie Marsh about uv earlier today. Yeah. We haven't looked into it yet. But anything you can pip install from PyPI, you can install in DropBase, which makes it really, really powerful. Yeah, nice. There's a database connections. I mean, you could use SQLAlchemy or you can import whatever else you want. But we make those a bit more native because we know that you're going to connect to databases. So we want to make it a bit more convenient. So. And your tables need sort of direct access to it as well, right? Not just the output of some access to the database, but you've got to figure out the columns and all that kind of stuff, right? That's correct. So we created a little library, like a utility slash helper that lets you perform database operations very quickly. So if you've added your database credentials to the .env file, then you can quickly perform, you know, like a select statement or, you know, make an update to that database via functions. But without, you know, the standard thing where you do, if you use SQLAlchemy, for example, where you like start a session, start a connection, you know, like all those steps, we kind of abstract that for you. But you can totally use SQLAlchemy in its full glory if you, you know, if that's what you're used to. Nice. Can I write Python files, like separate Python scripts and stuff, and then just import and call them from there? Or does it have to be done through the UI? Totally. Yeah. There's actually one of the biggest advantages of DropBase is that if you have like a Python script lying around and you want to sort of use it in DropBase, you can add it to that file system somewhere in the workspace directory. And you can just import it in via your function. So you just like from your file, you can import a specific function in that file, for example. And so the implication of this is that you can set up DropBase in a way that it just lives in your existing Python code base. So imagine you're already, you know, you've set up your company, you've got product market fit, you know, things are running, right? And you have a Python backend. And now you're starting to scale and you need to build tools. So your first option would be to do all custom, obviously. The second option is to use some sort of tools builder. But every single action you take is done over an HTTP request with authentication, with everything. So just like a standard internet communication. But if you wanted to just interact with an existing functions or internal endpoints, then you'd have to either set up an RPC server or you might want to use some other way to get in there. DropBase, you basically just set up DropBase in the same directory as your app. And you can then import selectively what functions you need. It's sort of like a window into your code base that it's like a plug into that code base where you can now expand and build a lot of internal tools that leverages everything that you've already built. Yeah. That's it, by the way. Yeah. When you've got, yeah, there's the requirements at custom, right? So you've got your Docker compose file. I mean, could you set it up just so as you build, maybe even better, just set up a volume so that it can directly find. I mean, I guess that's what you're kind of showing right here, right? Is that you can sort of map, mount a volume just directly into, say, your Git repo for your big project code. And then you can just start importing that and doing stuff with it, right? We still need to do some tweaks because of the relative paths. But the idea is that you can do that with a little bit of customization. But yeah, our workspace server, basically, you mount files or directories, and then we can look into those to execute. Yeah, manage those files with Git or something like that. A good example of this is, are you familiar with Django and Django Admin? Not super, as I do every day, but I'm aware, sure. Django, it's a great web framework. It's used by a lot of companies. It's like, if you want to build web apps, you have Django. It comes with a lot of stuff, right? And there's this thing called Django Admin that basically automatically generates admin panels for you based on your Django models. And so if you have a model for a book, right? And the book has authors. It basically exposes that to the Django admin. And then now you can edit a book without really doing anything. It all kind of comes for free. It's pretty neat. I think that's half the appeal of Django right there. It is. Yeah, I think a lot of people use it for that. Yeah, they're like, I don't want to write that stuff. I'm using Django. Yeah, for real. And it's great. Now, at some point, when your company hits a certain milestone or a certain number of customers, you will need to customize those admin panels. You might need to create admin panels for things that maybe you don't have models for yet. Or for things that combine data from your database with data from like Stripe or some other source. And so what we see when we talk to these people is that they kind of struggle to like either do I like keep using this or do I like completely rebuild everything? For those users, when we talk to them about DropBase, they get very excited because with DropBase, you can install Django and it can sit in your file system. And so essentially all the models that you've already built in Django, you can basically call them via DropBase, with DropBase function because it's all Python, right? And so it gives you this like, okay, Django admins are great up to a certain point. And then after that, what happens, right? Like you might not want to rebuild everything just so you can have internal tooling. And so I think that's quite of a nice spot for us to say, look, DropBase can live in your code base, uses everything you already have, but it gives you some extra things if you want to build internal tools very quickly. So that's something we're obviously very, very excited about. That's really cool. I like that aspect of it. So when we talk about this code, I guess there's two scenarios, the cloud version or the self-hosted version. But where and how does this Python run? Is it, it must be full CPython? Is it running in isolated Docker containers? Or in your cloud, what happens? Is it functions like AWS functions, Lambda? It just runs either on your local machine, if you've set it up as a developer. It's all running there. Obviously, if you turn off your machine, you can use your apps. And then if you set it up in a production instance, let's say you deploy this on an EC2, your Python functions are running on that EC2. But it's running via Docker container inside. So it gets a little isolation, a little bit of protection, that kind of stuff. And we're assuming that, I mean, you're building these apps to run on your own infrastructure. It's that you would, that you know what you're doing. So this is as opposed to us having a full cloud version where all customers run untrusted code in the same sort of backend system, which would be obviously very dangerous because I'm sure there's ways a customer can somehow, you know, go through the backend and access other customers' untrusted code. And that would be a nightmare. And so if, you know, we have isolation, first layer is, well, it's in your infrastructure you're going to do. It's just your company's code. But then further, you know, we run Python in containers in that instance. That sounds more like a durability thing than anything. I mean, it is also for isolation protection. But first and foremost, just don't let bad Python code take down the whole thing, you know? The way we recommend people using DropBase or setting up their dev sort of process with DropBase is that they would clone, basically fork the for DropBase. And then they will develop locally. They will test changes. And once they're happy with the new code, you know, they'll push it back. And then they will have CI/CD into the production instance. And then they can version control everything. So that also gives you that extra layer of, okay, let's make sure that whatever we're pushing is tested. You can always add test databases that you develop locally with before you push the production, where it's going to have to act on your production data. Yeah, that's pretty interesting. I like the version control aspect of it. That gives it a much nicer touch to connection to real software rather than just it's a text input area in an app that who knows what happens. As developers, it sometimes feels a bit scary, right? Like you're building something and it's in this other framework and this other cloud. And it just feels like you can't kind of get, like if the thing goes away, like you can't even see your previous code. That was another key concept that we wanted to have is in this tool that it feels friendly for developers, that it matches your mental models and your sort of like your development process, let's call it. Like how you're used to making apps or developing code, that we keep that feeling when you're building apps for a trial phase. I want to maybe have a PR to understand if we accept this change to it, right? That's right. Yeah. Yeah. You don't normally hear that kind of stuff around these kind of tools, you know? And if you do, I think it tends to be like, yeah, okay, it's like a huge enterprise contract, you know, pay us $50,000 a year and then you get version control, which to me, it sounds scary. I mean, it just, it will make me a little bit less comfortable. Now, obviously, if I'm a big company and I just really need the tool, sure, maybe I'll just pay for it and I get version control. But, you know, getting version control, it just feels so like, like table stakes for developers, especially today. But yeah, it just wouldn't make sense otherwise for us. I mean, it's the way we're approaching this product. Yeah. Well, the other aspect is, you know, what are you version controlling? You know, do you end up with, you know, something like effectively a Jupyter Notebook, like big blob of something. And then there's an older blob of something and then you diff it. You're like, what is this? But since you end up with just these, you know, your workspace files that just live there, right? It's a real optimized, like, show me the changes. Show me what's happened here. Yeah. It all lives there, including the component properties. Like we don't store this in like a separate database or anything like that. So like, you know, like for some of their tools, they will store all the components in their database. And so what they do is, you know, when you load up their tools, like their tools builder, it'll fetch all the components from the provider's database, combine it with maybe your custom code, and then it'll do it. And so even that feels like, okay, but where's like config for my components? Yeah. Where'd this button come from? Why is it gone? That's tough. Yeah. That's tough. And then like, imagine if you wanted to like share their apps or, you know, it's just like version control makes a bit less sense. I mean, you're just version controlling, just like the individual functions, maybe like the custom part of the code that you write, which is still useful, but it still feels like you don't have the full picture of what's happening. Yeah. You don't have a full record. It could easily get out of sync. Yeah. Quite interesting. I guess one thing we touched on a little bit before I press go here in the show, you said that at one point you were considering using Jupyter in this whole mechanism. Yeah. What's the story around that? We love Jupyter. We love notebooks. And we love the experience of them. The sense that you can write some code and you can quickly test and execute the code without, basically without, without needing to write anything else. So for prototyping, for getting quick feedback, it's great. And we wanted to give our developers something like that, because when you build these apps, you're kind of iterating, right? You're like, you're testing it. A lot of times you don't even know the documentation for Drive or HubSpot or, and so like there's a lot of experimentation. And so we wanted a quick way to do that. So we considered maybe having something like a Jupyter kernel within DropBase that allowed people to do it. There were some issues with it in the sense that the kernel actually stores results from like previous blocks. And sometimes that gets in the way of you triggering an action in a later block. And so we were like, okay, maybe that's a little bit more than we need. Now, we still kind of eventually want something like that. We hacked it in a way. Like, so the way that we do it is you can write a Python function. You basically get one block. You can write a Python function and you can click on a play button to basically run that function. But it's not like a kernel. So what we do is behind the scenes, we have like a main function. And when you trigger that function, we take the state from the client. So whatever you've selected or input it, we take the underlying file for your Python function. And then we call it from me. And so we kind of simulate that experience of like instantly testing code that you just wrote. But there is no Jupyter kernel behind the scenes. And then you can only do one block at a time. And so we said, okay, for now, as we're getting started with it, it's good enough. You can write your functions. You can run and test them immediately, which is really nice. You can do this with VS Code, by the way. Like you would have to open up the terminal and then basically run your function. And so we still wanted this feature where you can click and just see your outputs and basically debug and troubleshoot. But it would be really nice if you could get out multiple blocks and you can just build functions that way. So maybe for the future. Interesting. Did you say that you were a core developer for Jupyter? No, no. I just spoke to them. It sounds fun. I interviewed a whole bunch of them recently. And what I thought was interesting is Jupyter is such an empowering thing for Python developers. But many of the core developers are so focused on writing JavaScript and TypeScript to sort of make these interactions possible so that the rest of us don't have to write JavaScript and that kind of stuff. So I think we're getting about to the end of our time here. I'm sure that actually this is somewhat similar. It's really a dynamic interactive web app. And in that case, it probably has to have some interesting front end JavaScript stuff going on. What's the JavaScript story? Yeah. What framework are you using and stuff like that? We just react to build our components. Obviously, we abstract that away so that you as a Python developer, you're just writing Python. Well, you're writing SQL as well. But let's call that Python. And then we deal with the components for you. And so it's not the kind of framework where you're writing Python and we're generating HTMX or something like that. So obviously, we understand React. And we know we can build some beautiful components, customize them with it. We weren't about to create a completely new framework where we somehow just generate HTML from Python. I think there's a few people working on that, actually. We already know React, so let's just build those components or customize those components and then just let people declare them and then sort of access and modify them via the context objects in your Python functions. So our stack, we use FastAPI for our backend, which is great. It's excellent, yeah. I'm not sure if you've had the creator here. Yeah, I've had Sebastian on, I think, at least three times, Sebastian Ramirez. Yeah, he's great. Yeah, he is really great, yeah. FastAPI is a fantastic app. And so, yeah, we use them. We use React or our client side. And we are a lot of our infras on AWS. Yeah, sounds really interesting. Sounds like a fun app to work on. Yeah, you should play around with it. I can help you build some apps to manage your podcast library. All right, well, Jimmy, I think we are pretty much out of time. Final thought for people listening. Maybe they're excited to try this out. What are you telling them? Yeah, just go to droppace.io and sign up for a free account. It's free for developers. You can set it up locally. If you have any issues setting it up, just reach out. I'll personally help you get it up and running. Yeah, you can look at the documentation for everything else. Yeah. Let's find it. Try it. Give us some feedback. We'd love to hear from you. Awesome. Congrats on building a cool project for people. And yeah, good luck with it. Thanks, Michael. 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. Mailtrap, an email delivery platform that developers love. Try for free at mailtrap.io. 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. We'll see you next time.
