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. To streamline my workflow and increase productivity, I've turned to Python for automation. In this article, I'll share how I use Python to automate tasks, from project setup to invoicing, and how it's helped me grow my business.

Setting up Projects with Python

When a new project comes in, I use a Python script to set up the basic directory structure and files. This includes creating a new Git repository, setting up a virtual environment, and initializing a requirements.txt file. Here's an example of how I do it:

import os
import subprocess

def create_project(project_name):
    # Create a new directory for the project
    os.mkdir(project_name)

    # Create a new Git repository
    subprocess.run(["git", "init"], cwd=project_name)

    # Create a virtual environment
    subprocess.run(["python", "-m", "venv", "env"], cwd=project_name)

    # Initialize a requirements.txt file
    with open(os.path.join(project_name, "requirements.txt"), "w") as f:
        f.write("")

    print(f"Project {project_name} created successfully!")

# Example usage
create_project("my_new_project")
Enter fullscreen mode Exit fullscreen mode

This script saves me around 10-15 minutes per project, which may not seem like a lot, but it adds up when you're working on multiple projects simultaneously.

Automating Task Management with Python

I use Trello to manage my tasks and projects. To automate the process of creating new cards and assigning tasks, I use the Trello API and the requests library in Python. Here's an example:

import requests

def create_trello_card(card_name, list_id, api_key, api_token):
    url = f"https://api.trello.com/1/cards"
    params = {
        "key": api_key,
        "token": api_token,
        "name": card_name,
        "idList": list_id
    }
    response = requests.post(url, params=params)
    if response.status_code == 200:
        print(f"Card {card_name} created successfully!")
    else:
        print(f"Failed to create card {card_name}")

# Example usage
create_trello_card("New Task", "1234567890", "my_api_key", "my_api_token")
Enter fullscreen mode Exit fullscreen mode

This script allows me to create new cards and assign tasks to my team members automatically, saving me around 30 minutes per day.

Invoicing and Payment Tracking with Python

I use Stripe to manage my payments and invoices. To automate the process of generating invoices and tracking payments, I use the Stripe API and the datetime library in Python. Here's an example:

import datetime
import stripe

def generate_invoice(client_name, amount, due_date):
    stripe.api_key = "my_stripe_api_key"
    invoice = stripe.Invoice.create(
        customer="my_customer_id",
        amount=amount,
        currency="usd",
        due_date=due_date
    )
    print(f"Invoice created for {client_name} for ${amount}")

# Example usage
generate_invoice("John Doe", 1000, int(datetime.datetime.now().timestamp()) + 30 * 24 * 60 * 60)
Enter fullscreen mode Exit fullscreen mode

This script generates invoices and sends them to my clients automatically, saving me around 1 hour per week.

Monetization Angle

By automating my workflow with Python, I've been able to take on more projects and clients, increasing my revenue by around 20%. I've also been able to offer more competitive pricing to my clients, as I'm able to complete tasks faster and more efficiently. Additionally, I've been able to create and sell automated tools and scripts to other

Top comments (0)