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 freelance developer, I've learned that automation is key to increasing productivity and delivering high-quality work to clients. In this article, I'll share how I use Python to automate my freelance workflow, from project management to invoicing.

Project Management Automation

I use the github library in Python to automate my project management workflow. Here's an example of how I use it to create a new repository for a client project:

import github

# Create a GitHub object
gh = github.Github("your-github-token")

# Create a new repository
repo = gh.get_user().create_repo(
    name="client-project",
    description="Client project repository",
    private=True
)

# Print the repository URL
print(repo.html_url)
Enter fullscreen mode Exit fullscreen mode

This code creates a new private repository for the client project and prints the repository URL. I can then use this URL to clone the repository and start working on the project.

Time Tracking Automation

I use the toggl library in Python to automate my time tracking workflow. Here's an example of how I use it to start a new timer for a client project:

import toggl

# Create a Toggl object
toggl_api = toggl.Toggl("your-toggl-api-token")

# Start a new timer
timer = toggl_api.start_timer(
    description="Client project work",
    project_id=12345,
    tags=["client-project", "development"]
)

# Print the timer ID
print(timer["id"])
Enter fullscreen mode Exit fullscreen mode

This code starts a new timer for the client project and prints the timer ID. I can then use this ID to stop the timer when I'm done working on the project.

Invoicing Automation

I use the stripe library in Python to automate my invoicing workflow. Here's an example of how I use it to create a new invoice for a client:

import stripe

# Create a Stripe object
stripe.api_key = "your-stripe-api-key"

# Create a new invoice
invoice = stripe.Invoice.create(
    customer="client-customer-id",
    items=[
        {
            "price_data": {
                "currency": "usd",
                "product_data": {
                    "name": "Client project work"
                },
                "unit_amount": 1000
            },
            "quantity": 1
        }
    ]
)

# Print the invoice URL
print(invoice.hosted_invoice_url)
Enter fullscreen mode Exit fullscreen mode

This code creates a new invoice for the client and prints the invoice URL. I can then send this URL to the client to pay the invoice.

Monetization Angle

By automating my freelance workflow with Python, I've been able to increase my productivity and deliver high-quality work to clients. This has led to an increase in client satisfaction, which has resulted in more referrals and a higher earning potential. In fact, I've been able to increase my hourly rate by 25% since implementing these automations.

Putting it all Together

To put all of these automations together, I use a Python script that runs on a schedule using schedule library. Here's an example of how I use it to automate my workflow:


python
import schedule
import time

def automate_workflow():
    # Create a new repository
    repo = gh.get_user().create_repo(
        name="client-project",
        description="Client project repository",
        private=True
    )

    # Start a new timer
    timer = toggl_api.start_timer(
        description="Client project work",
        project_id=12345,
        tags=["client-project", "development"]
    )

    # Create a new invoice
    invoice = stripe.Invoice.create(
        customer="client-customer-id",
        items=[
            {
                "price_data": {
                    "currency": "us
Enter fullscreen mode Exit fullscreen mode

Top comments (0)