DEV Community

Caper B
Caper B

Posted on

How I Automate My Freelance Workflow with Python

How I Automate My Freelance Workflow with Python

As a freelancer, managing multiple projects and clients can be overwhelming. However, by leveraging the power of Python, I've been able to automate many tasks, freeing up more time to focus on high-leverage activities like coding and client relationships. In this article, I'll walk you through the steps I took to automate my freelance workflow with Python.

Step 1: Project Management with Trello and Python

I use Trello to manage my projects and tasks. To automate tasks like creating new boards, lists, and cards, I use the Trello API and the requests library in Python. Here's an example of how I create a new board:

import requests

# Trello API credentials
api_key = "YOUR_API_KEY"
api_token = "YOUR_API_TOKEN"

# Create a new board
board_name = "New Project"
response = requests.post(
    f"https://api.trello.com/1/boards/",
    params={
        "key": api_key,
        "token": api_token,
        "name": board_name
    }
)

# Get the new board's ID
board_id = response.json()["id"]
Enter fullscreen mode Exit fullscreen mode

Step 2: Time Tracking with Harvest and Python

I use Harvest to track my time and generate invoices. To automate time tracking, I use the Harvest API and the requests library in Python. Here's an example of how I log time for a project:

import requests

# Harvest API credentials
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"

# Log time for a project
project_id = "YOUR_PROJECT_ID"
task_id = "YOUR_TASK_ID"
hours = 2
notes = "Worked on feature X"
response = requests.post(
    f"https://api.harvestapp.com/api/v2/time_entries",
    auth=(api_key, api_secret),
    json={
        "project_id": project_id,
        "task_id": task_id,
        "hours": hours,
        "notes": notes
    }
)
Enter fullscreen mode Exit fullscreen mode

Step 3: Invoicing with Stripe and Python

I use Stripe to generate invoices and accept payments. To automate invoicing, I use the Stripe API and the stripe library in Python. Here's an example of how I create a new invoice:

import stripe

# Stripe API credentials
api_key = "YOUR_API_KEY"

# Create a new invoice
stripe.api_key = api_key
customer_id = "YOUR_CUSTOMER_ID"
invoice_items = [
    {"price": "YOUR_PRICE_ID", "quantity": 1}
]
invoice = stripe.Invoice.create(
    customer=customer_id,
    auto_advance=True,
    items=invoice_items
)
Enter fullscreen mode Exit fullscreen mode

Step 4: Client Onboarding with Gmail and Python

I use Gmail to communicate with clients. To automate client onboarding, I use the Gmail API and the google-api-python-client library in Python. Here's an example of how I send a welcome email to a new client:

import base64
from googleapiclient.discovery import build

# Gmail API credentials
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"

# Send a welcome email to a new client
client_email = "client@example.com"
subject = "Welcome to our project!"
body = "Hello, we're excited to start working with you!"
service = build("gmail", "v1", credentials=api_key)
message = service.users().messages().send(
    userId="me",
    body={
        "raw": base64.urlsafe_b64encode(
            f"Subject: {subject}\r\n\r\n{body}".encode("utf-8")
        ).decode("utf-8")
    }
)
Enter fullscreen mode Exit fullscreen mode

Monetization Angle

By automating my

Top comments (0)