UK police API¶
source: https://data.police.uk/docs/
import requests
import pandas as pd
parameters¶
Forces
Specific force
Force senior officers
Street level crimes
Street level outcomes
Crimes at location
Crimes with no location
Crime categories
Last updated
Outcomes for a specific crime
Neighbourhoods
Specific neighbourhood
Neighbourhood boundary
Neighbourhood team
Neighbourhood events
Neighbourhood priorities
Locate neighbourhood
Stop and searches by area
Stop and searches by location
Stop and searches with no location
Stop and searches by force
Availability last 36 months¶
# returns list of all available datasets
url = 'https://data.police.uk/api/crimes-street-dates'
req = requests.get(url)
req
<Response [200]>
# data from earliest month
print(req.json()[35]['date'])
# data from latest month
print(req.json()[0]['date'])
2019-09
2022-08
Stop and search¶
# send query via variables and f-string
endpoint = 'https://data.police.uk/api'
method = 'stops-street'
lat = "52.629729"
long = "-1.131592"
month = "2021-04"
query = f'{endpoint}/{method}?lat={lat}&lng={long}&date={month}'
print(query)
req = requests.get(query)
req
https://data.police.uk/api/stops-street?lat=52.629729&lng=-1.131592&date=2021-04
<Response [200]>
req.json()[0]
{'age_range': 'over 34',
'outcome': 'A no further action disposal',
'involved_person': True,
'self_defined_ethnicity': 'Other ethnic group - Not stated',
'gender': 'Male',
'legislation': 'Police and Criminal Evidence Act 1984 (section 1)',
'outcome_linked_to_object_of_search': None,
'datetime': '2021-04-07T19:55:00+00:00',
'removal_of_more_than_outer_clothing': False,
'outcome_object': {'id': 'bu-no-further-action',
'name': 'A no further action disposal'},
'location': {'latitude': '52.626988',
'street': {'id': 882307,
'name': 'On or near Further/Higher Educational Building'},
'longitude': '-1.123532'},
'operation': None,
'officer_defined_ethnicity': 'Asian',
'type': 'Person and Vehicle search',
'operation_name': None,
'object_of_search': 'Stolen goods'}
# query via assembled url (bicycle theft, April 2021)
epoint = 'https://data.police.uk/api/crimes-street/bicycle-theft?lat=51.476369992679096&lng=-3.1781098361443667&date=2021-04'
req = requests.get(epoint)
req
<Response [200]>
response = req.json()
len(response)
34
response[0]
{'category': 'bicycle-theft',
'location_type': 'Force',
'location': {'latitude': '51.485384',
'street': {'id': 1081176, 'name': 'On or near The Walk'},
'longitude': '-3.169447'},
'context': '',
'outcome_status': {'category': 'Investigation complete; no suspect identified',
'date': '2021-04'},
'persistent_id': 'b690e717ff1e48bd1b15ad8055a648c62d3ba5956a25a70fdc4f116218719902',
'id': 92090274,
'location_subtype': '',
'month': '2021-04'}
‘params’ as arguments dict¶
endpoint = 'https://data.police.uk/api/stops-street?'
parameters = {'lat':"52.629729", 'lng':"-1.131592", 'date':"2020-06"}
req = requests.get(endpoint, params = parameters)
req
<Response [200]>
response = req.json()
response[0]
{'age_range': 'over 34',
'outcome': 'A no further action disposal',
'involved_person': True,
'self_defined_ethnicity': 'White - English/Welsh/Scottish/Northern Irish/British',
'gender': 'Male',
'legislation': 'Police and Criminal Evidence Act 1984 (section 1)',
'outcome_linked_to_object_of_search': None,
'datetime': '2020-06-12T21:04:00+00:00',
'removal_of_more_than_outer_clothing': False,
'outcome_object': {'id': 'bu-no-further-action',
'name': 'A no further action disposal'},
'location': {'latitude': '52.629909',
'street': {'id': 883345, 'name': 'On or near Marquis Street'},
'longitude': '-1.132073'},
'operation': None,
'officer_defined_ethnicity': 'White',
'type': 'Person search',
'operation_name': None,
'object_of_search': 'Stolen goods'}