From cada1db42774dc7a6ec917512948393e6f7b7ee1 Mon Sep 17 00:00:00 2001 From: Frances Wong Date: Thu, 20 Aug 2026 15:28:29 -0600 Subject: [PATCH] Remove unsupported v1 and update readme --- config/config.ini | 13 - custom_templates/common_README.mustache | 5 + src/lexmachina/v1/__init__.py | 12 - src/lexmachina/v1/_async/__init__.py | 0 src/lexmachina/v1/_async/auth.py | 88 ---- src/lexmachina/v1/_async/base_request.py | 39 -- src/lexmachina/v1/_async/client.py | 145 ----- src/lexmachina/v1/_async/query_cases.py | 39 -- src/lexmachina/v1/_sync/__init__.py | 0 src/lexmachina/v1/_sync/auth.py | 87 --- src/lexmachina/v1/_sync/base_request.py | 39 -- src/lexmachina/v1/_sync/client.py | 196 ------- src/lexmachina/v1/_sync/query_cases.py | 39 -- src/lexmachina/v1/query/__init__.py | 0 src/lexmachina/v1/query/appeals_casequery.py | 488 ----------------- src/lexmachina/v1/query/district_casequery.py | 496 ------------------ src/lexmachina/v1/query/state_casequery.py | 495 ----------------- src/lexmachina_README.md | 5 + 18 files changed, 10 insertions(+), 2176 deletions(-) delete mode 100644 config/config.ini delete mode 100644 src/lexmachina/v1/__init__.py delete mode 100644 src/lexmachina/v1/_async/__init__.py delete mode 100644 src/lexmachina/v1/_async/auth.py delete mode 100644 src/lexmachina/v1/_async/base_request.py delete mode 100644 src/lexmachina/v1/_async/client.py delete mode 100644 src/lexmachina/v1/_async/query_cases.py delete mode 100644 src/lexmachina/v1/_sync/__init__.py delete mode 100644 src/lexmachina/v1/_sync/auth.py delete mode 100644 src/lexmachina/v1/_sync/base_request.py delete mode 100644 src/lexmachina/v1/_sync/client.py delete mode 100644 src/lexmachina/v1/_sync/query_cases.py delete mode 100644 src/lexmachina/v1/query/__init__.py delete mode 100644 src/lexmachina/v1/query/appeals_casequery.py delete mode 100644 src/lexmachina/v1/query/district_casequery.py delete mode 100644 src/lexmachina/v1/query/state_casequery.py diff --git a/config/config.ini b/config/config.ini deleted file mode 100644 index 0498e72..0000000 --- a/config/config.ini +++ /dev/null @@ -1,13 +0,0 @@ -# TODO Used for v1 only - can delete after get rid of v1 -[URLS] -token_url = /oauth2/token -base_url = https://api.lexmachina.com - -[CREDENTIALS] -client_id = -client_secret = - -[TOKEN] -issued_at = -access_token = - diff --git a/custom_templates/common_README.mustache b/custom_templates/common_README.mustache index c1b58c5..9e28712 100644 --- a/custom_templates/common_README.mustache +++ b/custom_templates/common_README.mustache @@ -78,6 +78,11 @@ Class | Method | HTTP request | Description {{/authMethods}} +## v1.x Client + +v1.x of the Python client was deprecated in April 2024. If you are still using a 1.x version, please upgrade to the latest 2.x version. If for some reason you will want to use a deprecated version, the last version can be found [here](https://pypi.org/project/lexmachina-client/1.2.1/). + + ## Contact Send any questions to support@lexmachina.com. \ No newline at end of file diff --git a/src/lexmachina/v1/__init__.py b/src/lexmachina/v1/__init__.py deleted file mode 100644 index 4bb177f..0000000 --- a/src/lexmachina/v1/__init__.py +++ /dev/null @@ -1,12 +0,0 @@ -from lexmachina.v1._sync.client import LexMachinaClient -from lexmachina.v1._async.client import LexMachinaAsyncClient -from lexmachina.v1.query.district_casequery import DistrictCaseQueryRequest -from lexmachina.v1.query.state_casequery import StateCaseQueryRequest - - -__all__ = [ - 'LexMachinaClient', - 'LexMachinaAsyncClient', - 'DistrictCaseQueryRequest', - 'StateCaseQueryRequest' -] \ No newline at end of file diff --git a/src/lexmachina/v1/_async/__init__.py b/src/lexmachina/v1/_async/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/lexmachina/v1/_async/auth.py b/src/lexmachina/v1/_async/auth.py deleted file mode 100644 index 59d90e5..0000000 --- a/src/lexmachina/v1/_async/auth.py +++ /dev/null @@ -1,88 +0,0 @@ -import os - -import aiohttp -import configparser -from datetime import datetime -from pathlib import Path - - -class Auth: - def __init__(self, config_file_path=None, client_id=None, client_secret=None) -> None: - self._config_file_path = config_file_path - self._client_id = client_id - self._client_secret = client_secret - self._headers = {"Content-Type": "application/x-www-form-urlencoded"} - - async def _get_token(self): - config, config_file = self.config_reader() - async with aiohttp.ClientSession() as session: - token_url = config.get("URLS", "base_url") + config.get("URLS", "token_url") - if self._client_id is None and self._client_secret is None: - if config.has_section("TOKEN") and config.get("TOKEN", "ACCESS_TOKEN") != '': - now = datetime.utcnow().timestamp() - else: - return await self.renew_token(config, config_file, session, token_url) - - if not now - float(config.get("TOKEN", "ISSUED_AT")) >= 3599: - return config.get("TOKEN", "ACCESS_TOKEN") - else: - return await self.renew_token(config, config_file, session, token_url) - else: - config["CREDENTIALS"] = { - "client_id": self._client_id, - "client_secret": self._client_secret - } - with open(config_file, 'w') as file: - config.write(file) - async with session.post(token_url, headers=self._headers, data={ - "grant_type": "client_credentials", - "client_id":config.get("CREDENTIALS", "client_id"), - "client_secret": config.get("CREDENTIALS", "client_secret") - }) as response: - if not response.status == 200: - raise Exception(await response.json()) - - else: - access_token = await response.json() - config["TOKEN"] = { - "issued_at": str(datetime.utcnow().timestamp()), - "access_token": access_token['access_token'] - } - with open(config_file, 'w') as file: - config.write(file) - return access_token['access_token'] - - def config_reader(self): - config = configparser.ConfigParser() - if not self._config_file_path: - config_file = Path("./config/config.ini") - else: - config_file = Path(self._config_file_path) - if not config_file.is_file(): - os.makedirs("./config") - config_file.touch(exist_ok=True) - config['URLS'] = {"base_url": "https://api.lexmachina.com", - "token_url": "/oauth2/token"} - with open(config_file, 'w') as file_object: - config.write(file_object) - else: - config.read(config_file) - return config, config_file - - async def renew_token(self, config, config_file, session, token_url): - async with session.post(token_url, headers=self._headers, data={ - "grant_type": "client_credentials", - "client_id": config.get("CREDENTIALS", "client_id"), - "client_secret": config.get("CREDENTIALS", "client_secret") - }) as response: - if not response.status == 200: - raise Exception(await response.json()) - else: - access_token = await response.json() - if not config.has_section("TOKEN"): - config.add_section("TOKEN") - config['TOKEN']['ISSUED_AT'] = str(datetime.utcnow().timestamp()) - config['TOKEN']['ACCESS_TOKEN'] = access_token['access_token'] - with open(config_file, "w") as configfile: - config.write(configfile) - return access_token['access_token'] diff --git a/src/lexmachina/v1/_async/base_request.py b/src/lexmachina/v1/_async/base_request.py deleted file mode 100644 index d15eb91..0000000 --- a/src/lexmachina/v1/_async/base_request.py +++ /dev/null @@ -1,39 +0,0 @@ -import json - -import aiohttp -from aiohttp import ContentTypeError - -from .auth import Auth - - -class BaseRequest(Auth): - async def _get(self, path=None, args=None, params=None): - config, config_file = self.config_reader() - try: - async with aiohttp.ClientSession() as session: - url = config.get("URLS", "base_url") - headers = {"Authorization": f"Bearer {await self._get_token()}", "User-Agent": "lexmachina-python-async-client-0.0.2"} - if args is None: - url = f"{url}/{path}" - else: - url = f"{url}/{path}/{args}" - async with session.get(url, headers=headers, - params=params) as response: - return await response.json() - except ContentTypeError: - return await response.text() - - async def _post(self, path=None, data=None): - config, config_file = self.config_reader() - async with aiohttp.ClientSession() as session: - url = config.get("URLS", "base_url") - headers = {"Authorization": f"Bearer {await self._get_token()}", "User-Agent": "lexmachina-python-async-client-0.0.2"} - url = f"{url}/{path}" - try: - - async with session.post( - url, headers=headers, json=data - ) as response: - return await response.json() - except ContentTypeError: - return await response.text() diff --git a/src/lexmachina/v1/_async/client.py b/src/lexmachina/v1/_async/client.py deleted file mode 100644 index 1eefc68..0000000 --- a/src/lexmachina/v1/_async/client.py +++ /dev/null @@ -1,145 +0,0 @@ -from typing import List -import configparser - -from .base_request import BaseRequest -from .query_cases import QueryCase - - -class LexMachinaAsyncClient(BaseRequest): - def __init__(self, config_file_path=None, client_id=None, client_secret=None): - if config_file_path: - config = configparser.ConfigParser() - config.read(config_file_path) - client_id = config['CREDENTIALS']['client_id'] - client_secret = config['CREDENTIALS']['client_secret'] - - super().__init__(config_file_path, client_id, client_secret) - self._config_file_path = config_file_path - self._client_id = client_id - self._client_secret = client_secret - self.query = QueryCase(config=self._config_file_path) - - async def get_district_cases(self, cases: int): - return await self._get(path='district-cases', args=cases) - - async def get_state_cases(self, cases: int) -> dict: - return await self._get(path="state-cases", args=cases) - - - async def get_appeals_cases(self, cases: int) -> dict: - return await self._get(path='appeals-cases', args=cases) - async def query_state_cases_case(self, query, options=None, page_size=100): - return await self.query.query_case(query=query, options=options, page_size=page_size, endpoint='state-cases') - - async def query_district_case(self, query, options=None, page_size=100): - return await self.query.query_case('district-cases', query, options, page_size) - - async def query_appeals_case(self, query, options=None, page_size=100): - return await self.query.query_case('appeals-cases', query, options, page_size) - - async def get_parties(self, parties: List[str]): - if isinstance(parties, list): - response = await self._get(path='parties', params={"partyIds": parties}) - else: - response = await self._get(path='parties', args=parties) - return response - - async def search_parties(self, q: str, page_number: int = 1, page_size: int = 500): - return await self._get(path='search-parties', params={"q": q, - "pageNumber": page_number, - "pageSize": page_size}) - - async def get_attorneys(self, attorneys: List[int]): - if isinstance(attorneys, list): - response = await self._get(path='attorneys', params={"attorneyIds": attorneys}) - else: - response = await self._get(path='attorneys', args=attorneys) - return response - - async def search_attorneys(self, q: str, page_number: int = 1, page_size: int = 500): - response = await self._get(path='search-attorneys', params={"q": q, - "pageNumber": page_number, - "pageSize": page_size}) - return response - - async def get_law_firms(self, law_firms: List[int]): - if isinstance(law_firms, list): - response = await self._get(path='law-firms', params={"lawFirmIds": law_firms}) - else: - response = await self._get(path='law-firms', args=law_firms) - return response - - async def search_law_firms(self, q: str, page_number: int = 1, page_size: int = 500): - return await self._get(path='search-law-firms', params={"q": q, - "pageNumber": page_number, - "pageSize": page_size}) - - async def get_federal_judges(self, federal_judges: List[int]): - if isinstance(federal_judges, list): - response = await self._get(path='federal-judges', params={"federalJudgeIds": federal_judges}) - else: - response = await self._get(path='federal-judges', args=federal_judges) - return response - - async def get_state_judges(self, state_judges: List[int]): - if isinstance(state_judges, list): - response = await self._get(path='state-judges', params={"stateJudgeIds": state_judges}) - else: - response = await self._get(path='state-judges', args=state_judges) - return response - - async def get_magistrate_judges(self, magistrate_judges: str): - return await self._get(path='magistrate-judges', args=magistrate_judges) - - async def search_judges(self, q: str): - return await self._get(path='search-judges', params={"q": q}) - - async def get_patents(self, patents: List[str]): - if isinstance(patents, list): - response = await self._get(path='patents', params={"patentNumbers": patents}) - else: - response = await self._get(path='patents', args=patents) - return response - - async def list_case_resolutions(self, court_type): - return await self._list(path=f'list-case-resolutions/{court_type}') - - async def list_case_tags(self, court_type): - return await self._list(path=f'list-case-tags/{court_type}') - - async def list_case_types(self, court_type): - return await self._list(path=f'list-case-types/{court_type}') - - async def list_courts(self, court_types): - return await self._list(path=f'list-courts/{court_types}') - - async def list_damages_federal(self): - return await self._list(path='list-damages/FederalDistrict') - - async def list_damages_state(self): - return await self._list(path='list-damages/State') - - - async def list_events(self, court_type): - return await self._list(path=f'list-events/{court_type}') - - async def list_judgment_sources_federal(self): - return await self._list(path='list-judgment-sources/FederalDistrict') - - async def list_judgment_events_state(self): - return await self._list(path='list-judgment-events/State') - - async def list_originating_venues_federal(self): - return await self._list(path='list-originating-venues/FederalAppeals') - - async def list_appellate_decisions_federal(self): - return await self._list(path='list-appellate-decisions/FederalDistrict') - - async def list_supreme_court_decisions_federal(self): - return await self._list(path='list-supreme-court-decisions/FederalAppeals') - - async def _list(self, path): - return await self._get(path=path) - - async def health(self): - return await self._get(path="health") \ No newline at end of file diff --git a/src/lexmachina/v1/_async/query_cases.py b/src/lexmachina/v1/_async/query_cases.py deleted file mode 100644 index 05ad830..0000000 --- a/src/lexmachina/v1/_async/query_cases.py +++ /dev/null @@ -1,39 +0,0 @@ -from .base_request import BaseRequest - - -class QueryCase: - def __init__(self, config=None): - self.case_query = BaseRequest(config) - - async def query_one_page(self, query, endpoint): - if endpoint == 'district-cases': - response = await self.case_query._post(path="query-district-cases", data=query) - elif endpoint =='state-cases': - response = await self.case_query._post(path="query-state-cases", data=query) - elif endpoint =='appeals-cases': - response = await self.case_query._post(path="query-appeals-cases", data=query) - if response: - return response.get("cases") - return [] - - async def query_all_pages(self, query, endpoint, page_size): - cases = [] - if page_size > 100: - raise ValueError("Page size must be <= 100") - query.set_page_size(page_size) - query_results = query.execute() - while True: - page_cases = await self.query_one_page(query_results, endpoint) - if page_cases: - cases.extend(page_cases) - query.next_page() - if not page_cases: - break - return cases - - async def query_case(self, endpoint, query, options, page_size): - query_results = query.execute() - if options and options['pageThrough']: - return await self.query_all_pages(query, endpoint, page_size) - else: - return await self.query_one_page(query_results, endpoint) diff --git a/src/lexmachina/v1/_sync/__init__.py b/src/lexmachina/v1/_sync/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/lexmachina/v1/_sync/auth.py b/src/lexmachina/v1/_sync/auth.py deleted file mode 100644 index 3215292..0000000 --- a/src/lexmachina/v1/_sync/auth.py +++ /dev/null @@ -1,87 +0,0 @@ -import os - -import requests -import configparser -from datetime import datetime -from pathlib import Path - - -class Auth: - def __init__(self, config_file_path=None, client_id=None, client_secret=None) -> None: - self._config_file_path = config_file_path - self._client_id = client_id - self._client_secret = client_secret - self._headers = {"Content-Type": "application/x-www-form-urlencoded"} - - def get_token(self): - config, config_file = self.config_reader() - with requests.Session() as session: - token_url = config.get("URLS", "base_url") + config.get("URLS", "token_url") - if self._client_id is None and self._client_secret is None: - if config.has_section("TOKEN") and config.get("TOKEN", "ACCESS_TOKEN") != '': - now = datetime.utcnow().timestamp() - else: - return self.renew_token(config, config_file, session, token_url) - - if not now - float(config.get("TOKEN", "ISSUED_AT")) >= 3599: - return config.get("TOKEN", "ACCESS_TOKEN") - else: - return self.renew_token(config, config_file, session, token_url) - else: - config["CREDENTIALS"] = { - "client_id": self._client_id, - "client_secret": self._client_secret - } - with open(config_file, 'w') as file: - config.write(file) - with session.post(token_url, headers=self._headers, data={ - "grant_type": "client_credentials", - "client_id": config.get("CREDENTIALS", "client_id"), - "client_secret": config.get("CREDENTIALS", "client_secret") - }) as response: - if not response.status_code == 200: - raise Exception(response.json()) - else: - access_token = response.json() - config["TOKEN"] = { - "issued_at": str(datetime.utcnow().timestamp()), - "access_token": access_token['access_token'] - } - with open(config_file, 'w') as file: - config.write(file) - return access_token['access_token'] - - def config_reader(self): - config = configparser.ConfigParser() - if not self._config_file_path: - config_file = Path("./config/config.ini") - else: - config_file = Path(self._config_file_path) - if not config_file.is_file(): - os.makedirs("./config") - config_file.touch(exist_ok=True) - config['URLS'] = {"base_url": "https://api.lexmachina.com", - "token_url": "/oauth2/token"} - with open(config_file, 'w') as file_object: - config.write(file_object) - else: - config.read(config_file) - return config, config_file - - def renew_token(self, config, config_file, session, token_url): - with session.post(token_url, headers=self._headers, data={ - "grant_type": "client_credentials", - "client_id": config.get("CREDENTIALS", "client_id"), - "client_secret": config.get("CREDENTIALS", "client_secret") - }) as response: - if not response.status_code == 200: - raise Exception(response.json()) - else: - access_token = response.json() - if not config.has_section("TOKEN"): - config.add_section("TOKEN") - config['TOKEN']['ISSUED_AT'] = str(datetime.utcnow().timestamp()) - config['TOKEN']['ACCESS_TOKEN'] = access_token['access_token'] - with open(config_file, "w") as configfile: - config.write(configfile) - return access_token['access_token'] \ No newline at end of file diff --git a/src/lexmachina/v1/_sync/base_request.py b/src/lexmachina/v1/_sync/base_request.py deleted file mode 100644 index cac92a4..0000000 --- a/src/lexmachina/v1/_sync/base_request.py +++ /dev/null @@ -1,39 +0,0 @@ -import configparser -from pathlib import Path - -import requests -from requests import JSONDecodeError - -from .auth import Auth - - -class BaseRequest(Auth): - def _get(self, path=None, args=None, params=None): - config, config_file = self.config_reader() - with requests.Session() as session: - url = config.get("URLS", "base_url") - headers = {"Authorization": f"Bearer {self.get_token()}", "User-Agent": "lexmachina-python-client-0.0.2"} - if args is None: - url = f"{url}/{path}" - else: - url = f"{url}/{path}/{args}" - try: - with session.get(url, headers=headers, - params=params) as response: - return response.json() - except JSONDecodeError: - return response.text - - def _post(self, path=None, data=None): - config, config_file = self.config_reader() - with requests.Session() as session: - url = config.get("URLS", "base_url") - headers = {"Authorization": f"Bearer {self.get_token()}", "User-Agent": "lexmachina-python-client-0.0.2"} - url = f"{url}/{path}" - try: - with session.post( - url, headers=headers, json=data - ) as response: - return response.json() - except JSONDecodeError: - return response.text diff --git a/src/lexmachina/v1/_sync/client.py b/src/lexmachina/v1/_sync/client.py deleted file mode 100644 index 7d1b158..0000000 --- a/src/lexmachina/v1/_sync/client.py +++ /dev/null @@ -1,196 +0,0 @@ -from typing import List -import configparser - -from .base_request import BaseRequest -from .query_cases import QueryCase - - -class LexMachinaClient(BaseRequest): - def __init__(self, config_file_path=None, client_id=None, client_secret=None): - super().__init__(config_file_path, client_id, client_secret) - - if config_file_path: - config = configparser.ConfigParser() - config.read(config_file_path) - client_id = config['CREDENTIALS']['client_id'] - client_secret = config['CREDENTIALS']['client_secret'] - - self._config_file_path = config_file_path - self._client_id = client_id - self._client_secret = client_secret - self.query = QueryCase(config=self._config_file_path) - - def get_district_cases(self, cases: int) -> dict: - """ - - :param cases: int of a case ID - :return: JSON case structure - """ - return self._get(path='district-cases', args=cases) - - def get_appeals_cases(self, cases: int) -> dict: - return self._get(path='appeals-cases', args=cases) - - def get_state_cases(self, cases: int) -> dict: - return self._get(path="state-cases", args=cases) - - def query_state_cases(self, query, options=None, page_size=100): - return self.query.query_case(query=query, options=options, page_size=page_size, endpoint='state-cases') - - def query_district_case(self, query, options=None, page_size=100): - return self.query.query_case(query=query, options=options, page_size=page_size, endpoint='district-cases') - - def query_appeals_case(self, query, options=None, page_size=100): - return self.query.query_case(query=query, options=options, page_size=page_size, endpoint='appeals-cases') - - def get_parties(self, parties: List[str]) -> dict: - """ - - :param parties: provide a single value or a list of values - :return: JSON string with a name and partyID - """ - if isinstance(parties, list): - response = self._get(path='parties', params={"partyIds": parties}) - else: - response = self._get(path='parties', args=parties) - return response - - def search_parties(self, q: str, page_number: int = 1, page_size: int = 500) -> dict: - """ - - :param q: search string - :param page_number: what page number to return - :param page_size: how many results to return per page - :return: JSON - """ - return self._get(path='search-parties', params={"q": q, - "pageNumber": page_number, - "pageSize": page_size}) - - def get_attorneys(self, attorneys: List[int]): - """ - :param attorneys: provide a single value or a list of values - :return: JSON string with a name and partyID - """ - if isinstance(attorneys, list): - response = self._get(path='attorneys', params={"attorneyIds": attorneys}) - else: - response = self._get(path='attorneys', args=attorneys) - return response - - def search_attorneys(self, q: str, page_number: int = 1, page_size: int = 500) -> dict: - """ - :param q: search string - :param page_number: what page number to return - :param page_size: how many results to return per page - :return: JSON - """ - return self._get(path='search-attorneys', params={"q": q, - "pageNumber": page_number, - "pageSize": page_size}) - - def get_law_firms(self, law_firms: list[int]) -> dict: - """ - :param law_firms: provide a single value or a list of values - :return: JSON string with a name and partyID - """ - if isinstance(law_firms, list): - response = self._get(path='law-firms', params={"lawFirmIds": law_firms}) - else: - response = self._get(path='law-firms', args=law_firms) - return response - - def search_law_firms(self, q: str, page_number: int = 1, page_size: int = 500) -> dict: - """ - :param q: search string - :param page_number: what page number to return - :param page_size: how many results to return per page - :return: JSON - """ - return self._get(path='search-law-firms', params={"q": q, - "pageNumber": page_number, - "pageSize": page_size}) - - def get_federal_judges(self, federal_judges: List[int]) -> dict: - """ - :param federal_judges: provide a single value or a list of values - :return: JSON string - """ - if isinstance(federal_judges, list): - response = self._get(path='federal-judges', params={"federalJudgeIds": federal_judges}) - else: - response = self._get(path='federal-judges', args=federal_judges) - return response - - def get_state_judges(self, state_judges: List[int]) -> dict: - """ - :param state_judges: provide a single value or a list of values - :return: JSON string - """ - if isinstance(state_judges, list): - response = self._get(path='state-judges', params={"stateJudgeIds": state_judges}) - else: - response = self._get(path='state-judges', args=state_judges) - return response - - def get_magistrate_judges(self, magistrate_judges: str) -> dict: - return self._get(path='magistrate-judges', args=magistrate_judges) - - def search_judges(self, q: str) -> dict: - return self._get(path='search-judges', params={"q": q}) - - def get_patents(self, patents: List[str]) -> dict: - """ - :param patents: provide a single value or a list of values - :return: JSON - """ - if isinstance(patents, list): - response = self._get(path='patents', params={"patentNumbers": patents}) - else: - response = self._get(path='patents', args=patents) - return response - - def list_case_resolutions(self, court_type) -> dict: - return self._list(path=f'list-case-resolutions/{court_type}') - - def list_case_tags(self, court_type) -> dict: - return self._list(path=f'list-case-tags/{court_type}') - - def list_case_types(self, court_type) -> dict: - return self._list(path=f'list-case-types/{court_type}') - - def list_courts(self, court_type) -> dict: - return self._list(path=f'list-courts/{court_type}') - - def list_damages_federal_district(self) -> dict: - return self._list(path='list-damages/FederalDistrict') - - def list_damages_state(self) -> dict: - return self._list(path='list-damages/State') - - def list_events(self, court_type) -> dict: - return self._list(path=f'list-events/{court_type}') - - def list_federal_district_judgment_sources(self) -> dict: - return self._list(path='list-judgment-sources/FederalDistrict') - - def list_state_judgment_events(self) -> dict: - return self._list(path='list-judgment-events/State') - - def list_originating_venues_federal(self): - return self._list(path='list-originating-venues/FederalAppeals') - - def list_appellate_decisions_federal(self): - return self._list(path='list-appellate-decisions/FederalDistrict') - - def list_supreme_court_decisions_federal(self): - return self._list(path='list-supreme-court-decisions/FederalAppeals') - - def _list(self, path) -> dict: - return self._get(path=path) - - def health(self) -> str: - return self._get(path="health") - - def open_api(self) -> dict: - return self._get(path="openapi.json") \ No newline at end of file diff --git a/src/lexmachina/v1/_sync/query_cases.py b/src/lexmachina/v1/_sync/query_cases.py deleted file mode 100644 index 98b2978..0000000 --- a/src/lexmachina/v1/_sync/query_cases.py +++ /dev/null @@ -1,39 +0,0 @@ -from .base_request import BaseRequest - - -class QueryCase: - def __init__(self, config=None): - self.case_query = BaseRequest(config) - - def query_one_page(self, query, endpoint): - if endpoint == 'district-cases': - response = self.case_query._post(path="query-district-cases", data=query) - elif endpoint == 'state-cases': - response = self.case_query._post(path="query-state-cases", data=query) - elif endpoint == 'appeals-cases': - response = self.case_query._post(path="query-appeals-cases", data=query) - if response: - return response.get("cases") - return [] - - def query_all_pages(self, query, endpoint, page_size): - cases = [] - if page_size > 100: - raise ValueError("Page size must be <= 100") - query.set_page_size(page_size) - query_results = query.execute() - while True: - page_cases = self.query_one_page(query_results, endpoint) - if page_cases: - cases.extend(page_cases) - query.next_page() - if not page_cases: - break - return cases - - def query_case(self, query, endpoint, options, page_size): - query_results = query.execute() - if options and options['pageThrough']: - return self.query_all_pages(query, endpoint, page_size) - else: - return self.query_one_page(query_results, endpoint) diff --git a/src/lexmachina/v1/query/__init__.py b/src/lexmachina/v1/query/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/lexmachina/v1/query/appeals_casequery.py b/src/lexmachina/v1/query/appeals_casequery.py deleted file mode 100644 index d8dc797..0000000 --- a/src/lexmachina/v1/query/appeals_casequery.py +++ /dev/null @@ -1,488 +0,0 @@ -from datetime import datetime - - -def empty(x): - return x is None or x == {} or x == [] or x == '' - -class AppealsCaseQueryRequest: - - def __init__(self): - self._query_template = { - "courts": { - "include": [ - ], - "exclude": [ - ] - }, - "caseStatus": "", - "caseTags": { - "include": [ - ], - "exclude": [ - ] - }, - "dates": { - "filed": { - "onOrAfter": "", - "onOrBefore": "" - }, - "terminated": { - "onOrAfter": "", - "onOrBefore": "" - }, - "lastDocket": { - "onOrAfter": "", - "onOrBefore": "" - } - }, - "judges": { - "include": [ - ], - "exclude": [ - ] - }, - "lawFirms": { - "include": [ - ], - "exclude": [ - ], - "includeAppellant": [ - ], - "excludeAppellant": [ - ], - "includeAppellee": [ - ], - "excludeAppellee": [ - ], - "includeRespondent": [ - ], - "excludeRespondent": [ - ], - "includeThirdParty": [ - ], - "excludeThirdParty": [ - ], - "includePetitionerMovant": [ - ], - "excludePetitionerMovant": [ - ] - }, - "attorneys": { - "include": [ - ], - "exclude": [ - ], - "includeAppellant": [ - ], - "excludeAppellant": [ - ], - "includeAppellee": [ - ], - "excludeAppellee": [ - ], - "includeRespondent": [ - ], - "excludeRespondent": [ - ], - "includeThirdParty": [ - ], - "excludeThirdParty": [ - ], - "includePetitionerMovant": [ - ], - "excludePetitionerMovant": [ - ] - }, - "parties": { - "include": [ - ], - "exclude": [ - ], - "includeAppellant": [ - ], - "excludeAppellant": [ - ], - "includeAppellee": [ - ], - "excludeAppellee": [ - ], - "includeRespondent": [ - ], - "excludeRespondent": [ - ], - "includeThirdParty": [ - ], - "excludeThirdParty": [ - ], - "includePetitionerMovant": [ - ], - "excludePetitionerMovant": [ - ] - }, - "originatingVenues": { - "include": [ - ], - "exclude": [ - ] - }, - "originatingCases": { - "includeDistrictCaseIds": [ - ], - "excludeDistrictCaseIds": [ - ], - "includeOriginatingJudges": { - "districtFederalJudges": { - "include": [ - ], - "exclude": [ - ] - } - }, - "originatingDistrictCaseCriteria": { - "courts": { - "include": [ - ], - "exclude": [ - ] - }, - "caseTypes": { - "include": [ - ], - "exclude": [ - ] - } - } - }, - "resolutions": { - "include": [ - ], - "exclude": [ - ] - }, - "supremeCourtDecisions": { - "include": [ - ], - "exclude": [ - ] - }, - "ordering": "ByFirstFiled", - "page": 1, - "pageSize": 5 - } - - def _remove_empty_elements(self, data): - if not isinstance(data, dict) and not isinstance(data, list): - return data - elif isinstance(data, list): - return [v for v in (self._remove_empty_elements(v) for v in data) if not empty(v)] - else: - return {k: v for k, v in ((k, self._remove_empty_elements(v)) for k, v in data.items()) if not empty(v)} - - def validate_date(self, date): - try: - datetime.fromisoformat(date) - except ValueError: - raise ValueError("Incorrect date format, dates should be 'YYYY-MM-DD'") - return True - - def set_date(self, date, field, operator): - ''' - - :param date: provide a date in iso format: 2023-01-01 - :param field: examples include 'onOrAfter', 'onOrBefore, - :param operator: choose from 'filed', 'terminated', 'trial', 'lastDocket' - :return: - ''' - valid_date = self.validate_date(date) - if isinstance(field, str): - new_field = self._query_template['dates'][field] - if valid_date: - new_field[operator] = date - else: - new_field = field - if valid_date: - new_field[operator] = date - - return self - - def set_page(self, page): - self._query_template['page'] = page - return self - - def next_page(self): - self._query_template['page'] += 1 - return self - - def set_page_size(self, size): - self._query_template['pageSize'] = size - return self - - def get_page(self): - return self._query_template['page'] - - def include_courts(self, *args): - """ - :param args: include an arbitrary number of court ids - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['courts']['include'].append(value) for value in args] - return self - - def exclude_courts(self, *args): - ''' - :param args: exclude an arbitrary number of court ids - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['courts']['exclude'].append(value) for value in args] - return self - - def include_resolutions(self, summary, specific): - """ - :param summary: Include a resolution summary - :param specific: Include specific resolution info - These can be found with the '/list-case-resolutions endpoint. - This function can be chained with other functions - :return: CaseQueryRequest object - """ - resolution = {"summary": summary, "specific": specific} - self._query_template['resolutions']['include'].append(resolution) - return self - - def exclude_resolutions(self, summary, specific): - """ - :param summary: Exclude a resolution summary - :param specific: Exclude specific resolution info - These can be found with the '/list-case-resolutions endpoint. - This function can be chained with other functions - :return: CaseQueryRequest object - """ - resolution = {"summary": summary, "specific": specific} - self._query_template['resolutions']['exclude'].append(resolution) - return self - - def include_judges(self, *args): - ''' - :param args: include an arbitrary number of judge ids - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['judges']['include'].append(value) for value in args] - return self - - def exclude_judges(self, *args): - ''' - :param args: exclude an arbitrary number of judge ids - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['judges']['exclude'].append(value) for value in args] - return self - - - def include_law_firms(self, *args): - ''' - :param args: include an arbitrary number of lawfirm ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['include'].append(value) for value in args] - - return self - - def exclude_law_firms(self, *args): - ''' - :param args: exclude an arbitrary number of lawfirm ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['exclude'].append(value) for value in args] - return self - - def lawfirms_include_plaintiffs(self, *args): - ''' - :param args: include an arbitrary number of plaintiff ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['includePlaintiff'].append(value) for value in args] - return self - - def lawfirms_exclude_plaintiffs(self, *args): - ''' - :param args: exclude an arbitrary number of plaintiff ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['excludePlaintiff'].append(value) for value in args] - return self - - def lawfirms_include_defendant(self, *args): - ''' - :param args: include an arbitrary number of defendant ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['includeDefendant'].append(value) for value in args] - return self - - def lawfirms_exclude_defendant(self, *args): - ''' - :param args: exclude an arbitrary number of defendant ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawfirms']['excludeDefendant'].append(value) for value in args] - return self - - def lawfirms_include_third_party(self, *args): - ''' - :param args: include an arbitrary number of third party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['includeThirdParty'].append(value) for value in args] - return self - - def lawfirms_exclude_third_party(self, *args): - ''' - :param args: exclude an arbitrary number of third party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['excludeThirdParty'].append(value) for value in args] - return self - - def include_parties(self, *args): - ''' - :param args: include an arbitrary number of party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['include'].append(value) for value in args] - return self - - def exclude_parties(self, *args): - ''' - :param args: exclude an arbitrary number of party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['exclude'].append(value) for value in args] - return self - - def parties_include_plaintiff(self, *args): - ''' - :param args: include an arbitrary number of plaintiff party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['includePlaintiff'].append(value) for value in args] - return self - - def parties_exclude_plaintiff(self, *args): - ''' - :param args: exclude an arbitrary number of plaintiff party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - - [self._query_template['parties']['excludePlaintiff'].append(value) for value in set(args)] - return self - - def parties_include_defendant(self, *args): - ''' - :param args: include an arbitrary number of defendant party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['includeDefendant'].append(value) for value in args] - return self - - def parties_exclude_defendant(self, *args): - ''' - :param args: exclude an arbitrary number of defendant party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['excludeDefendant'].append(value) for value in args] - return self - - def parties_include_third_party(self, *args): - """ - :param args: include an arbitrary number of third-party party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['parties']['includeThirdParty'].append(value) for value in args] - return self - - def parties_exclude_third_party(self, *args): - """ - :param args: exclude an arbitrary number of third-party party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - - [self._query_template['parties']['excludeThirdParty'].append(value) for value in args] - return self - - def parties_include_petitioner_movant(self, *args): - [self._query_template['parties']['includePetitionerMovant'].append(value) for value in args] - return self - - - def parties_exclude_petitioner_movant(self, *args): - [self._query_template['parties']['excludePetitionerMovant'].append(value) for value in args] - return self - - def include_originating_venues(self, *args): - [self._query_template['originatingVenues']['include'].append(value) for value in args] - return self - - def exclude_originating_venues(self, *args): - [self._query_template['originatingVenues']['exclude'].append(value) for value in args] - return self - - def include_originating_cases(self, *args): - [self._query_template['originatingCases']['includeDistrictCaseIds'].append(value) for value in args] - return self - - def exclude_originating_cases(self, *args): - [self._query_template['originatingCases']['excludeDistrictCaseIds'].append(value) for value in args] - return self - - def include_originating_judges(self, *args): - [self._query_template['originatingCases']['includeOriginatingJudges']['districtFederalJudges']['include'].append( - value) for value in args] - return self - - def exclude_originating_judges(self, *args): - [self._query_template['originatingCases']['includeOriginatingJudges']['districtFederalJudges']['exclude'].append( - value) for value in args] - return self - - def include_originating_district_case_courts(self, *args): - [self._query_template['originatingCases']['originatingDistrictCaseCriteria']['courts']['include'].append(value) for - value in args] - return self - - def exclude_originating_district_case_courts(self, *args): - [self._query_template['originatingCases']['originatingDistrictCaseCriteria']['courts']['exclude'].append(value) for - value in args] - return self - - def include_originating_district_case_types(self, *args): - [self._query_template['originatingCases']['originatingDistrictCaseCriteria']['caseTypes']['include'].append(value) for - value in args] - return self - - def exclude_originating_district_case_types(self, *args): - [self._query_template['originatingCases']['originatingDistrictCaseCriteria']['caseTypes']['exclude'].append(value) for - value in args] - return self - - def execute(self): - self._query_template = self._remove_empty_elements(self._query_template) - return self._query_template \ No newline at end of file diff --git a/src/lexmachina/v1/query/district_casequery.py b/src/lexmachina/v1/query/district_casequery.py deleted file mode 100644 index bdee166..0000000 --- a/src/lexmachina/v1/query/district_casequery.py +++ /dev/null @@ -1,496 +0,0 @@ -from datetime import datetime - - -def empty(x): - return x is None or x == {} or x == [] or x == '' - - -class DistrictCaseQueryRequest: - def __init__(self): - self._query_template = { - 'caseStatus': '', - "caseTypes": {"include": [], "exclude": []}, - 'caseTags': {'include': [], 'exclude': []}, - "dates": { - "filed": {"onOrAfter": "", "onOrBefore": ""}, - 'terminated': {'onOrAfter': '', 'onOrBefore': ''}, - 'trial': {'onOrAfter': '', 'onOrBefore': ''}, - 'lastDocket': {'onOrAfter': '', 'onOrBefore': ''} - }, - 'judges': {'include': [], 'exclude': []}, - 'magistrates': {'include': [], 'exclude': []}, - 'events': {'include': [], 'exclude': []}, - 'lawFirms': {'include': [], 'exclude': [], 'includePlaintiff': [], 'excludePlaintiff': [], - 'includeDefendant': [], 'excludeDefendant': [], 'includeThirdParty': [], - 'excludeThirdParty': []}, - 'parties': {'include': [], 'exclude': [], 'includePlaintiff': [], 'excludePlaintiff': [], - 'includeDefendant': [], 'excludeDefendant': [], 'includeThirdParty': [], - 'excludeThirdParty': []}, - 'courts': {'include': [], 'exclude': []}, - 'resolutions': {'include': [], 'exclude': []}, - 'findings': [{'judgmentSource': {'include': [], 'exclude': []}, 'nameType': {'include': [], 'exclude': []}, - 'date': {'onOrAfter': '', 'onOrBefore': ''}, 'awardedToParties': [], - 'awardedAgainstParties': [], 'patentInvalidityReasons': {'include': []}}], - 'remedies': [{'judgmentSource': {'include': [], 'exclude': []}, 'nameType': {'include': [], 'exclude': []}, - 'date': {'onOrAfter': '', 'onOrBefore': ''}, 'awardedToParties': [], - 'awardedAgainstParties': []}], - 'damages': [{'judgmentSource': {'include': [], 'exclude': []}, 'nameType': {'include': [], 'exclude': []}, - 'date': {'onOrAfter': '', 'onOrBefore': ''}, 'awardedToParties': [], - 'awardedAgainstParties': [], 'minimumAmount': ''}], - 'patents': {'include': [], 'exclude': []}, - 'mdl': {'include': [], 'exclude': []}, - 'ordering': 'ByFirstFiled', - 'page': 1, - 'pageSize': 5 - } - - def _remove_empty_elements(self, data): - if not isinstance(data, dict) and not isinstance(data, list): - return data - elif isinstance(data, list): - return [v for v in (self._remove_empty_elements(v) for v in data) if not empty(v)] - else: - return {k: v for k, v in ((k, self._remove_empty_elements(v)) for k, v in data.items()) if not empty(v)} - - def validate_date(self, date): - try: - datetime.fromisoformat(date) - except ValueError: - raise ValueError("Incorrect date format, dates should be 'YYYY-MM-DD'") - return True - - def set_date(self, date, field, operator): - ''' - - :param date: provide a date in iso format: 2023-01-01 - :param field: examples include 'onOrAfter', 'onOrBefore, - :param operator: choose from 'filed', 'terminated', 'trial', 'lastDocket' - :return: - ''' - valid_date = self.validate_date(date) - if isinstance(field, str): - new_field = self._query_template['dates'][field] - if valid_date: - new_field[operator] = date - else: - new_field = field - if valid_date: - new_field[operator] = date - - return self - - def set_page(self, page): - self._query_template['page'] = page - return self - - def next_page(self): - self._query_template['page'] += 1 - return self - - def set_page_size(self, size): - self._query_template['pageSize'] = size - return self - - def get_page(self): - return self._query_template['page'] - - def include_case_types(self, *args): - ''' - :param args: include an arbitrary number of case types - list of case types can be found using the /list-case-types endpoint. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['caseTypes']['include'].append(value) for value in args] - return self - - def exclude_case_types(self, *args): - ''' - :param args: exclude an arbitrary number of case types - list of case types can be found using the /list-case-types endpoint. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['caseTypes']['exclude'].append(value) for value in args] - return self - - def include_case_tags(self, *args): - ''' - :param args: include an arbitrary number of case tags - list of case tags can be found using the /list-case-tags endpoint. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['caseTags']['include'].append(value) for value in args] - return self - - def exclude_case_tags(self, *args): - ''' - :param args: exclude an arbitrary number of case tags - list of case tags can be found using the /list-case-tags endpoint. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['caseTags']['exclude'].append(value) for value in args] - return self - - def include_judges(self, *args): - ''' - :param args: include an arbitrary number of judge ids - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['judges']['include'].append(value) for value in args] - return self - - def exclude_judges(self, *args): - ''' - :param args: exclude an arbitrary number of judge ids - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['judges']['exclude'].append(value) for value in args] - return self - - def include_courts(self, *args): - """ - :param args: include an arbitrary number of court ids - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['courts']['include'].append(value) for value in args] - return self - - def exclude_courts(self, *args): - """ - :param args: exclude an arbitrary number of court ids - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['courts']['exclude'].append(value) for value in args] - return self - - def include_magistrates(self, *args): - ''' - :param args: include an arbitrary number of magistrate ids - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['magistrates']['include'].append(value) for value in args] - return self - - def exclude_magistrates(self, *args): - ''' - :param args: exclude an arbitrary number of magistrate ids - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['magistrates']['exclude'].append(value) for value in args] - return self - - def include_event_types(self, *args): - ''' - :param args: include an arbitrary number of event types. - These types can be found with the '/list-events' endpoint - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['events']['include'].append(value) for value in args] - return self - - def exclude_event_types(self, *args): - ''' - :param args: exclude an arbitrary number of event types. - These types can be found with the '/list-events' endpoint - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['events']['exclude'].append(value) for value in args] - return self - - def include_law_firms(self, *args): - ''' - :param args: include an arbitrary number of lawfirm ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['include'].append(value) for value in args] - - return self - - def exclude_law_firms(self, *args): - ''' - :param args: exclude an arbitrary number of lawfirm ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['exclude'].append(value) for value in args] - return self - - def lawfirms_include_plaintiffs(self, *args): - ''' - :param args: include an arbitrary number of plaintiff ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['includePlaintiff'].append(value) for value in args] - return self - - def lawfirms_exclude_plaintiffs(self, *args): - ''' - :param args: exclude an arbitrary number of plaintiff ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['excludePlaintiff'].append(value) for value in args] - return self - - def lawfirms_include_defendant(self, *args): - ''' - :param args: include an arbitrary number of defendant ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['includeDefendant'].append(value) for value in args] - return self - - def lawfirms_exclude_defendant(self, *args): - ''' - :param args: exclude an arbitrary number of defendant ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawfirms']['excludeDefendant'].append(value) for value in args] - return self - - def lawfirms_include_third_party(self, *args): - ''' - :param args: include an arbitrary number of third party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['includeThirdParty'].append(value) for value in args] - return self - - def lawfirms_exclude_third_party(self, *args): - ''' - :param args: exclude an arbitrary number of third party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['excludeThirdParty'].append(value) for value in args] - return self - - def include_parties(self, *args): - ''' - :param args: include an arbitrary number of party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['include'].append(value) for value in args] - return self - - def exclude_parties(self, *args): - ''' - :param args: exclude an arbitrary number of party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['exclude'].append(value) for value in args] - return self - - def parties_include_plaintiff(self, *args): - ''' - :param args: include an arbitrary number of plaintiff party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['includePlaintiff'].append(value) for value in args] - return self - - def parties_exclude_plaintiff(self, *args): - ''' - :param args: exclude an arbitrary number of plaintiff party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - - [self._query_template['parties']['excludePlaintiff'].append(value) for value in set(args)] - return self - - def parties_include_defendant(self, *args): - ''' - :param args: include an arbitrary number of defendant party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['includeDefendant'].append(value) for value in args] - return self - - def parties_exclude_defendant(self, *args): - ''' - :param args: exclude an arbitrary number of defendant party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['excludeDefendant'].append(value) for value in args] - return self - - def parties_include_third_party(self, *args): - """ - :param args: include an arbitrary number of third-party party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['parties']['includeThirdParty'].append(value) for value in args] - return self - - def parties_exclude_third_party(self, *args): - """ - :param args: exclude an arbitrary number of third-party party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - - [self._query_template['parties']['excludeThirdParty'].append(value) for value in args] - return self - - def include_resolutions(self, summary, specific): - """ - :param summary: Include a resolution summary - :param specific: Include specific resolution info - These can be found with the '/list-case-resolutions endpoint. - This function can be chained with other functions - :return: CaseQueryRequest object - """ - resolution = {"summary": summary, "specific": specific} - self._query_template['resolutions']['include'].append(resolution) - return self - - def exclude_resolutions(self, summary, specific): - """ - :param summary: Exclude a resolution summary - :param specific: Exclude specific resolution info - These can be found with the '/list-case-resolutions endpoint. - This function can be chained with other functions - :return: CaseQueryRequest object - """ - resolution = {"summary": summary, "specific": specific} - self._query_template['resolutions']['exclude'].append(resolution) - return self - - def findings_include_awarded_to_parties(self, *args): - """ - :param args: include an arbitrary number of party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['findings'][0]['awardedToParties'].append(value) for value in args] - return self - - def findings_includes_awarded_against_parties(self, *args): - """ - :param args: exclude an arbitrary number of party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['findings'][0]['awardedAgainstParties'].append(value) for value in args] - return self - - def findings_include_judgment_source(self, *args): - """ - :param args: include an arbitrary number of judgment source ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['findings'][0]['judgmentSource']['include'].append(value) for value in args] - return self - - def findings_exclude_judgment_source(self, *args): - """ - :param args: exclude an arbitrary number of third-party party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['findings'][0]['judgmentSource']['exclude'].append(value) for value in args] - return self - - def findings_include_patent_invalidity_reasons(self, *args): - [self._query_template['findings'][0]['patentInvalidityReasons']['include'].append(value) for value in args] - return self - - def include_remedies_awarded_to_parties(self, *args): - [self._query_template['remedies'][0]['awardedToParties'].append(value) for value in args] - return self - - def include_remedies_awarded_against_parties(self, *args): - [self._query_template['remedies'][0]['awardedAgainstParties'].append(value) for value in args] - return self - - def include_remedies_judgment_source(self, *args): - [self._query_template['remedies'][0]['judgmentSource']['include'].append(value) for value in args] - return self - - def exclude_remedies_judgment_source(self, *args): - [self._query_template['remedies'][0]['judgmentSource']['exclude'].append(value) for value in args] - return self - - def include_remedies_name_type(self, name, type): - name_type = {'name': name, 'type': type} - self._query_template['remedies'][0]['nameType']['include'].append(name_type) - return self - - def exclude_remedies_name_type(self, name, type): - name_type = {'name': name, 'type': type} - self._query_template['remedies'][0]['nameType']['exclude'].append(name_type) - return self - - def add_remedies_date(self, date, operator): - """ - :param date: date in format YYYY-MM-DD - :param operator: options are onOrBefore or onOrAfter. Choose to set date to either value. - :return: CaseQueryRequest - """ - self.set_date(date, self._query_template['remedies'][0]['date'], operator) - return self - - def set_damages_minimum_amount(self, amount): - """ - :param amount: provide a minimum amount of damages. - This function can be chained with other functions - :return: CaseQueryRequest - """ - if amount <= 0 or isinstance(amount, str): - raise ValueError("Damages amount must be a number greater than 0") - self._query_template['damages'][0]['minimumAmount'] = amount - return self - - def include_patents(self, *args): - """ - :param args: include an arbitrary number of patent ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['patents']['include'].append(value) for value in args] - return self - - def exclude_patents(self, *args): - """ - :param args: exclude an arbitrary number of patent ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['patents']['exclude'].append(value) for value in args] - return self - - def include_mdl(self, *args): - [self._query_template['mdl']['include'].append(value) for value in args] - return self - - def exclude_mdl(self, *args): - [self._query_template['mdl']['exclude'].append(value) for value in args] - return self - - def execute(self): - self._query_template = self._remove_empty_elements(self._query_template) - return self._query_template diff --git a/src/lexmachina/v1/query/state_casequery.py b/src/lexmachina/v1/query/state_casequery.py deleted file mode 100644 index d02fc59..0000000 --- a/src/lexmachina/v1/query/state_casequery.py +++ /dev/null @@ -1,495 +0,0 @@ -from datetime import datetime - - -def empty(x): - return x is None or x == {} or x == [] or x == '' - - -class StateCaseQueryRequest: - def __init__(self): - self._query_template = { - "courts": { "state": "" , "include": [], "exclude": []}, - "caseStatus": "", - "caseTypes": { "include": [],"exclude": [] }, - "caseTags": { "include": [], "exclude": [] }, - "dates": { - "filed": { "onOrAfter": "", "onOrBefore": "" }, - "terminated": { "onOrAfter": "", "onOrBefore": "" }, - "trial": { "onOrAfter": "", "onOrBefore": "" }, - "lastDocket": { "onOrAfter": "", "onOrBefore": "" } - }, - "judges": { "include": [], "exclude": [] }, - "events": { "include": [], "exclude": [] }, - "lawFirms": { - "include": [],"exclude": [], "includePlaintiff": [], "excludePlaintiff": [], "includeDefendant": [], "excludeDefendant": [], "includeThirdParty": [], "excludeThirdParty": [] - }, - "attorneys": { "include": [], "exclude": [], "includePlaintiff": [], "excludePlaintiff": [], "includeDefendant": [], "excludeDefendant": [], "includeThirdParty": [], "excludeThirdParty": [] }, - "parties": { "include": [], "exclude": [], "includePlaintiff": [], "excludePlaintiff": [], "includeDefendant": [], "excludeDefendant": [], "includeThirdParty": [], "excludeThirdParty": [] }, - "resolutions": { "include": [ { "summary": "", "specific": "" } ], "exclude": [ { "summary": "", "specific": "" } ] }, - "damages": [ { - "judgmentSource": { "include": [], "exclude": [] }, - "name": { "include": [], "exclude": [] }, - "date": { "onOrAfter": "", "onOrBefore": "" }, "awardedToParties": [], "awardedAgainstParties": [], "minimumAmount": ""} ], - "rulings": [ { - "judgmentEvent": { "include": [], "exclude": [] }, "awardedToParties": [], "awardedAgainstParties": [], - "date": { "onOrAfter": "", "onOrBefore": "" } } ], - "ordering": "ByFirstFiled", - "page": 1, - "pageSize": 5 - } - - def _remove_empty_elements(self, data): - if not isinstance(data, dict) and not isinstance(data, list): - return data - elif isinstance(data, list): - return [v for v in (self._remove_empty_elements(v) for v in data) if not empty(v)] - else: - return {k: v for k, v in ((k, self._remove_empty_elements(v)) for k, v in data.items()) if not empty(v)} - - def validate_date(self, date): - try: - datetime.fromisoformat(date) - except ValueError: - raise ValueError("Incorrect date format, dates should be 'YYYY-MM-DD'") - return True - - - def set_terminated_date(self, date, operator='terminated'): - self.set_date(date, self._query_template['dates']['terminated'], operator) - return self - - def set_case_status(self, status): - self._query_template['caseStatus'] = status - return self - - def set_date(self, date, field, operator): - ''' - - :param date: provide a date in iso format: 2023-01-01 - :param field: examples include 'onOrAfter', 'onOrBefore, - :param operator: choose from 'filed', 'terminated', 'trial', 'lastDocket' - :return: - ''' - valid_date = self.validate_date(date) - if isinstance(field, str): - new_field = self._query_template['dates'][field] - if valid_date: - new_field[operator] = date - else: - new_field = field - if valid_date: - new_field[operator] = date - - return self - - def set_page(self, page): - self._query_template['page'] = page - return self - - def next_page(self): - self._query_template['page'] += 1 - return self - - def set_page_size(self, size): - self._query_template['pageSize'] = size - return self - - def get_page(self): - return self._query_template['page'] - - def include_case_types(self, *args): - ''' - :param args: include an arbitrary number of case types - list of case types can be found using the /list-case-types endpoint. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['caseTypes']['include'].append(value) for value in args] - return self - - def exclude_case_types(self, *args): - ''' - :param args: exclude an arbitrary number of case types - list of case types can be found using the /list-case-types endpoint. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['caseTypes']['exclude'].append(value) for value in args] - return self - - def include_case_tags(self, *args): - ''' - :param args: include an arbitrary number of case tags - list of case tags can be found using the /list-case-tags endpoint. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['caseTags']['include'].append(value) for value in args] - return self - - def exclude_case_tags(self, *args): - ''' - :param args: exclude an arbitrary number of case tags - list of case tags can be found using the /list-case-tags endpoint. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['caseTags']['exclude'].append(value) for value in args] - return self - - def include_judges(self, *args): - ''' - :param args: include an arbitrary number of judge ids - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['judges']['include'].append(value) for value in args] - return self - - def exclude_judges(self, *args): - ''' - :param args: exclude an arbitrary number of judge ids - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['judges']['exclude'].append(value) for value in args] - return self - - def include_courts(self, *args): - ''' - :param args: include an arbitrary number of court ids - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['courts']['include'].append(value) for value in args] - return self - - def include_state(self, state): - self._query_template['courts'].update({"state": state}) - return self - - def exclude_courts(self, *args): - ''' - :param args: exclude an arbitrary number of court ids - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['courts']['exclude'].append(value) for value in args] - return self - - def include_magistrates(self, *args): - ''' - :param args: include an arbitrary number of magistrate ids - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['magistrates']['include'].append(value) for value in args] - return self - - def exclude_magistrates(self, *args): - ''' - :param args: exclude an arbitrary number of magistrate ids - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['magistrates']['exclude'].append(value) for value in args] - return self - - def include_event_types(self, *args): - ''' - :param args: include an arbitrary number of event types. - These types can be found with the '/list-events' endpoint - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['events']['include'].append(value) for value in args] - return self - - def exclude_event_types(self, *args): - ''' - :param args: exclude an arbitrary number of event types. - These types can be found with the '/list-events' endpoint - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['events']['exclude'].append(value) for value in args] - return self - - def include_law_firms(self, *args): - ''' - :param args: include an arbitrary number of lawfirm ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['include'].append(value) for value in args] - - return self - - def exclude_law_firms(self, *args): - ''' - :param args: exclude an arbitrary number of lawfirm ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['exclude'].append(value) for value in args] - return self - - def lawfirms_include_plaintiffs(self, *args): - ''' - :param args: include an arbitrary number of plaintiff ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['includePlaintiff'].append(value) for value in args] - return self - - def lawfirms_exclude_plaintiffs(self, *args): - ''' - :param args: exclude an arbitrary number of plaintiff ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['excludePlaintiff'].append(value) for value in args] - return self - - def lawfirms_include_defendant(self, *args): - ''' - :param args: include an arbitrary number of defendant ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['includeDefendant'].append(value) for value in args] - return self - - def lawfirms_exclude_defendant(self, *args): - ''' - :param args: exclude an arbitrary number of defendant ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawfirms']['excludeDefendant'].append(value) for value in args] - return self - - def lawfirms_include_third_party(self, *args): - ''' - :param args: include an arbitrary number of third party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['includeThirdParty'].append(value) for value in args] - return self - - def lawfirms_exclude_third_party(self, *args): - ''' - :param args: exclude an arbitrary number of third party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['lawFirms']['excludeThirdParty'].append(value) for value in args] - return self - - def include_parties(self, *args): - ''' - :param args: include an arbitrary number of party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['include'].append(value) for value in args] - return self - - def exclude_parties(self, *args): - ''' - :param args: exclude an arbitrary number of party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['exclude'].append(value) for value in args] - return self - - def parties_include_plaintiff(self, *args): - ''' - :param args: include an arbitrary number of plaintiff party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['includePlaintiff'].append(value) for value in args] - return self - - def parties_exclude_plaintiff(self, *args): - ''' - :param args: exclude an arbitrary number of plaintiff party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - - [self._query_template['parties']['excludePlaintiff'].append(value) for value in args] - return self - - def parties_include_defendant(self, *args): - ''' - :param args: include an arbitrary number of defendant party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['includeDefendant'].append(value) for value in args] - return self - - def parties_exclude_defendant(self, *args): - ''' - :param args: exclude an arbitrary number of defendant party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - ''' - [self._query_template['parties']['excludeDefendant'].append(value) for value in args] - return self - - def parties_include_third_party(self, *args): - """ - :param args: include an arbitrary number of third-party party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['parties']['includeThirdParty'].append(value) for value in args] - return self - - def parties_exclude_third_party(self, *args): - """ - :param args: exclude an arbitrary number of third-party party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - - [self._query_template['parties']['excludeThirdParty'].append(value) for value in args] - return self - - def include_resolutions(self, summary, specific): - """ - :param summary: Include a resolution summary - :param specific: Include specific resolution info - These can be found with the '/list-case-resolutions endpoint. - This function can be chained with other functions - :return: CaseQueryRequest object - """ - resolution = {"summary": summary, "specific": specific} - self._query_template['resolutions']['include'].append(resolution) - return self - - def exclude_resolutions(self, summary, specific): - """ - :param summary: Exclude a resolution summary - :param specific: Exclude specific resolution info - These can be found with the '/list-case-resolutions endpoint. - This function can be chained with other functions - :return: CaseQueryRequest object - """ - resolution = {"summary": summary, "specific": specific} - self._query_template['resolutions']['exclude'].append(resolution) - return self - - def findings_include_awarded_to_parties(self, *args): - """ - :param args: include an arbitrary number of party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['findings'][0]['awardedToParties'].append(value) for value in args] - return self - - def findings_includes_awarded_against_parties(self, *args): - """ - :param args: exclude an arbitrary number of party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['findings'][0]['awardedAgainstParties'].append(value) for value in args] - return self - - def findings_include_judgment_source(self, *args): - """ - :param args: include an arbitrary number of judgment source ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['findings'][0]['judgmentSource']['include'].append(value) for value in args] - return self - - def findings_exclude_judgment_source(self, *args): - """ - :param args: exclude an arbitrary number of third-party party ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['findings'][0]['judgmentSource']['exclude'].append(value) for value in args] - return self - - def findings_include_patent_invalidity_reasons(self, *args): - [self._query_template['findings'][0]['patentInvalidityReasons']['include'].append(value) for value in args] - return self - - def include_remedies_awarded_to_parties(self, *args): - [self._query_template['remedies'][0]['awardedToParties'].append(value) for value in args] - return self - - def include_remedies_awarded_against_parties(self, *args): - [self._query_template['remedies'][0]['awardedAgainstParties'].append(value) for value in args] - return self - - def include_remedies_judgment_source(self, *args): - [self._query_template['remedies'][0]['judgmentSource']['include'].append(value) for value in args] - return self - - def exclude_remedies_judgment_source(self, *args): - [self._query_template['remedies'][0]['judgmentSource']['exclude'].append(value) for value in args] - return self - - def include_remedies_name_type(self, name, type): - name_type = {'name': name, 'type': type} - self._query_template['remedies'][0]['nameType']['include'].append(name_type) - return self - - def exclude_remedies_name_type(self, name, type): - name_type = {'name': name, 'type': type} - self._query_template['remedies'][0]['nameType']['exclude'].append(name_type) - return self - - def add_remedies_date(self, date, operator): - """ - :param date: date in format YYYY-MM-DD - :param operator: options are onOrBefore or onOrAfter. Choose to set date to either value. - :return: CaseQueryRequest - """ - self.set_date(date, self._query_template['remedies'][0]['date'], operator) - return self - - def set_damages_minimum_amount(self, amount): - """ - :param amount: provide a minimum amount of damages. - This function can be chained with other functions - :return: CaseQueryRequest - """ - if amount <= 0 or isinstance(amount, str): - raise ValueError("Damages amount must be a number greater than 0") - self._query_template['damages'][0]['minimumAmount'] = amount - return self - - def include_patents(self, *args): - """ - :param args: include an arbitrary number of patent ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['patents']['include'].append(value) for value in args] - return self - - def exclude_patents(self, *args): - """ - :param args: exclude an arbitrary number of patent ids. - This function can be chained with other functions. - :return: CaseQueryRequest object - """ - [self._query_template['patents']['exclude'].append(value) for value in args] - return self - - def execute(self): - self._query_template = self._remove_empty_elements(self._query_template) - return self._query_template \ No newline at end of file diff --git a/src/lexmachina_README.md b/src/lexmachina_README.md index 3a54fb3..68290dc 100644 --- a/src/lexmachina_README.md +++ b/src/lexmachina_README.md @@ -374,6 +374,11 @@ Authentication schemes defined for the API: - **Type**: Bearer authentication +## v1.x Client + +v1.x of the Python client was deprecated in April 2024. If you are still using a 1.x version, please upgrade to the latest 2.x version. If for some reason you will want to use a deprecated version, the last version can be found [here](https://pypi.org/project/lexmachina-client/1.2.1/). + + ## Contact Send any questions to support@lexmachina.com. \ No newline at end of file