CanLii API

Get Metadata for Canadian Law

CanLii is an indispensible research tool for lawyers, law students, and scholars. Researchers who wish to interact with CanLii programmatically can access some metadata through an API. This library automates and simplifies many API calls and returns dataframes. Its objective is to help beginners access and use powerful computational tools.

Program functionality

This module automates calls to CanLii databases to obtain metadata. Out of the box, you can use it to obtain nine different sets of results:

  1. Names of all CanLii tribunal databases (database ID, jurisdiction, tribunal name)
  2. Identifying information for decisions in a CanLii database (case ID, title, citation)
  3. Metadata for a specific case (information depends on the database)
  4. Identities of cases cited by a specified case
  5. Identities of statutes cited by a specified case
  6. Identities of cases that cite a specified case
  7. An edge list of citations (for network analysis)
  8. An edge list of keywords (for network analysis)
  9. A topic to topic edgelist of keyword (for network analysis)

All results are returned as Pandas dataframes or series.

Demonstration

To get your own API key, request one directly from CanLii.

Initialize the program

from obiter.canlii_api import *
APIkey = 'YOUR SECRET API KEY'
language = 'en' # or 'fr'
api_caller = canlii_api(APIkey, language)

1. List CanLii caselaw databases


source

canlii_api.list_tribunals

 canlii_api.list_tribunals ()

Returns list of CanLii caselaw databases

api_caller.list_tribunals()
databaseId jurisdiction name
0 qccdoooq qc Conseil de discipline de l'Ordre des opticiens...
1 skqb sk Court of King's Bench for Saskatchewan
2 qcoaciq qc Comité de discipline de l'organisme d'autorégl...
3 abmgb ab Alberta Municipal Government Board
4 onsc on Superior Court of Justice
... ... ... ...
357 ytrto yk Yukon Residential Tenancies Office
358 nbsec nb Financial and Consumer Services Tribunal
359 onbcc on Building Code Commission
360 exchc-cech ca Exchequer Court of Canada
361 nttc nt Territorial Court of the Northwest Territories

362 rows × 3 columns

#isolate a tribunal
isolate_df = api_caller.list_tribunals()
filt = isolate_df['name'].str.contains('Federal')
isolate_df[filt]
databaseId jurisdiction name
128 fca ca Federal Court of Appeal
246 fct ca Federal Court
247 pslreb ca Federal Public Sector Labour Relations and Emp...
264 caci ca Federal Commission of Inquiry

2. List decisions in a caselaw database


source

canlii_api.list_decisions

 canlii_api.list_decisions (databaseId, descending=True, resultCount=10,
                            decision_date_after='',
                            decision_date_before='')
databaseId = 'onbcc' #ID of database to be searched, (Building Code Commission)
resultCount = 10 #number of results
decision_date_after = '2020-01-01' # "date" is a YYYY-MM-DD
decision_date_before = '2020-12-31'

api_caller.list_decisions(databaseId=databaseId, descending=False, resultCount=resultCount, decision_date_after=decision_date_after, decision_date_before=decision_date_before)
caseId title citation
0 2020onbcc19 Leung v. Johnston 2020 ONBCC 19 (CanLII)
1 2020onbcc20 Earle v. Richardson 2020 ONBCC 20 (CanLII)
2 2020onbcc15 Oster v. Bidin 2020 ONBCC 15 (CanLII)
3 2020onbcc14 Ropp v. Capener-Hunt 2020 ONBCC 14 (CanLII)
4 2020onbcc11 Vance v. Cox 2020 ONBCC 11 (CanLII)
5 2020onbcc8 MacPhail v. VanderWindt 2020 ONBCC 8 (CanLII)
6 2020onbcc6 Randle v. Johnston 2020 ONBCC 6 (CanLII)
7 2020onbcc3 Hand v. Janotta 2020 ONBCC 3 (CanLII)
8 2020onbcc2 Hooshley v. Goodale 2020 ONBCC 2 (CanLII)
9 2020onbcc1 Allen v. Fedoriw 2020 ONBCC 1 (CanLII)

3. Get case metadata


source

canlii_api.case_metadata

 canlii_api.case_metadata (databaseId, caseId)
databaseId = 'onbcc' #ID of database to be searched, (Building Code Commission)
caseId = '2021onbcc13' #Id of target case

