Package: canliicalls
Call CanLiiCanLiiis an indispensable research tool for lawyers,
law students, judges, adjudicators, and researchers. Largely funded by
Canadian lawyers, it is the international gold standard when it comes to
the free and open access to law.With an intuitive and beautiful interface, researchers use CanLii to
look up an individual case or statute, read it, see what cites it, and
see what it cites.“Computer calls a database,” AI artist
(2022)Some legal researchers and social scientists require bulk access to
legal data for their projects. Fortunately, CanLii provides anAPIthat allows (limited) programmatic access to its databases. Too few
legal researchers, however, know how to use and interact with APIs.This library’s purpose is simple: make it easier to use CanLii’s APIs.
More than that, I demonstrate how easy it is to use code to facilitate
aspects of legal research. Use the library, but look at its source code
and see if it inspires you to do more.You can do this!Installpipinstallcanliicallsorcondainstallcanliicallsthen:fromcanliicalls.callerimport*UsageGet and use your secret API keyTo use CanLii’s API, you need your own secret access key. Applying for a
key is simple. Just send a request through theCanlii feedback
form.Once you have your API key, the rest is easy. First, enter your secret
API key and, second, enter your preferred language (‘en’ or ‘fr’). Then
call the object.api='MY SECRET API KEY'#this will look like lots of numbers and letterslanguage='en'my_caller=Caller(api,language)A sample research projectTo see how to use the library, let’s do a simple research project and
figure out what statutes a recent Supreme Court of Canada case cites to.
To do this, we need to figure out where CanLii stores the case and the
case name.Lookup CanLii database namesFirst, let’s get a list of CanLii database names.my_caller.list_tribunals()<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>databaseIdjurisdictionname0qccdoooqqcConseil de discipline de l'Ordre des opticiens...1qcoaciqqcComité de discipline de l'organisme d'autorégl...2skqbskCourt of King's Bench for Saskatchewan3onsconSuperior Court of Justice4abmgbabAlberta Municipal Government Board............357ytrtoykYukon Residential Tenancies Office358nbsecnbFinancial and Consumer Services Tribunal359onbcconBuilding Code Commission360exchc-cechcaExchequer Court of Canada361nttcntTerritorial Court of the Northwest Territories362 rows × 3 columnsWe can do a few things from here. First, if you want to save this as an
excel or a csv file, that’s easy!my_caller.list_tribunals().to_csv('CanLii_tribunal_list.csv')Or you can search directly for the Supreme Court of Canada’s database
ID.df=my_caller.list_tribunals()df[df['name']=='Supreme Court of Canada']<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>databaseIdjurisdictionname90csc-scccaSupreme Court of CanadaFind recent decisions by the SCCGreat! Now that we have the database ID for SCC cases, we can zero in on
a recent case. To list individual cases from the database, we call a
different function.This function has a few paramaters. You can decide whether you want the
results in ascending or descending chronological order (defaults to
descending) and how many results you want the API to return (defaults to
100).my_caller.list_decisions(databaseId='csc-scc',offset=0,resultCount=10)<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>caseIdtitlecitation02022scc34R. v. Schneider2022 SCC 34 (CanLII)12022scc33R. v. Kirkpatrick2022 SCC 33 (CanLII)22022scc32R. v. Lafrance2022 SCC 32 (CanLII)32022scc31R. v. Sundman2022 SCC 31 (CanLII)42022scc30Society of Composers, Authors and Music Publis...2022 SCC 30 (CanLII)52022scc29Law Society of Saskatchewan v. Abrametz2022 SCC 29 (CanLII)62022scc28R. v. J.J.2022 SCC 28 (CanLII)72022scc27British Columbia (Attorney General) v. Council...2022 SCC 27 (CanLII)82022scc26Canada (Attorney General) v. Collins Family Trust2022 SCC 26 (CanLII)92022scc25R. v. Goforth2022 SCC 25 (CanLII)Search for case metadataWe can look up the metadata for any case. Let’s see what the fifth case
down is about.my_caller.case_metadata(databaseId='csc-scc',caseId='2022scc30')databaseId                                                  csc-scc
caseId                                                    2022scc30
url                                       https://canlii.ca/t/jqgw0
title             Society of Composers, Authors and Music Publis...
citation                                       2022 SCC 30 (CanLII)
language                                                         en
docketNumber                                                  39418
decisionDate                                             2022-07-15
keywords          technological neutrality — available for on-de...
topics                                                             
concatenatedId                                        2022csc-scc30
dtype: objectCheck to see what legislation the Court citesInteresting! This case is interesting, I wonder what statutory
provisions in cites?my_caller.case_cites_of_legislation(databaseId='csc-scc',caseId='2022scc30')<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>databaseIdlegislationIdtitlecitationtype0casrsc-1985-c-c-42Copyright ActRSC 1985, c C-42STATUTE1caasc-2012-c-20Copyright Modernization ActSC 2012, c 20ANNUAL_STATUTEOnly two! Even though thefull
judgementis long, this looks right.Using loopsThis program is designed to support queries at scale. You can, for
example, retrieve all of the keywords for the last ten SCC decisions.First, request a dataframe of the last ten decisions.df=my_caller.list_decisions(databaseId='csc-scc',offset=0,resultCount=10)dfSecond, loop over the dataframe and make a separate call for the
keywords of each case.forindex,rowindf.iterrows():case=df.loc[index,'caseId']print(f'Keywords for{case}.')print(my_caller.case_metadata(databaseId='csc-scc',caseId=case)['keywords'])print('---')Keywords for 2022scc34.
brother — overheard — jury — evidence — probative value
---
Keywords for 2022scc33.
stare decisis — sexual activity — precedent — without a condom — sex
---
Keywords for 2022scc32.
police — detainee — detention — interview — encounter
---
Keywords for 2022scc31.
unlawful confinement — degree murder — domination — truck — temporal-causal connection
---
Keywords for 2022scc30.
technological neutrality — available for on-demand streaming — work — royalties — works
---
Keywords for 2022scc29.
abuse — inordinate delay — process — stay — prejudice
---
Keywords for 2022scc28.
record screening regime — complainants — privacy — evidence — defence
---
Keywords for 2022scc27.
well-developed factual setting — public interest standing — access to justice — disabilities — legality
---
Keywords for 2022scc26.
tax — rescission — taxpayer — rectification — mistake
---
Keywords for 2022scc25.
jury — unlawfully causing bodily harm — necessaries — mens rea requirement — marked departure
---