How I Automate My Freelance Workflow with Python
As a freelance developer, I've learned that automation is key to increasing productivity and reducing the time spent on repetitive tasks. In this article, I'll share how I use Python to automate my freelance workflow, from project management to invoicing.
Project Management Automation
One of the most time-consuming tasks as a freelancer is managing multiple projects simultaneously. To automate this process, I use the github library in Python to interact with the GitHub API. Here's an example of how I use it to create a new project repository:
import github
# Create a GitHub API connection
g = github.Github("your-github-token")
# Create a new repository
repo = g.get_user().create_repo(
name="new-project",
description="New project repository",
private=True
)
print(f"Repository created: {repo.name}")
This script creates a new private repository on my GitHub account, which I can then use to manage my project's codebase.
Time Tracking Automation
Accurate time tracking is essential for freelancers, as it helps us bill clients correctly. I use the toggl library in Python to interact with the Toggl API, which allows me to track my time spent on projects. Here's an example of how I use it to start a new time entry:
import toggl
# Create a Toggl API connection
t = toggl.Toggl("your-toggl-token")
# Start a new time entry
time_entry = t.start(time_entry={
"description": "New time entry",
"project_id": 12345,
"tag_ids": [123, 456]
})
print(f"Time entry started: {time_entry['description']}")
This script starts a new time entry on my Toggl account, which I can then use to track my time spent on a project.
Invoicing Automation
Invoicing clients is another time-consuming task that can be automated using Python. I use the pdfkit library to generate PDF invoices based on my time entries. Here's an example of how I use it to generate an invoice:
import pdfkit
from jinja2 import Template
# Define the invoice template
template = Template("""
<html>
<body>
<h1>Invoice {{ invoice_number }}</h1>
<table>
<tr>
<th>Description</th>
<th>Hours</th>
<th>Rate</th>
<th>Total</th>
</tr>
{% for time_entry in time_entries %}
<tr>
<td>{{ time_entry.description }}</td>
<td>{{ time_entry.hours }}</td>
<td>{{ time_entry.rate }}</td>
<td>{{ time_entry.total }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>
""")
# Generate the invoice
time_entries = [
{"description": "Time entry 1", "hours": 2, "rate": 100, "total": 200},
{"description": "Time entry 2", "hours": 3, "rate": 100, "total": 300}
]
invoice_number = "INV001"
invoice_html = template.render(invoice_number=invoice_number, time_entries=time_entries)
invoice_pdf = pdfkit.from_string(invoice_html, False)
# Save the invoice to a file
with open(f"invoice_{invoice_number}.pdf", "wb") as f:
f.write(invoice_pdf)
This script generates a PDF invoice based on my time entries, which I can then send to my clients.
Monetization Angle
By automating my freelance workflow using Python, I've been able to increase my productivity and reduce the time spent
Top comments (0)