diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..73f10a9 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,28 @@ +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Set the OS, Python version, and other tools you might need +build: + os: ubuntu-24.04 + tools: + python: "3.13" + +# Build documentation in the "docs/" directory with Sphinx +sphinx: + configuration: docs/conf.py + +# Optionally, but recommended, +# declare the Python requirements required to build your documentation +# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html +# python: +# install: +# - requirements: docs/requirements.txt +python: + install: + - method: pip + path: . + extra_requirements: + - docs diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..607d08d --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,24 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information +from datetime import datetime, timezone + +project = "lexmachina-client" +copyright = "2025, support@lexmachina.com" +author = "support@lexmachina.com" +release = "2.0.0.20250318" + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = [] + +templates_path = ["_templates"] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + +html_theme = "sphinx_rtd_theme" +html_static_path = ["_static"] diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..bca8909 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,12 @@ +lexmachina-client documentation +=============================== + + +.. toctree:: + :caption: Contents: + :maxdepth: 2 + + installation + quickstart + spreadsheet_example + diff --git a/docs/installation.rst b/docs/installation.rst new file mode 100644 index 0000000..b93d81d --- /dev/null +++ b/docs/installation.rst @@ -0,0 +1,26 @@ +Installation +============ + +Install using pip within a virtual environment: + +.. code-block:: bash + + $ pip install lexmachina-client + + +The examples in :doc:`quickstart` and :doc:`spreadsheet_example` assume a valid bearer token is set in the environment variable ``BEARER_TOKEN``. You can get a bearer token by using the ``/oauth2/token`` endpoint: + +.. code-block:: bash + + $ curl -i -X POST 'https://api.lexmachina.com/oauth2/token' \ + --header 'Content-Type: application/x-www-form-urlencoded' \ + --data-urlencode 'client_id=' \ + --data-urlencode 'client_secret=' \ + --data-urlencode 'grant_type=client_credentials' + + +Then set that bearer token in the environment variable: + +.. code-block:: bash + + $ export BEARER_TOKEN= diff --git a/docs/quickstart.rst b/docs/quickstart.rst new file mode 100644 index 0000000..74cf7ef --- /dev/null +++ b/docs/quickstart.rst @@ -0,0 +1,103 @@ +Quickstart +========== + +After following the :doc:`installation` instructions and setting your bearer token in the environment variable ``BEARER_TOKEN``, you are ready to start! + +For this example, we'll search for a case and get its details. + +To get detailed information on an individual case, we'll need the Lex Machina id for that case. One way to get the Lex Machina case id is to search for it by case number. + +In the first code block, you will see the following steps: + +#. We configure the client. In this example we set the value of the bearer token in an environment variable (mostly to prevent contributors to this documentation from accidentally exposing credentials), but you could also feed the value directly to ``access_token``. + +#. Using the configured client, we create an object with access to the Federal District Case endpoints. +#. We do a case number search. For this example, we search for the Samsung Electronics v. Sandisk Corporation case with case number 9:02-cv-00058-JH. The case number search ignores judge initials at the end of a case number so they've been left out in the search example below. But they could be left in and the results would be the same. We further refine the search by using the optional court filter to limit our search to cases in the U.S. District Court for the Eastern District of Texas. + +Now to get started. In a jupyter notebook or ``ipython`` try out the following: + +.. code-block:: python + + import lexmachina + import os + + configuration = lexmachina.Configuration( + host="https://api.lexmachina.com", + access_token=os.environ["BEARER_TOKEN"] + ) + + api_client = lexmachina.ApiClient(configuration) + + fed_dist_case_api_instance = lexmachina.FederalDistrictCasesApi(api_client) + + case_search_results = fed_dist_case_api_instance.find_district_case_by_number( + case_numbers=["9:02-cv-00058"], court="txed" + ) + + +When we look at ``case_search_results``, this search conveniently returns just one result (if we had left out the court filter, it would have returned three results): + +.. code-block:: python + + case_search_results + [ + DistrictCaseNumberSearchResult( + total_count=1, + input_case_number='9:02-cv-00058', + input_court='txed', + matches=[ + DistrictCaseNumberReference( + url='https://api.lexmachina.com/district-cases/88', + district_case_id=88, + case_number='9:02-cv-00058', + court='U.S. District Court for the Eastern District of Texas', + title='Samsung Electronics v. Sandisk Corporation' + ) + ] + ] + +We can see from the output above the Lex Machina id for the case is 88. We will use that in the endpoint to get data on an individual case: + + +.. code-block:: python + + apple_v_sandisk_case = fed_dist_case_api_instance.get_district_case(88) + + +Just for example purposes, here is a sampling of data provided for this individual case. You'll see a number of ids that you can then use to get more information on invidual judges, law firms, attorneys, and parties. + +.. code-block:: python + + apple_v_sandisk_case.case_type + ['Patent'] + + apple_v_sandisk_case.patents + [Patent(number='5473563', title='Nonvolatile semiconductor memory'), + Patent(number='5514889', title='Non-volatile semiconductor memory device and method for manufacturing the same'), + Patent(number='5546341', title='Nonvolatile semiconductor memory'), + Patent(number='5642309', title='Auto-program circuit in a nonvolatile semiconductor memory device')] + + apple_v_sandisk_case.judges + [FederalJudge(name='John H. Hannah Jr.', federal_judge_id=969)] + + apple_v_sandisk_case.law_firms + [LawFirm(name='Fish & Richardson', law_firm_id=906, client_party_ids=[123]), + LawFirm(name='McKool Smith', law_firm_id=3425, client_party_ids=[25635]), + LawFirm(name='Weil, Gotshal & Manges', law_firm_id=4521, client_party_ids=[123]), + LawFirm(name='Ramey & Flock', law_firm_id=17879, client_party_ids=[25635]), + LawFirm(name='The Roth Law Firm (rothfirm.com)', law_firm_id=18116, client_party_ids=[111]), + LawFirm(name='Chandler Law Offices (cmzlaw.net)', law_firm_id=19244, client_party_ids=[123]), + LawFirm(name='Law Office of Claude E Welch', law_firm_id=38775, client_party_ids=[123]), + LawFirm(name='Richards & Penn', law_firm_id=7915397, client_party_ids=[123]), + LawFirm(name='Wilson Sonsini Goodrich & Rosati', law_firm_id=75246884, client_party_ids=[25635])] + + +This example uses the case number search endpoint to find the case id, but there are other ways to find it, such as the Federal District case query endpoint. + +To know your search options, it helps to be familiar with the user-facing Lex Machina website. We recognize that, for new users, the search options are not always immediately obvious. If you would like any help using the Lex Machina API, please contact support@lexmachina.com. + + + + + + diff --git a/docs/spreadsheet_example.rst b/docs/spreadsheet_example.rst new file mode 100644 index 0000000..dbeceb8 --- /dev/null +++ b/docs/spreadsheet_example.rst @@ -0,0 +1,328 @@ +Adding Case Data to a Spreadsheet +================================= + + +In this example, we will look at Antitrust cases that terminated in 2024, do some light timing analysis, and add data on those cases to a spreadsheet. + +We'll be using `openpyxl `_ to add data to an Excel file. You can install this package with the command ``pip install openpyxl``. + +In the :doc:`quickstart`, you saw how we created an API client object which we then used to create an object with access to the Federal District case API endpoints: + +.. code-block:: python + + import lexmachina + import os + + configuration = lexmachina.Configuration( + host="https://api.lexmachina.com", + access_token=os.environ["BEARER_TOKEN"] + ) + + api_client = lexmachina.ApiClient(configuration) + + fed_dist_case_api_instance = lexmachina.FederalDistrictCasesApi(api_client) + + +To get started on our cases search, we'll create a query for Antitrust cases terminated in 2024 in the form of a dictionary. The API returns results in "pages" with each page showing a maximum of 100 results. If your search returns more than 100 results, you'll need to page through them. You'll see in the example below we request the first page to start. + +.. code-block:: python + + query = { + "caseTypes": { + "include": [ + "Antitrust" + ] + }, + "dates": { + "terminated": { + "onOrAfter": "2024-01-01", + "onOrBefore": "2024-12-31" + } + }, + "page": 1, + "pageSize": 100 + } + + +Below, we iterate over pages and save the resulting case ids to a list. While this query returns under 700 cases, some queries return a lot of cases, so we use a print to provide progress updates. + + +.. code-block:: python + + case_ids = [] + done_paging = False + + while not done_paging: + query_response = fed_dist_case_api_instance.query_district_cases(query) + + if query_response.cases: + current_page = query['page'] + print(f'{current_page=}') + result_case_ids = [caseref.district_case_id for caseref in query_response.cases] + case_ids += result_case_ids + query['page'] = current_page + 1 + + else: + print(f'Number of Antitrust cases terminated in 2024: {len(case_ids)}') + done_paging=True + + +Armed with case ids, we can then get case data for each of those cases. While we could use more efficient list comprehension, for this example we'll use a loop so we can use a print to get updates on progress. + + +.. code-block:: python + + case_data = [] + + for case_id in case_ids: + case_data.append(fed_dist_case_api_instance.get_district_case(case_id)) + if len(case_data) % 20 == 0: + print(f'{len(case_data)} out of {len(case_ids)} processed') + + +We can now do some analysis. First we'll check which judges saw the most cases among Antitrust cases that terminated in 2024. +We'll also get info on how long these cases lasted. + +.. code-block:: python + + from collections import defaultdict + + cases_by_judge = defaultdict(list) + + for c in case_data: + for j in c.judges: + cases_by_judge[(j.name, j.federal_judge_id)].append( + dict(case_id=c.district_case_id, duration=c.dates.terminated - c.dates.filed) + ) + + +If we check the length of keys in ``cases_by_judge``, we'll see that 378 judges saw these 671 cases. We'll also check one of the judges to see how the data is represented. We see timing is represented in days. + +.. code-block:: python + + len(cases_by_judge) + 378 + + list(cases_by_judge)[:5] + [('Mitchell S. Goldberg', 3193), + ('Edmond E-Min Chang', 3342), + ('Miriam Goldman Cedarbaum', 406), + ('Lorna Gail Schofield', 3451), + ('Joel A. Pisano', 2851)] + + cases_by_judge[('Lorna Gail Schofield', 3451)] + [{'case_id': 2000009555, 'duration': datetime.timedelta(days=4981)}] + +Next, we'll get some timing info: + +.. code-block:: python + + all_durations = [] + + for case_group in cases_by_judge.values(): + all_durations += [c['duration'].days for c in case_group] + + +If we import the ``statistics`` library, we can check out the mean and median timing values for all Antitrust cases terminated in 2024 (timing is in days): + +.. code-block:: python + + import statistics + + round(statistics.mean(all_durations)) + 1084 + + statistics.median(all_durations) + 451 + + +Next, let's check how long these durations were for the judges who saw the most cases. + +First let's sort judges by case counts: + +.. code-block:: python + + case_count_by_judges = [ + (judge_info, len(cases_by_judge[judge_info])) + for judge_info in cases_by_judge + ] + + sorted_case_counts_by_judges = sorted( + case_count_by_judges, key=lambda x: x[-1], reverse=True + ) + +And then check duration stats for the top five judges: + +.. code-block:: python + + for j in sorted_case_counts_by_judges[:5]: + judge_cases = cases_by_judge[j[0]] + judge_durations = [c['duration'].days for c in judge_cases] + print('--------------------') + print(f'judge name: {j[0][0]}') + print(f'total num cases: {j[1]}') + print(f'average duration: {round(statistics.mean(judge_durations))}') + print(f'median duration: {statistics.median(judge_durations)}') + + + -------------------- + judge name: Edgardo Ramos + total num cases: 37 + average duration: 133 + median duration: 95 + -------------------- + judge name: Waverly David Crenshaw Jr. + total num cases: 34 + average duration: 280 + median duration: 307.0 + -------------------- + judge name: Sarah Elizabeth Pitlyk + total num cases: 30 + average duration: 1146 + median duration: 1178.0 + -------------------- + judge name: P. Kevin Castel + total num cases: 23 + average duration: 823 + median duration: 912 + -------------------- + judge name: Sara Elizabeth Lioi + total num cases: 23 + average duration: 65 + median duration: 71 + + +Now lets add the cases to a spreadsheet. + +For this example, since we focused on judges until now, for the spreadsheet let's focus on law firms and the roles of the parties they represented. + + +First we'll check the structure of the law firm and party data provided: + + +.. code-block:: python + + case_data[0].law_firms[:3] + [LawFirm(name='Kessler Topaz Meltzer & Check', law_firm_id=27, client_party_ids=[257121, 52552843, 231694, 37904, 23356662, 20047290, 24917852, 37648157]), + LawFirm(name='Hagens Berman Sobol Shapiro', law_firm_id=30, client_party_ids=[231694]), + LawFirm(name='Berger Montague', law_firm_id=51, client_party_ids=[231694])] + + case_data[0].parties[:3] + [Party(name='Pennsylvania Employees Benefit Trust Fund', party_id=37904, role='Plaintiff'), + Party(name='Cephalon, Inc.', party_id=20036179, role='Defendant'), + Party(name='Vista Health Plan, Inc.', party_id=20047290, role='Plaintiff')] + + +To translate party ids provided in law firm information to party names, we will create a dictionary mapping party ids to party names: + +.. code-block:: python + + parties_by_id_by_case_id = {} + + for c in case_data: + parties_by_id_by_case_id[c.district_case_id] = {} + for p in c.parties: + parties_by_id_by_case_id[c.district_case_id][p.party_id] = p + +Now we are ready to create our spreadsheet rows! We'll first determine which columns we want and then add that info for each row. + +.. code-block:: python + + column_names = [ + 'case id', + 'case number', + 'case title', + 'law_firm', + 'law_firm_id', + 'party', + 'party_id', + 'role' + ] + + rows = [] + rows.append(column_names) + + for c in case_data: + for law_firm in c.law_firms: + for party_id in law_firm.client_party_ids: + party = parties_by_id_by_case_id[c.district_case_id][party_id] + rows.append( + ( + c.district_case_id, + c.case_no, + c.title, + law_firm.name, + law_firm.law_firm_id, + party.name, + party.party_id, + party.role + ) + ) + +Now we'll spot check a few of them, including the header to make sure we added it. + +.. code-block:: python + + len(rows) + 19083 + + rows[0] + ['case id', + 'case number', + 'case title', + 'law_firm', + 'law_firm_id', + 'party', + 'party_id', + 'role'] + + rows[1] + (97091, + '2:06-cv-01833-MSG', + 'VISTA HEALTHPLAN, INC. v. CEPHALON, INC. et al', + 'Kessler Topaz Meltzer & Check', + 27, + 'SHIRLEY PANEBIANO', + 257121, + 'Plaintiff') + + rows[10000] + (2005150350, + '3:20-cv-05792-JD', + 'In re Google Play Developer Antitrust Litigation', + "O'Melveny & Myers", + 227639559, + 'Google Asia Pacific PTE. Limited', + 52824280, + 'Defendant') + + rows[-1] + (2034774512, + '3:24-cv-09118-VC', + 'Kushner et al v. Chunghwa Picture Tubes, Ltd. et al', + 'Goldman Scarlato & Penny', + 15211344, + 'Barry Kushner', + 10805, + 'Plaintiff') + + +Now let's add these rows to a spreadsheet. + +.. code-block:: python + + from openpyxl import Workbook + + wb = Workbook() + ws = wb.active + + for r in rows: + ws.append(r) + + wb.save("antitrust_terminated_2024_law_firms.xlsx") + wb.close() + + +The rows are then saved to the spreadsheet in your working directory. + +The API returns a lot of data for each case, including data on resolution, damages, and remedies. If you want any help figuring out how to get the information you want, please contact support@lexmachina.com. diff --git a/examples/spreadsheet_example.ipynb b/examples/spreadsheet_example.ipynb new file mode 100644 index 0000000..92323c1 --- /dev/null +++ b/examples/spreadsheet_example.ipynb @@ -0,0 +1,937 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "ae993c1c-a333-4de3-b2a9-842b31f3a386", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "from collections import defaultdict\n", + "import statistics\n", + "\n", + "import lexmachina\n", + "import openpyxl # pip install openpyxl" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "28656d9f-a5d0-4d32-8aa0-a08ff294b668", + "metadata": {}, + "outputs": [], + "source": [ + "configuration = lexmachina.Configuration(\n", + " host=\"https://api.lexmachina.com\",\n", + " access_token=os.environ[\"BEARER_TOKEN\"]\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "097d4903-2407-4115-8773-d4c06e7878a1", + "metadata": {}, + "outputs": [], + "source": [ + "api_client = lexmachina.ApiClient(configuration)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "11d376bb-e4eb-4c18-8b30-2b2798fca3dc", + "metadata": {}, + "outputs": [], + "source": [ + "fed_dist_case_api_instance = lexmachina.FederalDistrictCasesApi(api_client)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "a2059042-88b3-494a-8f2a-a727b41f29b0", + "metadata": {}, + "outputs": [], + "source": [ + "query = {\n", + " \"caseTypes\": {\n", + " \"include\": [\n", + " \"Antitrust\"\n", + " ]\n", + " },\n", + " \"dates\": {\n", + " \"terminated\": {\n", + " \"onOrAfter\": \"2024-01-01\",\n", + " \"onOrBefore\": \"2024-12-31\"\n", + " }\n", + " },\n", + " \"page\": 1,\n", + " \"pageSize\": 100\n", + " }" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "18d2c87d-7224-47c1-a503-d4f81d09c8e9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "current_page=1\n", + "current_page=2\n", + "current_page=3\n", + "current_page=4\n", + "current_page=5\n", + "current_page=6\n", + "current_page=7\n", + "Number of Antitrust cases terminated in 2024: 671\n" + ] + } + ], + "source": [ + "case_ids = []\n", + "done_paging = False\n", + "\n", + "while not done_paging:\n", + " query_response = fed_dist_case_api_instance.query_district_cases(query)\n", + "\n", + " if query_response.cases:\n", + " current_page = query['page']\n", + " print(f'{current_page=}')\n", + " result_case_ids = [caseref.district_case_id for caseref in query_response.cases]\n", + " case_ids += result_case_ids\n", + " query['page'] = current_page + 1\n", + "\n", + " else:\n", + " print(f'Number of Antitrust cases terminated in 2024: {len(case_ids)}')\n", + " done_paging=True" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "ebb09c14-4741-4008-9535-452b5ff989b4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Now getting indvidual case info\n", + "20 out of 671 processed\n", + "40 out of 671 processed\n", + "60 out of 671 processed\n", + "80 out of 671 processed\n", + "100 out of 671 processed\n", + "120 out of 671 processed\n", + "140 out of 671 processed\n", + "160 out of 671 processed\n", + "180 out of 671 processed\n", + "200 out of 671 processed\n", + "220 out of 671 processed\n", + "240 out of 671 processed\n", + "260 out of 671 processed\n", + "280 out of 671 processed\n", + "300 out of 671 processed\n", + "320 out of 671 processed\n", + "340 out of 671 processed\n", + "360 out of 671 processed\n", + "380 out of 671 processed\n", + "400 out of 671 processed\n", + "420 out of 671 processed\n", + "440 out of 671 processed\n", + "460 out of 671 processed\n", + "480 out of 671 processed\n", + "500 out of 671 processed\n", + "520 out of 671 processed\n", + "540 out of 671 processed\n", + "560 out of 671 processed\n", + "580 out of 671 processed\n", + "600 out of 671 processed\n", + "620 out of 671 processed\n", + "640 out of 671 processed\n", + "660 out of 671 processed\n" + ] + } + ], + "source": [ + "case_data = []\n", + "\n", + "for case_id in case_ids:\n", + " case_data.append(fed_dist_case_api_instance.get_district_case(case_id))\n", + " if len(case_data) % 20 == 0:\n", + " print(f'{len(case_data)} out of {len(case_ids)} processed')" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "b069531f-0c0b-440a-bf9a-18d5bd02bf01", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[FederalJudge(name='Mitchell S. Goldberg', federal_judge_id=3193)]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "case_data[0].judges" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "88204f40-0c2e-4b59-b140-407b6b0bd85e", + "metadata": {}, + "outputs": [], + "source": [ + "cases_by_judge = defaultdict(list)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "92093b5a-acd0-41c7-8b3c-841d94d873f5", + "metadata": {}, + "outputs": [], + "source": [ + "for c in case_data:\n", + " for j in c.judges:\n", + " cases_by_judge[(j.name, j.federal_judge_id)].append(dict(case_id=c.district_case_id, duration=c.dates.terminated - c.dates.filed))\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "6e7f1382-5988-4cb7-ae8b-058f9109fa7c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "378" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(cases_by_judge)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "afdb2296-fe46-4f84-8635-449ff78c0a01", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[('Mitchell S. Goldberg', 3193),\n", + " ('Edmond E-Min Chang', 3342),\n", + " ('Miriam Goldman Cedarbaum', 406),\n", + " ('Lorna Gail Schofield', 3451),\n", + " ('Joel A. Pisano', 2851)]" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(cases_by_judge)[:5]" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "ba5310fb-db7d-40e2-b682-54f9d8fe8eaf", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'case_id': 2000009555, 'duration': datetime.timedelta(days=4981)}]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cases_by_judge[('Lorna Gail Schofield', 3451)]" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "014909c0-f89c-45a8-b098-a797f4cfc51c", + "metadata": {}, + "outputs": [], + "source": [ + "all_durations = []" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "7a21f080-4aba-445d-a25a-4dc09e483408", + "metadata": {}, + "outputs": [], + "source": [ + "for case_group in cases_by_judge.values():\n", + " all_durations += [c['duration'].days for c in case_group]" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "53db69a3-8671-4982-8837-ffe726baa09e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[6752, 4015, 4011, 3980, 3952]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "all_durations[:5]" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "9ac3916f-77b4-47f1-925c-db595de7b037", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1084" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(statistics.mean(all_durations))" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "585fe050-7a73-47f3-bf89-b7986ad9f460", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "451" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "statistics.median(all_durations)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "34c9b660-853d-4b26-92ff-b03849bfa8bd", + "metadata": {}, + "outputs": [], + "source": [ + "case_count_by_judges = [(judge_info, len(cases_by_judge[judge_info])) for judge_info in cases_by_judge]" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "b8c7b5f7-9798-4036-957b-22f40eed1d83", + "metadata": {}, + "outputs": [], + "source": [ + "sorted_case_counts_by_judges = sorted(case_count_by_judges, key=lambda x: x[-1], reverse=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "5a9b2351-d5a0-4cef-b744-7a986428d4e7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[(('Edgardo Ramos', 3405), 37),\n", + " (('Waverly David Crenshaw Jr.', 3603), 34),\n", + " (('Sarah Elizabeth Pitlyk', 7465646), 30),\n", + " (('P. Kevin Castel', 3029), 23),\n", + " (('Sara Elizabeth Lioi', 3140), 23)]" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted_case_counts_by_judges[:5]" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "514d178c-3110-4564-a006-d6a6dbb4ebc7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[(('Steven Douglas Merryday', 1627), 1),\n", + " (('Mary Stenson Scriven', 3189), 1),\n", + " (('John George Koeltl', 1305), 1),\n", + " (('John Charles Hinderaker', 8938396), 1),\n", + " (('Yvonne Gonzalez Rogers', 3404), 1)]" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted_case_counts_by_judges[-5:]" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "b5b75e1a-b339-4255-a0e0-cd299b8eb944", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[{'case_id': 97091, 'duration': datetime.timedelta(days=6752)},\n", + " {'case_id': 2000045171, 'duration': datetime.timedelta(days=4015)},\n", + " {'case_id': 2000045229, 'duration': datetime.timedelta(days=4011)},\n", + " {'case_id': 2000046633, 'duration': datetime.timedelta(days=3980)},\n", + " {'case_id': 2000047864, 'duration': datetime.timedelta(days=3952)},\n", + " {'case_id': 2000049181, 'duration': datetime.timedelta(days=3918)},\n", + " {'case_id': 2000049340, 'duration': datetime.timedelta(days=3912)},\n", + " {'case_id': 2000049341, 'duration': datetime.timedelta(days=3912)},\n", + " {'case_id': 2000049655, 'duration': datetime.timedelta(days=3905)},\n", + " {'case_id': 2000049658, 'duration': datetime.timedelta(days=3905)},\n", + " {'case_id': 2000049746, 'duration': datetime.timedelta(days=3903)},\n", + " {'case_id': 2000051026, 'duration': datetime.timedelta(days=3863)}],\n", + " [{'case_id': 48907, 'duration': datetime.timedelta(days=6117)},\n", + " {'case_id': 2007889413, 'duration': datetime.timedelta(days=935)},\n", + " {'case_id': 2034461979, 'duration': datetime.timedelta(days=3)}],\n", + " [{'case_id': 2000009555, 'duration': datetime.timedelta(days=4981)}],\n", + " [{'case_id': 2000009555, 'duration': datetime.timedelta(days=4981)}],\n", + " [{'case_id': 2000026715, 'duration': datetime.timedelta(days=4739)},\n", + " {'case_id': 2000028620, 'duration': datetime.timedelta(days=4676)},\n", + " {'case_id': 2000029363, 'duration': datetime.timedelta(days=4653)},\n", + " {'case_id': 2000034588, 'duration': datetime.timedelta(days=4500)},\n", + " {'case_id': 2000035078, 'duration': datetime.timedelta(days=4481)}]]" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(cases_by_judge.values())[:5]" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "f6073a89-cc82-4400-bd2d-bde0894e5f60", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "--------------------\n", + "judge name: Edgardo Ramos\n", + "total num cases: 37\n", + "average duration: 133\n", + "median duration: 95\n", + "--------------------\n", + "judge name: Waverly David Crenshaw Jr.\n", + "total num cases: 34\n", + "average duration: 280\n", + "median duration: 307.0\n", + "--------------------\n", + "judge name: Sarah Elizabeth Pitlyk\n", + "total num cases: 30\n", + "average duration: 1146\n", + "median duration: 1178.0\n", + "--------------------\n", + "judge name: P. Kevin Castel\n", + "total num cases: 23\n", + "average duration: 823\n", + "median duration: 912\n", + "--------------------\n", + "judge name: Sara Elizabeth Lioi\n", + "total num cases: 23\n", + "average duration: 65\n", + "median duration: 71\n" + ] + } + ], + "source": [ + "for j in sorted_case_counts_by_judges[:5]:\n", + " judge_cases = cases_by_judge[j[0]]\n", + " judge_durations = [c['duration'].days for c in judge_cases]\n", + " print('--------------------')\n", + " print(f'judge name: {j[0][0]}')\n", + " print(f'total num cases: {j[1]}')\n", + " print(f'average duration: {round(statistics.mean(judge_durations))}')\n", + " print(f'median duration: {statistics.median(judge_durations)}')" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "c9de2e16-b774-41d1-91e0-270b592c385f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[LawFirm(name='Kessler Topaz Meltzer & Check', law_firm_id=27, client_party_ids=[257121, 52552843, 231694, 37904, 23356662, 20047290, 24917852, 37648157]),\n", + " LawFirm(name='Hagens Berman Sobol Shapiro', law_firm_id=30, client_party_ids=[231694]),\n", + " LawFirm(name='Berger Montague', law_firm_id=51, client_party_ids=[231694])]" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "case_data[0].law_firms[:3]" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "825628d6-1cdf-4ff4-b86b-f73bbd41b5a6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[Party(name='Pennsylvania Employees Benefit Trust Fund', party_id=37904, role='Plaintiff'),\n", + " Party(name='Cephalon, Inc.', party_id=20036179, role='Defendant'),\n", + " Party(name='Vista Health Plan, Inc.', party_id=20047290, role='Plaintiff')]" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "case_data[0].parties[:3]" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "8ac40da8-cd31-49a3-bdf0-16cbf08a77bb", + "metadata": {}, + "outputs": [], + "source": [ + "parties_by_id_by_case_id = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "c4a47c85-6044-45c8-9e79-e3d21f62402d", + "metadata": {}, + "outputs": [], + "source": [ + "for c in case_data:\n", + " parties_by_id_by_case_id[c.district_case_id] = {}\n", + " for p in c.parties:\n", + " parties_by_id_by_case_id[c.district_case_id][p.party_id] = p" + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "id": "feed8a02-9637-4acd-ba53-99043debbd1f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[97091, 48907, 2000009555, 2000026715, 2000028620]" + ] + }, + "execution_count": 114, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(parties_by_id_by_case_id.keys())[:5]" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "id": "baa34eab-f767-4cb9-818a-a543e031e57b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{24917852: Party(name='Debra Langan', party_id=24917852, role='Plaintiff'),\n", + " 23356662: Party(name='Pennsylvania Turnpike Commission', party_id=23356662, role='Plaintiff'),\n", + " 257121: Party(name='SHIRLEY PANEBIANO', party_id=257121, role='Plaintiff'),\n", + " 231694: Party(name='AvMed, Inc.', party_id=231694, role='Plaintiff'),\n", + " 34912145: Party(name='Jeffrey R. Krinsk', party_id=34912145, role='Plaintiff'),\n", + " 37648157: Party(name='District Council 37 Health and Security Plan', party_id=37648157, role='Plaintiff'),\n", + " 9750: Party(name='Eckerd Corporation', party_id=9750, role='Defendant'),\n", + " 2993: Party(name='Teva Pharmaceutical Industries Ltd.', party_id=2993, role='Defendant'),\n", + " 1087: Party(name='Teva Pharmaceuticals USA, Inc.', party_id=1087, role='Defendant'),\n", + " 27: Party(name='Mylan Pharmaceuticals, Inc.', party_id=27, role='Defendant'),\n", + " 1855: Party(name='Barr Laboratories, Inc.', party_id=1855, role='Defendant'),\n", + " 52552843: Party(name='End Payor Class Plaintiffs', party_id=52552843, role='Plaintiff'),\n", + " 20027124: Party(name='Ranbaxy Laboratories Limited', party_id=20027124, role='Defendant'),\n", + " 20047290: Party(name='Vista Health Plan, Inc.', party_id=20047290, role='Plaintiff'),\n", + " 20030256: Party(name='Ranbaxy Pharmaceuticals Inc.', party_id=20030256, role='Defendant'),\n", + " 20036179: Party(name='Cephalon, Inc.', party_id=20036179, role='Defendant'),\n", + " 20020989: Party(name='Mylan Laboratories, Inc.', party_id=20020989, role='Defendant'),\n", + " 37904: Party(name='Pennsylvania Employees Benefit Trust Fund', party_id=37904, role='Plaintiff')}" + ] + }, + "execution_count": 115, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "parties_by_id_by_case_id[97091]" + ] + }, + { + "cell_type": "code", + "execution_count": 192, + "id": "b6068f2d-d06d-4ad3-8d4d-3a3d1dd9bab6", + "metadata": {}, + "outputs": [], + "source": [ + "column_names = ['case id', 'case number', 'case title', 'law_firm', 'law_firm_id', 'party', 'party_id', 'role']" + ] + }, + { + "cell_type": "code", + "execution_count": 193, + "id": "64bd7dec-64a6-4c60-84e7-f4e96d056bc9", + "metadata": {}, + "outputs": [], + "source": [ + "rows = []" + ] + }, + { + "cell_type": "code", + "execution_count": 194, + "id": "34198f78-afaf-47d9-8593-212f3e138fb2", + "metadata": {}, + "outputs": [], + "source": [ + "rows.append(column_names)" + ] + }, + { + "cell_type": "code", + "execution_count": 195, + "id": "e8cfcf6c-0c76-460c-8be8-c40185b80a45", + "metadata": {}, + "outputs": [], + "source": [ + "for c in case_data:\n", + " for law_firm in c.law_firms:\n", + " for party_id in law_firm.client_party_ids:\n", + " party = parties_by_id_by_case_id[c.district_case_id][party_id]\n", + " rows.append(\n", + " (\n", + " c.district_case_id,\n", + " c.case_no,\n", + " c.title,\n", + " law_firm.name,\n", + " law_firm.law_firm_id,\n", + " party.name,\n", + " party.party_id,\n", + " party.role\n", + " )\n", + " )\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 196, + "id": "5fed65b3-31a2-4ec4-9e4b-2fe3435cded2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "19084" + ] + }, + "execution_count": 196, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(rows)" + ] + }, + { + "cell_type": "code", + "execution_count": 197, + "id": "c50fbd93-0f85-4d52-bee9-4759bf774e40", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['case id',\n", + " 'case number',\n", + " 'case title',\n", + " 'law_firm',\n", + " 'law_firm_id',\n", + " 'party',\n", + " 'party_id',\n", + " 'role']" + ] + }, + "execution_count": 197, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rows[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 198, + "id": "a04480d5-2182-4693-a6ca-ccb8328ef5de", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(97091,\n", + " '2:06-cv-01833-MSG',\n", + " 'VISTA HEALTHPLAN, INC. v. CEPHALON, INC. et al',\n", + " 'Kessler Topaz Meltzer & Check',\n", + " 27,\n", + " 'SHIRLEY PANEBIANO',\n", + " 257121,\n", + " 'Plaintiff')" + ] + }, + "execution_count": 198, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rows[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 199, + "id": "053c2b2a-03e5-4c7d-9878-51822201b376", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2005150350,\n", + " '3:20-cv-05792-JD',\n", + " 'In re Google Play Developer Antitrust Litigation',\n", + " \"O'Melveny & Myers\",\n", + " 227639559,\n", + " 'Google Asia Pacific PTE. Limited',\n", + " 52824280,\n", + " 'Defendant')" + ] + }, + "execution_count": 199, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rows[10000]" + ] + }, + { + "cell_type": "code", + "execution_count": 201, + "id": "4a93247c-fd30-416a-9292-c9ac8ef79088", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2034774512,\n", + " '3:24-cv-09118-VC',\n", + " 'Kushner et al v. Chunghwa Picture Tubes, Ltd. et al',\n", + " 'Goldman Scarlato & Penny',\n", + " 15211344,\n", + " 'Barry Kushner',\n", + " 10805,\n", + " 'Plaintiff')" + ] + }, + "execution_count": 201, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rows[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": 140, + "id": "f613953c-3284-42f2-9ef7-111f507f6f01", + "metadata": {}, + "outputs": [], + "source": [ + "from openpyxl import Workbook" + ] + }, + { + "cell_type": "code", + "execution_count": 202, + "id": "bf3996a5-6605-45b9-a250-a092b583e756", + "metadata": {}, + "outputs": [], + "source": [ + "wb.close()" + ] + }, + { + "cell_type": "code", + "execution_count": 203, + "id": "cd0f289b-cb72-4f93-8ec9-347fd3513293", + "metadata": {}, + "outputs": [], + "source": [ + "wb = Workbook()" + ] + }, + { + "cell_type": "code", + "execution_count": 204, + "id": "d92307cb-c9d7-49a1-812d-05e68b09b448", + "metadata": {}, + "outputs": [], + "source": [ + "ws = wb.active" + ] + }, + { + "cell_type": "code", + "execution_count": 205, + "id": "038d3234-2147-497d-8c49-ee1b4f6e2913", + "metadata": {}, + "outputs": [], + "source": [ + "for r in rows:\n", + " ws.append(r)" + ] + }, + { + "cell_type": "code", + "execution_count": 206, + "id": "662327a4-07d1-4de2-84ac-38935232d567", + "metadata": {}, + "outputs": [], + "source": [ + "wb.save(\"antitrust_terminated_2024_law_firms.xlsx\")" + ] + }, + { + "cell_type": "code", + "execution_count": 207, + "id": "319a6849-254f-4b6a-b220-8d2cb70b70e0", + "metadata": {}, + "outputs": [], + "source": [ + "wb.close()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/pyproject.toml b/pyproject.toml index cbdb268..b959656 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ dependencies = [ ] [project.urls] -Documentation = "https://github.com/LexMachinaInc/python-lexmachina-sync-api-client" +Documentation = "https://lexmachinaincpython-lexmachina-sync-api-client.readthedocs.io/en/latest/" Issues = "https://github.com/LexMachinaInc/python-lexmachina-sync-api-client/issues" Source = "https://github.com/LexMachinaInc/python-lexmachina-sync-api-client" Changelog = "https://github.com/LexMachinaInc/python-lexmachina-sync-api-client/blob/main/CHANGELOG.md" @@ -66,7 +66,8 @@ exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"] [project.optional-dependencies] tests = ["pytest >=7.2.1", "pytest-asyncio >= 0.21.0"] -dev = ['ipython >= 8.14.0', 'jupyterlab >= 4.0.0'] +dev = ["ipython >= 8.14.0", "jupyterlab >= 4.0.0"] +docs = ["sphinx>=8.2.3", "sphinx-rtd-theme>=3.0.2"] [tool.hatch.build.targets.wheel] diff --git a/requirements-docs.txt b/requirements-docs.txt new file mode 100644 index 0000000..3ec5c6f --- /dev/null +++ b/requirements-docs.txt @@ -0,0 +1,105 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# pip-compile --extra=docs --output-file=requirements-docs.txt pyproject.toml +# +aiohappyeyeballs==2.6.1 + # via aiohttp +aiohttp==3.11.18 + # via lexmachina-client (pyproject.toml) +aiosignal==1.3.2 + # via aiohttp +alabaster==1.0.0 + # via sphinx +annotated-types==0.7.0 + # via pydantic +attrs==25.3.0 + # via aiohttp +babel==2.17.0 + # via sphinx +certifi==2025.4.26 + # via requests +charset-normalizer==3.4.2 + # via requests +docutils==0.21.2 + # via + # sphinx + # sphinx-rtd-theme +frozenlist==1.6.0 + # via + # aiohttp + # aiosignal +idna==3.10 + # via + # requests + # yarl +imagesize==1.4.1 + # via sphinx +jinja2==3.1.6 + # via sphinx +markupsafe==3.0.2 + # via jinja2 +multidict==6.4.3 + # via + # aiohttp + # yarl +packaging==25.0 + # via sphinx +propcache==0.3.1 + # via + # aiohttp + # yarl +pydantic==2.11.4 + # via lexmachina-client (pyproject.toml) +pydantic-core==2.33.2 + # via pydantic +pygments==2.19.1 + # via sphinx +python-dateutil==2.9.0.post0 + # via lexmachina-client (pyproject.toml) +requests==2.32.3 + # via + # lexmachina-client (pyproject.toml) + # sphinx +roman-numerals-py==3.1.0 + # via sphinx +six==1.17.0 + # via python-dateutil +snowballstemmer==3.0.0.1 + # via sphinx +sphinx==8.2.3 + # via + # lexmachina-client (pyproject.toml) + # sphinx-rtd-theme + # sphinxcontrib-jquery +sphinx-rtd-theme==3.0.2 + # via lexmachina-client (pyproject.toml) +sphinxcontrib-applehelp==2.0.0 + # via sphinx +sphinxcontrib-devhelp==2.0.0 + # via sphinx +sphinxcontrib-htmlhelp==2.1.0 + # via sphinx +sphinxcontrib-jquery==4.1 + # via sphinx-rtd-theme +sphinxcontrib-jsmath==1.0.1 + # via sphinx +sphinxcontrib-qthelp==2.0.0 + # via sphinx +sphinxcontrib-serializinghtml==2.0.0 + # via sphinx +typing-extensions==4.13.2 + # via + # lexmachina-client (pyproject.toml) + # pydantic + # pydantic-core + # typing-inspection +typing-inspection==0.4.0 + # via pydantic +urllib3==2.4.0 + # via + # lexmachina-client (pyproject.toml) + # requests +yarl==1.20.0 + # via aiohttp diff --git a/tests/test_case_search.py b/tests/test_case_search.py index 399755f..7f260da 100644 --- a/tests/test_case_search.py +++ b/tests/test_case_search.py @@ -10,22 +10,22 @@ def api_client(): configuration = lexmachina.Configuration( host="https://api.lexmachina.com", access_token=os.environ["BEARER_TOKEN"] ) - api_client = lexmachina.ApiClient(configuration) - yield api_client + with lexmachina.ApiClient(configuration) as api_client: + yield api_client @pytest.fixture(scope="module") -def fed_cases_api(api_client): +def fed_cases_api_instance(api_client): yield lexmachina.FederalDistrictCasesApi(api_client) @pytest.fixture(scope="module") -def state_cases_api(api_client): +def state_cases_api_instance(api_client): yield lexmachina.StateCasesApi(api_client) -def test_fed_case_number_search(fed_cases_api): - case_search_results = fed_cases_api.find_district_case_by_number( +def test_fed_case_number_search(fed_cases_api_instance): + case_search_results = fed_cases_api_instance.find_district_case_by_number( case_numbers=["1:11-cv-11681-NMG"], court="mad" ) case_result = case_search_results[0] @@ -33,7 +33,7 @@ def test_fed_case_number_search(fed_cases_api): assert 2000026401 in [match.district_case_id for match in case_result.matches] -def test_fed_case_query(fed_cases_api): +def test_fed_case_query(fed_cases_api_instance): query = { "caseStatus": "Terminated", "courts": {"include": ["mad"]}, @@ -48,19 +48,19 @@ def test_fed_case_query(fed_cases_api): "pageSize": 5, } fed_case_query = lexmachina.DistrictCaseQuery.from_dict(query) - fed_case_query_result = fed_cases_api.query_district_cases(fed_case_query) + fed_case_query_result = fed_cases_api_instance.query_district_cases(fed_case_query) assert 1 < len(fed_case_query_result.cases) < 5 case_ids = [case_ref.district_case_id for case_ref in fed_case_query_result.cases] assert 2000026401 in case_ids -def test_get_fed_case(fed_cases_api): - case_data = fed_cases_api.get_district_case(2000026401) +def test_get_fed_case(fed_cases_api_instance): + case_data = fed_cases_api_instance.get_district_case(2000026401) law_firm_names = [firm.name for firm in case_data.law_firms] assert "Morrison & Foerster" in law_firm_names -def test_state_case_query(state_cases_api): +def test_state_case_query(state_cases_api_instance): query = { "caseStatus": "Terminated", "courts": {"include": ["Court of Chancery"], "state": "DE"}, @@ -75,7 +75,9 @@ def test_state_case_query(state_cases_api): "pageSize": 5, } state_case_query = lexmachina.StateCaseQuery.from_dict(query) - state_case_query_result = state_cases_api.query_state_cases(state_case_query) + state_case_query_result = state_cases_api_instance.query_state_cases( + state_case_query + ) assert 1 <= len(state_case_query_result.cases) < 5 state_case_ids = [ case_ref.state_case_id for case_ref in state_case_query_result.cases @@ -83,7 +85,7 @@ def test_state_case_query(state_cases_api): assert 2034871656 in state_case_ids -def test_get_state_case(state_cases_api): - case_data = state_cases_api.get_state_case(2034871656) +def test_get_state_case(state_cases_api_instance): + case_data = state_cases_api_instance.get_state_case(2034871656) law_firm_names = [firm.name for firm in case_data.law_firms] assert "Skadden, Arps, Slate, Meagher & Flom" in law_firm_names