api_caller.case_metadata(databaseId=databaseId, caseId=caseId)
databaseId                                                    onbcc
caseId                                                  2021onbcc13
url                                       https://canlii.ca/t/jkw96
title                                 Johnston and Roach v. Findlay
citation                                     2021 ONBCC 13 (CanLII)
language                                                         en
docketNumber                                  B 2021-06; 21-13-1187
decisionDate                                             2021-07-15
keywords          sound attenuation — second dwelling unit — chi...
topics                                                             
concatenatedId                                          2021onbcc13
dtype: object

4. Internal citations (i.e. cases a target case cites)


source

canlii_api.internal_cites

 canlii_api.internal_cites (databaseId, caseId)

Get a list of all the cases your target case cites.

databaseId = 'skqb' #ID of database to be searched, (Court of King's Bench for Saskatchewan)
caseId = '2022skkb215' #Id of target case

api_caller.internal_cites(databaseId=databaseId, caseId=caseId)
caseId title citation
0 1974canlii14 Kienapple v. R. 1974 CanLII 14 (SCC), [1975] 1 SCR 729
1 2022canlii26225 Michael Louis Hamer v. Her Majesty the Queen 2022 CanLII 26225 (SCC)
2 2022onca553 R. v. A.R. 2022 ONCA 553 (CanLII)
3 2007onca421 R. v. Allen 2007 ONCA 421 (CanLII)
4 2017scc64 R. v. Boutilier 2017 SCC 64 (CanLII), [2017] 2 SCR 936
5 1997canlii347 R. v. Currie 1997 CanLII 347 (SCC), [1997] 2 SCR 260
6 2020scc9 R. v. Friesen 2020 SCC 9 (CanLII)
7 1999canlii679 R. v. Gladue 1999 CanLII 679 (SCC), [1999] 1 SCR 688
8 2021bcca297 R. v. Hamer 2021 BCCA 297 (CanLII)
9 2011onca840 R. v. Hogg 2011 ONCA 840 (CanLII)
10 2003scc46 R. v. Johnson 2003 SCC 46 (CanLII), [2003] 2 SCR 357
11 1987canlii25 R. v. Lyons 1987 CanLII 25 (SCC), [1987] 2 SCR 309
12 2007onca872 R. v. R.M. 2007 ONCA 872 (CanLII)
13 2018onsc2226 R. v. Robertson 2018 ONSC 2226 (CanLII)
14 2022onca47 R. v. Straub 2022 ONCA 47 (CanLII)
15 2022skca13 R v Ballantyne 2022 SKCA 13 (CanLII)
16 2015skca134 R v Bird 2015 SKCA 134 (CanLII)
17 2011skca67 R v Daniels 2011 SKCA 67 (CanLII)
18 2021skca122 R v Goodpipe 2021 SKCA 122 (CanLII)
19 2019skqb221 R v Goodpipe 2019 SKQB 221 (CanLII)
20 2015skca82 R v Knife 2015 SKCA 82 (CanLII)
21 2022skca77 R v Laprise 2022 SKCA 77 (CanLII)
22 2022skpc7 R v Levac 2022 SKPC 7 (CanLII)
23 2020skqb171 R v Levac 2020 SKQB 171 (CanLII)
24 2015skca39 R v Moise 2015 SKCA 39 (CanLII)
25 2022abca48 R v Natomagan 2022 ABCA 48 (CanLII)
26 2021skca50 R v Pelly 2021 SKCA 50 (CanLII)
27 2015skca117 R v Toutsaint 2015 SKCA 117 (CanLII)
28 2016skca131 R v Wilton 2016 SKCA 131 (CanLII)

5. External citations (i.e. cases that cite a target case)


source

canlii_api.external_cites

 canlii_api.external_cites (databaseId, caseId)

Get a list of all the cases that cite your target case.

databaseId = 'csc-scc' #ID of database to be searched, (Supreme Court of Canada)
caseId = '2022scc30' #Id of target case

