### Get Candidate Summary Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Fetches a summary of a candidate's election information for a specific cycle. Requires 'cid' and 'cycle' parameters. ```python print(CRP.candSummary.get(cid='N00007360',cycle='2014')) ``` -------------------------------- ### Setup and Initialization for CRP API Source: https://context7.com/opensecrets/python-crpapi/llms.txt Import the CRP library and set your API key directly or from an environment variable. All API calls are wrapped in a try-except block to catch CRPApiError. ```python import os from crpapi import CRP, CRPApiError # Option 1: Set key directly CRP.apikey = 'your-api-key-here' # Option 2: Load from environment variable CRP.apikey = os.getenv("OPENSECRETS_API_KEY") # All calls raise CRPApiError on failure try: results = CRP.getLegislators.get(id='NJ04') except CRPApiError as e: print(f"API error: {e}") ``` -------------------------------- ### Setup and Initialization Source: https://context7.com/opensecrets/python-crpapi/llms.txt Import the library and set your API key before making any calls. An API key can be obtained at https://www.opensecrets.org/api/admin/. Optionally, load the key from an environment variable. All calls raise CRPApiError on failure. ```APIDOC ## Setup and Initialization Import the library and set your API key before making any calls. An API key can be obtained at https://www.opensecrets.org/api/admin/. Optionally, load the key from an environment variable. ```python import os from crpapi import CRP, CRPApiError # Option 1: Set key directly CRP.apikey = 'your-api-key-here' # Option 2: Load from environment variable CRP.apikey = os.getenv("OPENSECRETS_API_KEY") # All calls raise CRPApiError on failure try: results = CRP.getLegislators.get(id='NJ04') except CRPApiError as e: print(f"API error: {e}") ``` ``` -------------------------------- ### Get Organizations by Name Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Searches for organizations based on a partial or full name. Returns a list of matching organizations with their names and IDs. ```python print(CRP.getOrgs.get(org='Goog')) ``` -------------------------------- ### Get Candidate Industry Data Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieves a list of industries a candidate has received contributions from, along with the amounts. Requires candidate ID and cycle year. ```python print(CRP.candIndustry.get(cid='N00007360',cycle='2014')) ``` -------------------------------- ### Get Candidate Sector Data Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieves a list of economic sectors a candidate has received contributions from, along with the amounts. Requires candidate ID and cycle year. ```python print(CRP.candSector.get(cid='N00007360',cycle='2014')) ``` -------------------------------- ### Get Candidate Contributions Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieves a list of contributions made to a candidate for a specific cycle. Requires 'cid' and 'cycle' parameters. The output includes a list of organizations and their contribution totals. ```python print(CRP.candContrib.get(cid='N00007360',cycle='2014')) ``` -------------------------------- ### Get Organization Summary Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieves a summary of financial contributions and lobbying activity for a specific organization. Requires the organization's ID and cycle year. ```python print(CRP.orgSummary.get(id='D000022008')) ``` -------------------------------- ### Get Legislators by ID Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieve legislator information using the getLegislators method. Pass the desired legislator ID as an argument. ```python print(CRP.getLegislators.get(id='NJ04')) ``` -------------------------------- ### Get Candidate Industry by Specific Industry Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieves detailed information about a candidate's contributions from a specific industry. Requires candidate ID, cycle year, and industry code. ```python print(CRP.candIndByInd.get(cid='N00007360',cycle='2014',ind='H01')) ``` -------------------------------- ### Fetch Member's Personal Financial Disclosure Profile Source: https://context7.com/opensecrets/python-crpapi/llms.txt Get a legislator's financial disclosure data for a specific year. This includes asset holdings, net worth, and financial transactions, useful for transparency analysis. ```python from crpapi import CRP, CRPApiError CRP.apikey = 'your-api-key-here' # Fetch Dianne Feinstein's 2010 financial disclosure profile = CRP.memPFDprofile.get(cid='N00007364', year='2010') attrs = profile['@attributes'] print(f"Member: {attrs['name']}") print(f"Net worth range: ${int(attrs['net_low']):,} - ${int(attrs['net_high']):,}") print(f"Total assets: {attrs['asset_count']}, Transactions: {attrs['transaction_count']}") # List top assets for asset in profile['assets']['asset'][:3]: a = asset['@attributes'] print(f" Asset: {a['name']} ({a['industry']}) " f"${int(a['holdings_low']):,} - ${int(a['holdings_high']):,}") ``` -------------------------------- ### Get Committee Industry Data Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieves data for a specific industry code and committee. Requires the 'indus' and 'cmte' parameters. The output is a list of dictionaries, each containing committee details. ```python print(CRP.congCmteIndus.get(indus='F10',cmte='HARM')) #[{u'@attributes': {u'cid': u'N00024753', u'pacs': u'9500', u'indivs': u'81800',u'state': u'Colorado', u'member_name': u'Coffman, Mike', u'party': u'R', u'total':u'91300'}}, {u'@attributes': {u'cid': u'N00031244', u'pacs': u'12500', u'indivs': u'36300', u'state': u'Nevada', u'member_name': u'Heck, Joe', u'party': u'R', u'total': u'48800'}}, {u'@attributes': {u'cid': u'N00030962', u'pacs': u'4500', u'indivs': u'40150', u'state': u'Virginia', u'member_name': u'Rigell, Scott',u'party': u'R', u'total': u'44650'}}, {u'@attributes': {u'cid': u'N00025881', u'pacs': u'2000', u'indivs': u'41200', u'state': u'Hawaii', u'member_name': u'Hanabusa, Colleen', u'party': u'D', u'total': u'43200'}}, {u'@attributes': {u'cid':u'N00033591', u'pacs': u'6000', u'indivs': u'37000', u'state': u'California', u'member_name': u'Peters, Scott', u'party': u'D', u'total': u'43000'}}, {u'@attributes': {u'cid': u'N00031005', u'pacs': u'0', u'indivs': u'36050', u'state': u'Missouri', u'member_name': u'Hartzler, Vicky', u'party': u'R', u'total': u'36050'}}, {u'@attributes': {u'cid': u'N00033839', u'pacs': u'10000', u'indivs': u'22650', u'state': u'Texas', u'member_name': u'Veasey, Marc', u'party': u'D', u'total': u'32650'}}, {u'@attributes': {u'cid': u'N00004436', u'pacs': u'7000', u'indivs': u'24550', u'state': u'Minnesota', u'member_name': u'Kline, John', u'party': u'R', u'total': u'31550'}}, {u'@attributes': {u'cid': u'N00030768', u'pacs':u'3000', u'indivs': u'28250', u'state': u'Alabama', u'member_name': u'Roby, Martha', u'party': u'R', u'total': u'31250'}}, {u'@attributes': {u'cid':u'N00029026', u'pacs': u'2000', u'indivs': u'27500', u'state': u'Massachusetts', u'member_name': u'Tsongas, Niki', u'party': u'D', u'total': u'29500'}},{u'@attributes': {u'cid': u'N00032022', u'pacs': u'6500', u'indivs': u'20250', u'state': u'South Dakota', u'member_name': u'Noem, Kristi', u'party': u'R',u'total': u'26750'}}, {u'@attributes': {u'cid': u'N00013770', u'pacs': u'11500', u'indivs': u'13500', u'state': u'Pennsylvania', u'member_name': u'Shuster,Bill', u'party': u'R', u'total': u'25000'}}, {u'@attributes': {u'cid': u'N00008274', u'pacs': u'2000', u'indivs': u'21440', u'state': u'California',u'member_name': u'Sanchez, Loretta', u'party': u'D', u'total': u'23440'}}, {u'@attributes': {u'cid': u'N00013799', u'pacs': u'2000', u'indivs':u'19800', u'state': u'Virginia', u'member_name': u'Forbes, Randy', u'party': u'R', u'total': u'21800'}}, {u'@attributes': {u'cid': u'N00033981', u'pacs':u'4000', u'indivs': u'17750', u'state': u'Arizona', u'member_name': u'Barber, Ron', u'party': u'D', u'total': u'21750'}}, {u'@attributes': {u'cid':u'N00033310', u'pacs': u'10000', u'indivs': u'11350', u'state': u'Ohio', u'member_name': u'Wenstrup, Brad', u'party': u'R', u'total': u'21350'}}, {u'@attributes': {u'cid': u'N00027891', u'pacs': u'5000', u'indivs': u'16000', u'state': u'New York', u'member_name': u'Maffei, Dan', u'party': u'D', u'total':u'21000'}}, {u'@attributes': {u'cid': u'N00029679', u'pacs': u'1000', u'indivs': u'18350', u'state': u'Louisiana', u'member_name': u'Fleming, John',u'party': u'R', u'total': u'19350'}}, {u'@attributes': {u'cid': u'N00029649', u'pacs': u'1000', u'indivs': u'18220', u'state': u'California', u'member_name':u'Speier, Jackie', u'party': u'D', u'total': u'19220'}}, {u'@attributes': {u'cid': u'N00024759', u'pacs': u'8390', u'indivs': u'10750', u'state':u'Alabama', u'member_name': u'Rogers, Mike D', u'party': u'R', u'total': u'19140'}}, {u'@attributes': {u'cid': u'N00033316', u'pacs': u'6000', u'indivs':u'12934', u'state': u'Texas', u'member_name': u'Castro, Joaquin', u'party': u'D', u'total': u'18934'}}, {u'@attributes': {u'cid': u'N00003132', u'pacs':u'2000', u'indivs': u'16600', u'state': u'Tennessee', u'member_name': u'Cooper, Jim', u'party': u'D', u'total': u'18600'}}, {u'@attributes': {u'cid':u'N00025175', u'pacs': u'12000', u'indivs': u'6550', u'state': u'Ohio', u'member_name': u'Turner, Michael R', u'party': u'R', u'total': u'18550'}},{u'@attributes': {u'cid': u'N00029258', u'pacs': u'11000', u'indivs': u'7200', u'state': u'California', u'member_name': u'Hunter, Duncan D', u'party': u'R', u'total': u'18200'}}, {u'@attributes': {u'cid': u'N00034453', u'pacs': u'8000', u'indivs': u'9550', u'state': u'Washington', u'member_name': u'Kilmer, Derek',u'party': u'D', u'total': u'17550'}}, {u'@attributes': {u'cid': u'N00030856', u'pacs': u'2000', u'indivs': u'14885', u'state': u'California', u'member_name':u'Garamendi, John', u'party': u'D', u'total': u'16885'}}, {u'@attributes': {u'cid': u'N00034224', u'pacs': u'1000', u'indivs': u'14850', u'state':u'California', u'member_name': u'Cook, Paul', u'party': u'R', u'total': u'15850'}}, {u'@attributes': {u'cid': u'N00032457', u'pacs': u'4890', u'indivs':u'10350', u'state': u'Georgia', u'member_name': u'Scott, Austin', u'party': u'R', u'total': u'15240'}}, {u'@attributes': {u'cid': u'N00031226', u'pacs':u'7000' ``` -------------------------------- ### Get Member Personal Financial Disclosure Profile Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieves the personal financial disclosure profile for a specific member of Congress for a given year. Requires 'cid' and 'year' parameters. ```python print(CRP.memPFDprofile.get(cid='N00007364',year='2010')) ``` -------------------------------- ### Initialize CRP API with API Key Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Import the CRP module and set your API key. Ensure you have registered for an API key at https://www.opensecrets.org/api/admin/. ```python from crpapi import CRP, CRPApiError CRP.apikey = 'yr-api-key' ``` -------------------------------- ### Initialize CRP API with Environment Variable Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Import the CRP module and set your API key using an environment variable. This is an alternative to hardcoding the API key. ```python import os from crpapi import CRP, CRPApiError CRP.apikey = os.getenv("OPEN_STATES_API_KEY") # Use whatever key you have set in your .bashrc or .zshrc file ``` -------------------------------- ### Fetch Candidate's Fundraising Summary Source: https://context7.com/opensecrets/python-crpapi/llms.txt Retrieve high-level campaign finance figures for a candidate in a given election cycle, including total raised, spent, cash on hand, and debt. ```python from crpapi import CRP, CRPApiError CRP.apikey = 'your-api-key-here' # Fetch Nancy Pelosi's 2014 cycle fundraising summary summary = CRP.candSummary.get(cid='N00007360', cycle='2014') print(f"Candidate: {summary['cand_name']} ({summary['party']}, {summary['state']})") print(f"Total raised: ${float(summary['total']):,.2f}") print(f"Total spent: ${float(summary['spent']):,.2f}") print(f"Cash on hand: ${float(summary['cash_on_hand']):,.2f}") print(f"Debt: ${float(summary['debt']):,.2f}") print(f"Source: {summary['source']}") ``` -------------------------------- ### Fetch Organization Spending Summary (Python) Source: https://context7.com/opensecrets/python-crpapi/llms.txt Retrieves a detailed spending summary for a given organization. Requires the organization's ID. Useful for understanding an organization's political financial activities. ```python summary = CRP.orgSummary.get(id='D000022008') a = summary['@attributes'] print(f"Organization: {a['orgname']} (Cycle: {a['cycle']})") print(f"Total contributions: ${int(a['total']):,}") print(f"Lobbying spend: ${int(a['lobbying']):,}") print(f"Democrats: ${int(a['dems']):,}") print(f"Republicans: ${int(a['repubs']):,}") print(f"PAC contributions: ${int(a['pacs']):,}") print(f"Individual donations: ${int(a['indivs']):,}") print(f"Members invested: {a['mems_invested']}") ``` -------------------------------- ### orgSummary.get Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieves a summary of financial contributions and activities for a specific organization. ```APIDOC ## GET orgSummary ### Description Provides a financial summary for a given organization, including total contributions, amounts given to parties, PACs, candidates, and lobbying expenses for a specified cycle. ### Method GET ### Endpoint /orgSummary ### Parameters #### Query Parameters - **id** (string) - Required - The organization ID (e.g., 'D000022008'). - **cycle** (string) - Optional - The election cycle (e.g., '2014'). ### Response #### Success Response (200) - Returns a dictionary containing attributes such as `orgname`, `total`, `gave_to_party`, `gave_to_pac`, `gave_to_cand`, `lobbying`, `dems`, `repubs`, and `cycle`. ### Response Example { "@attributes": { "gave_to_party": "394046", "gave_to_pac": "215000", "pacs": "381500", "orgname": "Google Inc", "gave_to_cand": "680409", "source": "www.opensecrets.org/orgs/summary.php?id=D000022008", "repubs": "481717", "indivs": "667655", "lobbying": "15800000", "outside": "0", "orgid": "D000022008", "dems": "715598", "mems_invested": "25", "total": "1424019", "soft": "220500", "tot527": "154364", "gave_to_527": "154364", "cycle": "2014" } } ``` -------------------------------- ### Fetch Candidate Contributions by Sector Source: https://context7.com/opensecrets/python-crpapi/llms.txt Retrieves contribution totals for a candidate, grouped by broad economic sectors. Requires candidate ID and cycle. The results can be sorted by total contributions. ```python from crpapi import CRP, CRPApiError CRP.apikey = 'your-api-key-here' # Fetch sector-level contributions to Nancy Pelosi in 2014 sectors = CRP.candSector.get(cid='N00007360', cycle='2014') # Sort by total descending and print top 5 sorted_sectors = sorted(sectors, key=lambda x: int(x['@attributes']['total']), reverse=True) print("Top sectors by contribution:") for sector in sorted_sectors[:5]: a = sector['@attributes'] print(f" {a['sector_name']:<30} ${int(a['total']):>8,}") ``` -------------------------------- ### Fetch Candidate Top Contributors Source: https://context7.com/opensecrets/python-crpapi/llms.txt Retrieves the top contributing organizations for a specific candidate in a given election cycle. Requires setting the API key and providing candidate ID and cycle. ```python from crpapi import CRP, CRPApiError CRP.apikey = 'your-api-key-here' # Fetch top contributors to Nancy Pelosi in 2014 contributors = CRP.candContrib.get(cid='N00007360', cycle='2014') print("Top Contributors:") for contrib in contributors[:5]: attrs = contrib['@attributes'] print(f" {attrs['org_name']}: ${int(attrs['total']):,}") ``` -------------------------------- ### candIndByInd.get Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieves detailed industry information for a candidate within a specific industry and cycle. ```APIDOC ## GET candIndByInd ### Description Retrieves detailed information about a candidate's performance within a specific industry for a given election cycle. Includes total contributions, PACs, individuals, party affiliation, and source URL. ### Method GET ### Endpoint /candIndByInd ### Parameters #### Query Parameters - **cid** (string) - Required - The candidate ID. - **cycle** (string) - Required - The election cycle (e.g., '2014'). - **ind** (string) - Required - The industry code (e.g., 'H01'). ### Response #### Success Response (200) - Returns a dictionary containing details such as `cand_name`, `industry`, `pacs`, `indivs`, `total`, `party`, `state`, and `cycle`. ### Response Example { "origin": "Center for Responsive Politics", "last_updated": "2/18/14", "cand_name": "Pelosi, Nancy", "cid": "N00007360", "industry": "Health Professionals", "pacs": "70500", "rank": "36", "indivs": "4250", "chamber": "H", "state": "California", "source": "https://www.opensecrets.org/industries/recips.php?Ind=H01&cycle=2014&recipdetail=H&Mem=Y&sortorder=U", "party": "D", "total": "74750", "cycle": "2014" } ``` -------------------------------- ### Fetch Candidate Fundraising by Specific Industry Source: https://context7.com/opensecrets/python-crpapi/llms.txt Provides detailed fundraising data for a candidate within a single industry code, including their rank among all candidates in that industry. Requires candidate ID, cycle, and industry code. ```python from crpapi import CRP, CRPApiError CRP.apikey = 'your-api-key-here' # Fetch Nancy Pelosi's Health Professionals (H01) contributions in 2014 data = CRP.candIndByInd.get(cid='N00007360', cycle='2014', ind='H01') print(f"Candidate: {data['cand_name']} ({data['party']}, {data['state']})") print(f"Industry: {data['industry']}") print(f"Total: ${int(data['total']):,} (PACs: ${int(data['pacs']):,}, Individuals: ${int(data['indivs']):,})") print(f"Rank among all candidates in this industry: #{data['rank']}") ``` -------------------------------- ### candSummary.get Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieves a summary of a candidate's election information. Requires the candidate's unique ID (cid) and the election cycle. ```APIDOC ## candSummary.get ### Description Retrieves a summary of a candidate's election information, including their name, party, state, and financial details for a specific election cycle. ### Method GET (simulated) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters - **cid** (string) - Required - The unique identifier for the candidate. - **cycle** (string) - Required - The election cycle (e.g., '2014'). ### Request Example ```python print(CRP.candSummary.get(cid='N00007360',cycle='2014')) ``` ### Response #### Success Response (200) - **origin** (string) - The source of the data. - **next_election** (string) - The year of the next election for the candidate. - **debt** (string) - The amount of debt the candidate has. - **last_updated** (string) - The date the data was last updated. - **cand_name** (string) - The full name of the candidate. - **cid** (string) - The unique identifier for the candidate. - **spent** (string) - The total amount spent by the candidate. - **chamber** (string) - The chamber the candidate is running for (e.g., 'H' for House). - **state** (string) - The state the candidate represents. - **first_elected** (string) - The year the candidate was first elected. - **source** (string) - The URL of the source data. - **party** (string) - The political party of the candidate. - **total** (string) - The total amount of contributions received. - **cash_on_hand** (string) - The amount of cash the candidate has on hand. - **cycle** (string) - The election cycle. #### Response Example ```json { "origin": "Center for Responsive Politics", "next_election": "2014", "debt": "0", "last_updated": "12/31/2013", "cand_name": "Pelosi, Nancy", "cid": "N00007360", "spent": "1304840.24", "chamber": "H", "state": "CA", "first_elected": "1987", "source": "https://www.opensecrets.org/politicians/summary.php?cid=N00007360&cycle=2014", "party": "D", "total": "1294719.87", "cash_on_hand": "439206.96", "cycle": "2014" } ``` ``` -------------------------------- ### CRP.orgSummary.get Source: https://context7.com/opensecrets/python-crpapi/llms.txt Fetch an organization's political spending summary, including total contributions, PAC money, and lobbying spend. ```APIDOC ## CRP.orgSummary.get — Fetch an organization's political spending summary ### Description Returns comprehensive political spending data for an organization: total contributions, PAC money, lobbying spend, individual donations, party breakdown, and more. ### Method GET ### Endpoint `/v2/org_summary` (Assumed based on common API patterns and function name) ### Parameters #### Query Parameters - **id** (string) - Required - Organization ID (obtained from `CRP.getOrgs.get`) - **cycle** (string) - Optional - Election cycle (e.g., '2014') ### Request Example ```python from crpapi import CRP CRP.apikey = 'your-api-key-here' summary = CRP.orgSummary.get(id='D000022008', cycle='2014') ``` ### Response #### Success Response (200) - **@attributes** (object) - Contains summary data like 'orgname', 'total', 'pacs', 'lobbying' ### Response Example ```json { "@attributes": { "orgname": "Google Inc", "total": "1234567", "pacs": "500000", "lobbying": "734567" } } ``` ``` -------------------------------- ### CRP.candSummary.get Source: https://context7.com/opensecrets/python-crpapi/llms.txt Fetch a candidate's fundraising summary. Returns high-level campaign finance figures for a candidate in a given election cycle: total raised, total spent, cash on hand, debt, party, chamber, and state. ```APIDOC ## `CRP.candSummary.get` — Fetch a candidate's fundraising summary Returns high-level campaign finance figures for a candidate in a given election cycle: total raised, total spent, cash on hand, debt, party, chamber, and state. ```python from crpapi import CRP, CRPApiError CRP.apikey = 'your-api-key-here' # Fetch Nancy Pelosi's 2014 cycle fundraising summary summary = CRP.candSummary.get(cid='N00007360', cycle='2014') print(f"Candidate: {summary['cand_name']} ({summary['party']}, {summary['state']})") print(f"Total raised: ${float(summary['total']):,.2f}") print(f"Total spent: ${float(summary['spent']):,.2f}") print(f"Cash on hand: ${float(summary['cash_on_hand']):,.2f}") print(f"Debt: ${float(summary['debt']):,.2f}") print(f"Source: {summary['source']}") # Example output: # Candidate: Pelosi, Nancy (D, CA) # Total raised: $1,294,719.87 # Total spent: $1,304,840.24 # Cash on hand: $439,206.96 # Debt: $0.00 ``` ``` -------------------------------- ### getOrgs.get Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Searches for organizations based on a query string and returns matching organization IDs and names. ```APIDOC ## GET getOrgs ### Description Searches for organizations by name or partial name. Returns a list of organizations with their names and unique IDs. ### Method GET ### Endpoint /getOrgs ### Parameters #### Query Parameters - **org** (string) - Required - The organization name or partial name to search for (e.g., 'Goog'). ### Response #### Success Response (200) - Returns a list of dictionaries, where each dictionary contains `orgname` and `orgid` for matching organizations. ### Response Example [ { "@attributes": { "orgname": "Googasian Firm", "orgid": "D000051419" } }, { "@attributes": { "orgname": "Google Inc", "orgid": "D000022008" } } ] ``` -------------------------------- ### Fetch Organization Summary Source: https://context7.com/opensecrets/python-crpapi/llms.txt Retrieves a summary of political spending for a given organization, identified by its ID. ```APIDOC ## Fetch Google's political spending summary summary = CRP.orgSummary.get(id='D000022008') a = summary['@attributes'] print(f"Organization: {a['orgname']} (Cycle: {a['cycle']})") print(f"Total contributions: ${int(a['total']):,}") print(f"Lobbying spend: ${int(a['lobbying']):,}") print(f"Democrats: ${int(a['dems']):,}") print(f"Republicans: ${int(a['repubs']):,}") print(f"PAC contributions: ${int(a['pacs']):,}") print(f"Individual donations: ${int(a['indivs']):,}") print(f"Members invested: {a['mems_invested']}") ``` -------------------------------- ### Search Organizations by Name Source: https://context7.com/opensecrets/python-crpapi/llms.txt Searches for organizations by name and returns a list of matching organizations along with their OpenSecrets organization IDs. Useful for finding `orgid` for other queries. ```python from crpapi import CRP, CRPApiError CRP.apikey = 'your-api-key-here' # Search for organizations with "Goog" in their name orgs = CRP.getOrgs.get(org='Goog') for org in orgs: attrs = org['@attributes'] print(f" {attrs['orgname']} — ID: {attrs['orgid']}") ``` -------------------------------- ### Fetch Candidate Contributions by Industry Source: https://context7.com/opensecrets/python-crpapi/llms.txt Breaks down contributions received by a candidate from different industries, including PAC and individual totals. Requires candidate ID and cycle. ```python from crpapi import CRP, CRPApiError CRP.apikey = 'your-api-key-here' # Fetch industry contributions to Nancy Pelosi in 2014 industries = CRP.candIndustry.get(cid='N00007360', cycle='2014') print(f"{'Industry':<30} {'Total':>10} {'PACs':>10} {'Individuals':>12}") print("-" * 65) for ind in industries[:5]: a = ind['@attributes'] print(f"{a['industry_name']:<30} ${int(a['total']):>9,} ${int(a['pacs']):>9,} ${int(a['indivs']):>11,}") ``` -------------------------------- ### CRP.candIndustry.get Source: https://context7.com/opensecrets/python-crpapi/llms.txt Fetch a candidate's contributions by industry, including PAC vs. individual totals and industry codes. ```APIDOC ## CRP.candIndustry.get — Fetch a candidate's contributions by industry ### Description Returns a breakdown of contributions received from different industries, including PAC vs. individual totals and industry codes. ### Method GET ### Endpoint `/v2/contributions/by_industry` (Assumed based on common API patterns and function name) ### Parameters #### Query Parameters - **cid** (string) - Required - Candidate ID - **cycle** (string) - Required - Election cycle (e.g., '2014') ### Request Example ```python from crpapi import CRP CRP.apikey = 'your-api-key-here' industries = CRP.candIndustry.get(cid='N00007360', cycle='2014') ``` ### Response #### Success Response (200) - **@attributes** (object) - Contains attributes like 'industry_name', 'total', 'pacs', 'indivs' ### Response Example ```json [ { "@attributes": { "industry_name": "Health Professionals", "total": "74750", "pacs": "70500", "indivs": "4250" } } ] ``` ``` -------------------------------- ### Fetch Organization Summary Source: https://context7.com/opensecrets/python-crpapi/llms.txt Retrieves a comprehensive summary of an organization's political spending, including total contributions, PAC money, lobbying spend, and individual donations. Requires an organization ID. ```python from crpapi import CRP, CRPApiError CRP.apikey = 'your-api-key-here' ``` -------------------------------- ### candIndustry.get Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieves industry data for a specific candidate. Requires candidate ID and election cycle. ```APIDOC ## GET candIndustry ### Description Retrieves a list of industries associated with a candidate, including total contributions, PAC contributions, and individual contributions for a specified election cycle. ### Method GET ### Endpoint /candIndustry ### Parameters #### Query Parameters - **cid** (string) - Required - The candidate ID. - **cycle** (string) - Required - The election cycle (e.g., '2014'). ### Response #### Success Response (200) - Returns a list of dictionaries, where each dictionary represents an industry and contains attributes like `total`, `industry_code`, `industry_name`, `pacs`, and `indivs`. ### Response Example [ { "@attributes": { "total": "74750", "industry_code": "H01", "industry_name": "Health Professionals", "pacs": "70500", "indivs": "4250" } } ] ``` -------------------------------- ### CRP.getOrgs.get Source: https://context7.com/opensecrets/python-crpapi/llms.txt Search for organizations by name and retrieve their OpenSecrets organization IDs. ```APIDOC ## CRP.getOrgs.get — Search for organizations by name ### Description Returns a list of organizations matching the search term, with their OpenSecrets organization IDs. Use this to find an `orgid` for use with `orgSummary`. ### Method GET ### Endpoint `/v2/orgs/search` (Assumed based on common API patterns and function name) ### Parameters #### Query Parameters - **org** (string) - Required - Organization name or part of the name to search for ### Request Example ```python from crpapi import CRP CRP.apikey = 'your-api-key-here' orgs = CRP.getOrgs.get(org='Goog') ``` ### Response #### Success Response (200) - **@attributes** (object) - Contains attributes like 'orgname', 'orgid' ### Response Example ```json [ { "@attributes": { "orgname": "Googasian Firm", "orgid": "D000051419" } } ] ``` ``` -------------------------------- ### CRP.candIndByInd.get Source: https://context7.com/opensecrets/python-crpapi/llms.txt Fetch a candidate's fundraising within a specific industry, including rank among all candidates in that industry. ```APIDOC ## CRP.candIndByInd.get — Fetch a candidate's fundraising within a specific industry ### Description Returns detailed fundraising data for a candidate from a single industry code, including rank among all candidates in that industry. ### Method GET ### Endpoint `/v2/contributions/by_industry` (Assumed, specific industry filtering might be a parameter) ### Parameters #### Query Parameters - **cid** (string) - Required - Candidate ID - **cycle** (string) - Required - Election cycle (e.g., '2014') - **ind** (string) - Required - Industry code (e.g., 'H01') ### Request Example ```python from crpapi import CRP CRP.apikey = 'your-api-key-here' data = CRP.candIndByInd.get(cid='N00007360', cycle='2014', ind='H01') ``` ### Response #### Success Response (200) - **cand_name** (string) - Candidate's name - **party** (string) - Candidate's party affiliation - **state** (string) - Candidate's state - **industry** (string) - Industry name - **total** (string) - Total contributions from this industry - **pacs** (string) - PAC contributions from this industry - **indivs** (string) - Individual contributions from this industry - **rank** (string) - Rank among all candidates in this industry ### Response Example ```json { "cand_name": "Pelosi, Nancy", "party": "D", "state": "California", "industry": "Health Professionals", "total": "74750", "pacs": "70500", "indivs": "4250", "rank": "36" } ``` ``` -------------------------------- ### candSector.get Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieves sector data for a specific candidate, including contributions by sector for a given election cycle. ```APIDOC ## GET candSector ### Description Retrieves a list of economic sectors and the corresponding contributions from each sector to a specific candidate for a given election cycle. Includes total contributions, PAC contributions, and individual contributions. ### Method GET ### Endpoint /candSector ### Parameters #### Query Parameters - **cid** (string) - Required - The candidate ID. - **cycle** (string) - Required - The election cycle (e.g., '2014'). ### Response #### Success Response (200) - Returns a list of dictionaries, where each dictionary represents a sector and contains attributes like `total`, `indivs`, `sectorid`, `pacs`, and `sector_name`. ### Response Example [ { "@attributes": { "total": "11000", "indivs": "0", "sectorid": "A", "pacs": "11000", "sector_name": "Agribusiness" } } ] ``` -------------------------------- ### CRP.candSector.get Source: https://context7.com/opensecrets/python-crpapi/llms.txt Fetch a candidate's contributions by sector, grouping totals by broad economic sectors. ```APIDOC ## CRP.candSector.get — Fetch a candidate's contributions by sector ### Description Returns contribution totals grouped by broad economic sectors (e.g., Finance, Labor, Health, Technology). ### Method GET ### Endpoint `/v2/contributions/by_sector` (Assumed based on common API patterns and function name) ### Parameters #### Query Parameters - **cid** (string) - Required - Candidate ID - **cycle** (string) - Required - Election cycle (e.g., '2014') ### Request Example ```python from crpapi import CRP CRP.apikey = 'your-api-key-here' sectors = CRP.candSector.get(cid='N00007360', cycle='2014') ``` ### Response #### Success Response (200) - **@attributes** (object) - Contains attributes like 'sector_name', 'total' ### Response Example ```json [ { "@attributes": { "sector_name": "Labor", "total": "165500" } } ] ``` ``` -------------------------------- ### CRP.candContrib.get Source: https://context7.com/opensecrets/python-crpapi/llms.txt Fetch the top contributing organizations for a candidate in a given cycle, including total dollars given. ```APIDOC ## CRP.candContrib.get — Fetch a candidate's top contributors ### Description Returns the top contributing organizations for a candidate in a given cycle, including total dollars given. ### Method GET ### Endpoint `/v2/contributions/by_organization` (Assumed based on common API patterns and function name) ### Parameters #### Query Parameters - **cid** (string) - Required - Candidate ID - **cycle** (string) - Required - Election cycle (e.g., '2014') ### Request Example ```python from crpapi import CRP CRP.apikey = 'your-api-key-here' contributors = CRP.candContrib.get(cid='N00007360', cycle='2014') ``` ### Response #### Success Response (200) - **@attributes** (object) - Contains attributes like 'org_name', 'total' ### Response Example ```json [ { "@attributes": { "org_name": "Certain Software Inc", "total": "10400" } } ] ``` ``` -------------------------------- ### candContrib.get Source: https://github.com/opensecrets/python-crpapi/blob/master/README.md Retrieves contribution data for a specific candidate. Requires the candidate's unique ID (cid) and the election cycle. ```APIDOC ## candContrib.get ### Description Retrieves a list of contributions made to a specific candidate for a given election cycle. Includes details about the contributing organizations and the amounts. ### Method GET (simulated) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters - **cid** (string) - Required - The unique identifier for the candidate. - **cycle** (string) - Required - The election cycle (e.g., '2014'). ### Request Example ```python print(CRP.candContrib.get(cid='N00007360',cycle='2014')) ``` ### Response #### Success Response (200) - **@attributes** (object) - Contains attributes for each contribution, such as organization name and total contribution amount. #### Response Example ```json [ { "@attributes": { "org_name": "Certain Software Inc", "total": "10400" } }, { "@attributes": { "org_name": "Chartwell Hotels", "total": "10400" } }, { "@attributes": { "org_name": "Jewish Community Federation", "total": "10400" } }, { "@attributes": { "org_name": "Marcus & Millichap", "total": "10400" } }, { "@attributes": { "org_name": "Stanford University", "total": "10400" } }, { "@attributes": { "org_name": "Facebook Inc", "total": "10200" } }, { "@attributes": { "org_name": "American Assn for Justice", "total": "10000" } }, { "@attributes": { "org_name": "American Health Care Assn", "total": "10000" } }, { "@attributes": { "org_name": "Boeing Co", "total": "10000" } }, { "@attributes": { "org_name": "Francisco Partners", "total": "10000" } } ] ``` ``` -------------------------------- ### Fetch Legislators by State or District Source: https://context7.com/opensecrets/python-crpapi/llms.txt Retrieve a list of legislators for a specific state or district ID. The output includes contact information, party affiliation, and election details. ```python from crpapi import CRP, CRPApiError CRP.apikey = 'your-api-key-here' # Fetch all legislators for New Jersey's 4th congressional district legislators = CRP.getLegislators.get(id='NJ04') for leg in legislators: attrs = leg['@attributes'] print(f"{attrs['firstlast']} ({attrs['party']}) - Office: {attrs['office']}") print(f" Phone: {attrs['phone']}, Website: {attrs['website']}") print(f" First elected: {attrs['first_elected']}, CID: {attrs['cid']}") ```