Linear Python SDK

0.2.0 · active · verified Tue Mar 17

There is NO official Python SDK for Linear. Linear's official SDK is TypeScript only (@linear/sdk). For Python, three competing community packages exist: linear-py, linear-api, and linear-python — none are official. The recommended approach for production Python use is raw GraphQL over HTTP. Current best community package is linear-api 0.2.0.

Warnings

Install

Imports

Quickstart

Raw GraphQL approach — recommended for production Python use with Linear API.

import json
import urllib.request

API_KEY = 'lin_api_YOUR_KEY'

def graphql_request(query, variables=None):
    data = json.dumps({'query': query, 'variables': variables or {}}).encode()
    req = urllib.request.Request(
        'https://api.linear.app/graphql',
        data=data,
        headers={
            'Authorization': API_KEY,
            'Content-Type': 'application/json'
        }
    )
    with urllib.request.urlopen(req) as resp:
        result = json.loads(resp.read())
    if 'errors' in result:
        raise Exception(result['errors'])
    return result['data']

# Get current user
me = graphql_request('{ viewer { id name email } }')
print(me)

# Get issues for a team
query = '''
query TeamIssues($teamId: String!) {
    team(id: $teamId) {
        issues { nodes { id identifier title state { name } } }
    }
}
'''
issues = graphql_request(query, {'teamId': 'YOUR_TEAM_ID'})

view raw JSON →