api_caller.external_cites(databaseId=databaseId, caseId=caseId)
caseId title citation
0 2022cb7 SOCAN Tariff 22.G – Game Sites (2007-2019) 2022 CB 7 (CanLII)
1 2022qccs3010 Fédération des travailleurs et travailleuses d... 2022 QCCS 3010 (CanLII)
2 2022qcca1139 Ville de Brossard c. Ville de Longueuil 2022 QCCA 1139 (CanLII)
3 2022abqb611 NAIT Students’ Association v NAIT 2022 ABKB 611 (CanLII)
4 2022fc1147 Makkar v. Canada (Citizenship and Immigration) 2022 FC 1147 (CanLII)
5 2022qccs3728 Hydro-Québec c. Régie de l'Énergie 2022 QCCS 3728 (CanLII)
6 2022fc1365 Afzal v. Canada (Citizenship and Immigration) 2022 FC 1365 (CanLII)
7 2022abca264 Sedgwick v Edmonton Real Estate Board Co-Opera... 2022 ABCA 264 (CanLII)
8 2022abca259 Fazel v Singer (Wilson Laycraft) 2022 ABCA 259 (CanLII)
9 2022qccs3465 Ville de Gatineau c. Association des pompiers ... 2022 QCCS 3465 (CanLII)
10 2022fc1209 AbbVie Corporation v. Canada (Health) 2022 FC 1209 (CanLII)

6. Legislation citations within a case


source

canlii_api.legislation_cites

 canlii_api.legislation_cites (databaseId, caseId)

Get a list of all the legislation your target case cites.

databaseId = 'csc-scc' #ID of database to be searched, (Supreme Court of Canada)
caseId = '2022scc30' #Id of target case

api_caller.legislation_cites(databaseId=databaseId, caseId=caseId)
databaseId legislationId title citation type
0 cas rsc-1985-c-c-42 Copyright Act RSC 1985, c C-42 STATUTE
1 caa sc-2012-c-20 Copyright Modernization Act SC 2012, c 20 ANNUAL_STATUTE

7. Citations for network analyses (edge list)


source

canlii_api.citations_edge_list

 canlii_api.citations_edge_list (df, databaseId)
databaseId = 'csc-scc' #ID of database to be searched, (Building Code Commission)
resultCount = 10 #number of results
decision_date_after = '2021-01-01' # "date" is a YYYY-MM-DD
decision_date_before = '2021-12-31'

df = api_caller.list_decisions(databaseId=databaseId, descending=False, resultCount=resultCount, decision_date_after=decision_date_after, decision_date_before=decision_date_before)
api_caller.citations_edge_list(df, databaseId)
original_caseID original_case_citation original_case_title cited_case_caseId cited_case_title cited_case_citation
0 2021scc53 2021 SCC 53 (CanLII) Montréal (City) v. Deloitte Restructuring Inc. 2020scc10 9354-9186 Québec inc. v. Callidus Capital Corp. 2020 SCC 10 (CanLII)
1 2021scc53 2021 SCC 53 (CanLII) Montréal (City) v. Deloitte Restructuring Inc. 2009abqb183 Agriculture Financial Services Corporation v. ... 2009 ABQB 183 (CanLII)
2 2021scc53 2021 SCC 53 (CanLII) Montréal (City) v. Deloitte Restructuring Inc. 2003canlii64234 Air Canada (Re) 2003 CanLII 64234 (ON SC)
3 2021scc53 2021 SCC 53 (CanLII) Montréal (City) v. Deloitte Restructuring Inc. 2020qcca438 Arrangement relatif à Consultants SM inc. 2020 QCCA 438 (CanLII)
4 2021scc53 2021 SCC 53 (CanLII) Montréal (City) v. Deloitte Restructuring Inc. 2019qccs2316 Arrangement relatif à Consultants SM inc. 2019 QCCS 2316 (CanLII)
... ... ... ... ... ... ...
342 2021scc44 2021 SCC 44 (CanLII) H.M.B. Holdings Ltd. v. Antigua and Barbuda 2021scc27 Reference re Code of Civil Procedure (Que.), a... 2021 SCC 27 (CanLII)
343 2021scc44 2021 SCC 44 (CanLII) H.M.B. Holdings Ltd. v. Antigua and Barbuda 2014bcca482 Solehdin v. Stern 2014 BCCA 482 (CanLII)
344 2021scc44 2021 SCC 44 (CanLII) H.M.B. Holdings Ltd. v. Antigua and Barbuda 1994canlii10958 T.D.I. Hospitality Management Consultants Inc.... 1994 CanLII 10958 (MB CA)
345 2021scc44 2021 SCC 44 (CanLII) H.M.B. Holdings Ltd. v. Antigua and Barbuda 2017onca549 Tracy v. Iran (Information and Security) 2017 ONCA 549 (CanLII)
346 2021scc44 2021 SCC 44 (CanLII) H.M.B. Holdings Ltd. v. Antigua and Barbuda 2016onsc3759 Tracy v The Iranian Ministry of Information an... 2016 ONSC 3759 (CanLII)

