If you’re a freelancer or small agency owner, you know the drill: you finish a project, then you spend 30 minutes creating an invoice, emailing it, and chasing payment. Multiply that by 10 clients a month, and you’ve lost half a day. I’ve been there, and I decided to fix it with a script. Here’s how you can too.
First, let’s talk about the problem. Manual invoicing is error-prone: you might forget a tax rate, mix up a client’s email, or send the wrong attachment. Even if you use a tool like FreshBooks or QuickBooks, you still have to enter data every time. An automated script can pull data from a spreadsheet, generate a PDF, and email it—all with one command.
The core of the script is simple. You’ll have a CSV file with columns for client name, email, project, hours, and rate. The script reads that CSV, calculates the total (including tax), and uses a PDF library like ReportLab to create the invoice. Then it sends it via SMTP. I use a Gmail app password to authenticate—no need for a complex email setup.
Let’s walk through the key parts. First, install the dependencies: `pip install reportlab` and `pip install pandas` (for easy CSV handling). Next, write a function that takes a row of data and returns a PDF file. You can customize the header with your logo, and the layout is just a simple table. Here’s a snippet: `def create_invoice(row): …` (I’ll include the full code in the download).
The next step is sending the email. I use `smtplib` and `email.mime` to attach the PDF. You’ll need your Gmail address and an app password (enable 2FA). Then the script loops through all rows in the CSV and sends each one. It also marks the row as ‘sent’ in a separate column so you don’t double-send.
Now, the real-world application. My buddy Dan, a freelance designer, used this script to send invoices to his 15 recurring clients. He said it saved him about 3 hours a month, and he got paid faster because the invoices were always professional and on time. Another user, Priya, uses it for her online course business—she charges monthly, so she just updates the CSV and runs the script.
Of course, there are pitfalls. You need to test the email sending on your own address first. Also, make sure your CSV is formatted correctly—no weird commas. I recommend using a spreadsheet app to create the CSV, then save as CSV UTF-8 to avoid encoding issues.
One thing to note: this script doesn’t handle payment reminders. If you want that, I’ve built a separate script that checks your Stripe balance and sends a friendly reminder to unpaid invoices. That’s in the library too, but for this post, let’s stick to the basics.
Finally, let’s talk about scaling. Once you have the script running, you can schedule it with cron (on Mac/Linux) or Task Scheduler (on Windows). Set it to run every Friday at 9 AM, and your invoices will go out automatically. No more manual work.
If you’re tired of the invoice grind, grab the script from the library. It’s a one-time download, and you’ll have it forever. Plus, you get updates if I improve it. Trust me, your future self will thank you.