347 rows × 6 columns

8. Keywords for network analyses (edge list)


source

canlii_api.keywords_edge_list

 canlii_api.keywords_edge_list (df, databaseId)
databaseId = 'csc-scc' #ID of database to be searched, (Supreme Court of Canada)
resultCount = 200 #max number of results
decision_date_after = '2021-01-01' # "date" is a YYYY-MM-DD
decision_date_before = '2021-12-31'

df = api_caller.list_decisions(databaseId=databaseId, descending=False, resultCount=resultCount, decision_date_after=decision_date_after, decision_date_before=decision_date_before)
df
caseId title citation
0 2021scc53 Montréal (City) v. Deloitte Restructuring Inc. 2021 SCC 53 (CanLII)
1 2021scc52 R. v. Lai 2021 SCC 52 (CanLII)
2 2021scc51 Canada v. Loblaw Financial Holdings Inc. 2021 SCC 51 (CanLII)
3 2021scc50 Kreke v. Alansari 2021 SCC 50 (CanLII)
4 2021scc49 Canada v. Alta Energy Luxembourg S.A.R.L. 2021 SCC 49 (CanLII)
5 2021scc48 R. v. Albashir 2021 SCC 48 (CanLII)
6 2021scc47 Trial Lawyers Association of British Columbia ... 2021 SCC 47 (CanLII)
7 2021scc46 R. v. Parranto 2021 SCC 46 (CanLII)
8 2021scc45 R. v. Cowan 2021 SCC 45 (CanLII)
9 2021scc44 H.M.B. Holdings Ltd. v. Antigua and Barbuda 2021 SCC 44 (CanLII)
10 2021scc43 Ward v. Quebec (Commission des droits de la pe... 2021 SCC 43 (CanLII)
11 2021scc42 Northern Regional Health Authority v. Horrocks 2021 SCC 42 (CanLII)
12 2021scc41 Nelson (City) v. Marchi 2021 SCC 41 (CanLII)
13 2021scc40 R. v. Strathdee 2021 SCC 40 (CanLII)
14 2021scc39 6362222 Canada inc. v. Prelco inc. 2021 SCC 39 (CanLII)
15 2021scc38 R. v. Reilly 2021 SCC 38 (CanLII)
16 2021scc37 R. v. Khill 2021 SCC 37 (CanLII)
17 2021scc36 Richardson v. Richardson 2021 SCC 36 (CanLII)
18 2021scc35 R. v. Dingwall 2021 SCC 35 (CanLII)
19 2021scc34 Toronto (City) v. Ontario (Attorney General) 2021 SCC 34 (CanLII)
20 2021scc33 Canadian Broadcasting Corp. v. Manitoba 2021 SCC 33 (CanLII)
21 2021scc32 York University v. Canadian Copyright Licensin... 2021 SCC 32 (CanLII)
22 2021scc31 Grant Thornton LLP v. New Brunswick 2021 SCC 31 (CanLII)
23 2021scc30 Canada v. Canada North Group Inc. 2021 SCC 30 (CanLII)
24 2021scc29 Corner Brook (City) v. Bailey 2021 SCC 29 (CanLII)
25 2021scc28 Southwind v. Canada 2021 SCC 28 (CanLII)
26 2021scc27 Reference re Code of Civil Procedure (Que.), a... 2021 SCC 27 (CanLII)
27 2021scc26 R. v. Chouhan 2021 SCC 26 (CanLII)
28 2021scc25 Sherman Estate v. Donovan 2021 SCC 25 (CanLII)
29 2021scc24 Colucci v. Colucci 2021 SCC 24 (CanLII)
30 2021scc23 MediaQMI inc. v. Kamel 2021 SCC 23 (CanLII)
31 2021scc22 Ethiopian Orthodox Tewahedo Church of Canada S... 2021 SCC 22 (CanLII)
32 2021scc21 R. v. Morrow 2021 SCC 21 (CanLII)
33 2021scc20 R. v. G.F. 2021 SCC 20 (CanLII)
34 2021scc19 R. v. C.P. 2021 SCC 19 (CanLII)
35 2021scc18 Ontario (Attorney General) v. Clark 2021 SCC 18 (CanLII)
36 2021scc17 R. v. Desautel 2021 SCC 17 (CanLII)
37 2021scc16 R. v. Smith 2021 SCC 16 (CanLII)
38 2021scc15 R. v. Ramos 2021 SCC 15 (CanLII)
39 2021scc14 R. v. Gul 2021 SCC 14 (CanLII)
40 2021scc13 R. v. Sheikh 2021 SCC 13 (CanLII)
41 2021scc12 R. v. Ghotra 2021 SCC 12 (CanLII)
42 2021scc11 References re Greenhouse Gas Pollution Pricing... 2021 SCC 11 (CanLII)
43 2021scc10 R. v. R.V. 2021 SCC 10 (CanLII)
44 2021scc9 R. v. Esseghaier 2021 SCC 9 (CanLII)
45 2021scc8 R. v. W.O. 2021 SCC 8 (CanLII)
46 2021scc7 Wastech Services Ltd. v. Greater Vancouver Sew... 2021 SCC 7 (CanLII)
47 2021scc6 R. v. T.J.M. 2021 SCC 6 (CanLII)
48 2021scc5 R. v. Waterman 2021 SCC 5 (CanLII)
49 2021scc4 R. v. Murtaza 2021 SCC 4 (CanLII)
50 2021scc3 R. v. Deslauriers 2021 SCC 3 (CanLII)
51 2021scc2 R. v. Yusuf 2021 SCC 2 (CanLII)
52 2021scc1 Armstrong v. Ward 2021 SCC 1 (CanLII)
api_caller.keywords_edge_list(df, databaseId=databaseId)
databaseId caseId title citation decisionDate keyword
0 csc-scc 2021scc53 Montréal (City) v. Deloitte Restructuring Inc. 2021 SCC 53 (CanLII) 2021-12-10 pre-post compensation
1 csc-scc 2021scc53 Montréal (City) v. Deloitte Restructuring Inc. 2021 SCC 53 (CanLII) 2021-12-10 pre-post set-off
2 csc-scc 2021scc53 Montréal (City) v. Deloitte Restructuring Inc. 2021 SCC 53 (CanLII) 2021-12-10 creditor
3 csc-scc 2021scc53 Montréal (City) v. Deloitte Restructuring Inc. 2021 SCC 53 (CanLII) 2021-12-10 debtor
4 csc-scc 2021scc53 Montréal (City) v. Deloitte Restructuring Inc. 2021 SCC 53 (CanLII) 2021-12-10 supervising
... ... ... ... ... ... ...
260 csc-scc 2021scc1 Armstrong v. Ward 2021 SCC 1 (CanLII) 2021-01-18 ureter
261 csc-scc 2021scc1 Armstrong v. Ward 2021 SCC 1 (CanLII) 2021-01-18 intervener
262 csc-scc 2021scc1 Armstrong v. Ward 2021 SCC 1 (CanLII) 2021-01-18 kidney
263 csc-scc 2021scc1 Armstrong v. Ward 2021 SCC 1 (CanLII) 2021-01-18 colectomy
264 csc-scc 2021scc1 Armstrong v. Ward 2021 SCC 1 (CanLII) 2021-01-18 laparoscopic

265 rows × 6 columns

9. Topic to Topic keyword edge list


source

canlii_api.keywords_edge_list_topic2topic

 canlii_api.keywords_edge_list_topic2topic (df, databaseId)
databaseId = 'csc-scc' #ID of database to be searched, (Supreme Court of Canada)
resultCount = 200 #mac number of results
decision_date_after = '2021-01-01' # "date" is a YYYY-MM-DD
decision_date_before = '2021-12-31'

df = api_caller.list_decisions(databaseId=databaseId, descending=False, resultCount=resultCount, decision_date_after=decision_date_after, decision_date_before=decision_date_before)
api_caller.keywords_edge_list_topic2topic(df, databaseId=databaseId)
databaseId caseId title citation decisionDate keyword_1 keyword_2
0 csc-scc 2021scc53 Montréal (City) v. Deloitte Restructuring Inc. 2021 SCC 53 (CanLII) 2021-12-10 pre-post compensation pre-post set-off
1 csc-scc 2021scc53 Montréal (City) v. Deloitte Restructuring Inc. 2021 SCC 53 (CanLII) 2021-12-10 pre-post compensation creditor
2 csc-scc 2021scc53 Montréal (City) v. Deloitte Restructuring Inc. 2021 SCC 53 (CanLII) 2021-12-10 pre-post compensation debtor
3 csc-scc 2021scc53 Montréal (City) v. Deloitte Restructuring Inc. 2021 SCC 53 (CanLII) 2021-12-10 pre-post compensation supervising
4 csc-scc 2021scc53 Montréal (City) v. Deloitte Restructuring Inc. 2021 SCC 53 (CanLII) 2021-12-10 creditor pre-post set-off
... ... ... ... ... ... ... ...
472 csc-scc 2021scc1 Armstrong v. Ward 2021 SCC 1 (CanLII) 2021-01-18 kidney intervener
473 csc-scc 2021scc1 Armstrong v. Ward 2021 SCC 1 (CanLII) 2021-01-18 kidney colectomy
474 csc-scc 2021scc1 Armstrong v. Ward 2021 SCC 1 (CanLII) 2021-01-18 kidney laparoscopic
475 csc-scc 2021scc1 Armstrong v. Ward 2021 SCC 1 (CanLII) 2021-01-18 laparoscopic intervener
476 csc-scc 2021scc1 Armstrong v. Ward 2021 SCC 1 (CanLII) 2021-01-18 laparoscopic colectomy

477 rows × 7 columns

Saving and manipulating data

All program outputs are Pandas dataframes. To learn more about Pandas, check out the library’s introductory guide.

Basic functionality:

# save a datafram as a CSV file (to run in Excel, etc.)
df.to_csv('filename.csv')

# filter results
filt = df['title'].str.contains('R. v.')
df[filt]
caseId title citation
1 2021scc52 R. v. Lai 2021 SCC 52 (CanLII)
5 2021scc48 R. v. Albashir 2021 SCC 48 (CanLII)
7 2021scc46 R. v. Parranto 2021 SCC 46 (CanLII)
8 2021scc45 R. v. Cowan 2021 SCC 45 (CanLII)
13 2021scc40 R. v. Strathdee 2021 SCC 40 (CanLII)
15 2021scc38 R. v. Reilly 2021 SCC 38 (CanLII)
16 2021scc37 R. v. Khill 2021 SCC 37 (CanLII)
18 2021scc35 R. v. Dingwall 2021 SCC 35 (CanLII)
27 2021scc26 R. v. Chouhan 2021 SCC 26 (CanLII)
32 2021scc21 R. v. Morrow 2021 SCC 21 (CanLII)
33 2021scc20 R. v. G.F. 2021 SCC 20 (CanLII)
34 2021scc19 R. v. C.P. 2021 SCC 19 (CanLII)
36 2021scc17 R. v. Desautel 2021 SCC 17 (CanLII)
37 2021scc16 R. v. Smith 2021 SCC 16 (CanLII)
38 2021scc15 R. v. Ramos 2021 SCC 15 (CanLII)
39 2021scc14 R. v. Gul 2021 SCC 14 (CanLII)
40 2021scc13 R. v. Sheikh 2021 SCC 13 (CanLII)
41 2021scc12 R. v. Ghotra 2021 SCC 12 (CanLII)
43 2021scc10 R. v. R.V. 2021 SCC 10 (CanLII)
44 2021scc9 R. v. Esseghaier 2021 SCC 9 (CanLII)
45 2021scc8 R. v. W.O. 2021 SCC 8 (CanLII)
47 2021scc6 R. v. T.J.M. 2021 SCC 6 (CanLII)
48 2021scc5 R. v. Waterman 2021 SCC 5 (CanLII)
49 2021scc4 R. v. Murtaza 2021 SCC 4 (CanLII)
50 2021scc3 R. v. Deslauriers 2021 SCC 3 (CanLII)
51 2021scc2 R. v. Yusuf 2021 SCC 2 (CanLII)