Skip to main content

A Python wrapper for the UK Police API.

Project description

Pyolice

Overview

Pyolice is a Python wrapper for the UK Police API, providing an easy-to-use interface to access and interact with police data such as street-level crimes, outcomes, neighbourhoods, and stop-and-search activities. This readme.md is generated through ChatGPT for now, please forgive errors.

Features

  • Retrieve street-level crimes at specific locations or within custom areas.
  • Fetch crime outcomes by coordinates, location, or area.
  • Access information about neighbourhoods, including teams, events, and boundaries.
  • Perform stop-and-search queries by area, force, or location.
  • List and get details of police forces.
  • Obtain metadata, such as available crime categories and the last updated date for the data.

Requirements

  • Python 3.7 or later
  • requests

Usage

Pyolice is split between 4 sections

  • Street level crimes
  • Neighbourhood
  • Stop and search
  • Police force

this is an example to find specific info:

import pyolice

# Step 1: Locate the neighbourhood for specific coordinates
neighbourhood_info = pyolice.neighbourhoods.locate_neighbourhood(latitude=52.629729, longitude=-1.131592)
force_id = neighbourhood_info['force']
neighbourhood_id = neighbourhood_info['neighbourhood']

# Step 2: Get detailed information about the neighbourhood
neighbourhood_details = pyolice.neighbourhoods.get_neighbourhood_details(force_id=force_id, neighbourhood_id=neighbourhood_id)
print("Neighbourhood Details:", neighbourhood_details)

# Step 3: Fetch street-level crimes in the neighbourhood area
polygon = "52.268,0.543:52.794,0.238:52.130,0.478"  # Replace with actual boundary data if available
crimes = pyolice.street_level.get_street_crimes_in_area(poly=polygon, date="2023-12")
print("Crimes in Area:", crimes)

# Step 4: Retrieve outcomes for crimes near the specified coordinates
outcomes = pyolice.street_level.get_outcomes_by_coordinates(lat=52.629729, lng=-1.131592, date="2023-12")
print("Crime Outcomes:", outcomes)

Methods

Below are all methods in the api

Street Level Crimes

Methods relating to Street Level Crime:

Fetching Crimes at a Specific Location

import pyolice

crimes = pyolice.street_level.get_street_crimes_at_location(lat=52.629729, lng=-1.131592)
print(crimes)

Fetching Crimes in a Custom Area

import pyolice

polygon = "52.268,0.543:52.794,0.238:52.130,0.478"
crimes = pyolice.street_level.get_street_crimes_in_area(poly=polygon)
print(crimes)

Fetching Outcomes at a Specific Location

import pyolice

outcomes = pyolice.street_level.get_outcomes_at_location(location_id="12345", date="2023-12")
print(outcomes)

Fetching Outcomes by Coordinates

import pyolice

outcomes = pyolice.street_level.get_outcomes_by_coordinates(lat=52.629729, lng=-1.131592, date="2023-12")
print(outcomes)

Fetching Outcomes in a Custom Area

import pyolice

polygon = "52.268,0.543:52.794,0.238:52.130,0.478"
outcomes = pyolice.street_level.get_outcomes_in_area(poly=polygon)
print(outcomes)

Fetching Crimes at a Specific Location by ID or Coordinates

import pyolice

# Fetch by location ID
crimes = pyolice.street_level.get_crimes_at_specific_location(location_id="12345")
print(crimes)

# Fetch by coordinates
crimes = pyolice.street_level.get_crimes_at_specific_location(lat=52.629729, lng=-1.131592)
print(crimes)

Fetching Crimes with No Location

import pyolice

crimes = pyolice.street_level.get_crimes_no_location(category="all-crime", force="leicestershire", date="2023-12")
print(crimes)

Fetching Crime Categories

import pyolice

categories = pyolice.street_level.get_crime_categories(date="2023-12")
print(categories)

Fetching Last Updated Date

import pyolice

last_updated = pyolice.street_level.get_last_updated()
print(last_updated)

Fetching Outcomes for a Specific Crime

import pyolice

crime_id = "e11dade0a92a912d12329b9b2abb856ac9520434ad6845c30f503e9901d140f1"
outcomes = pyolice.street_level.get_outcomes_for_crime(crime_id=crime_id)
print(outcomes)

Fetching Neighbourhood Details

Methods relating to neighbourhoods:

Listing Neighbourhoods for a Force

import pyolice

neighbourhoods = pyolice.neighbourhoods.list_neighbourhoods(force_id="leicestershire")
print(neighbourhoods)

Fetching Neighbourhood Details

import pyolice

details = pyolice.neighbourhoods.get_neighbourhood_details(force_id="leicestershire", neighbourhood_id="12345")
print(details)

Fetching Neighbourhood Boundary

import pyolice

boundary = pyolice.neighbourhoods.get_neighbourhood_boundary(force_id="leicestershire", neighbourhood_id="12345")
print(boundary)

Fetching Neighbourhood Team Members

import pyolice

team = pyolice.neighbourhoods.get_neighbourhood_team(force_id="leicestershire", neighbourhood_id="12345")
print(team)

Fetching Neighbourhood Events

import pyolice

events = pyolice.neighbourhoods.get_neighbourhood_events(force_id="leicestershire", neighbourhood_id="12345")
print(events)

Fetching Neighbourhood Priorities

import pyolice

priorities = pyolice.neighbourhoods.get_neighbourhood_priorities(force_id="leicestershire", neighbourhood_id="12345")
print(priorities)

Locating Neighbourhood by Coordinates

import pyolice

location = pyolice.neighbourhoods.locate_neighbourhood(latitude=52.629729, longitude=-1.131592)
print(location)

Stop and Search

Methods relating to stop and search:

Stop and Search by Area

import pyolice

# By latitude and longitude
stops = pyolice.stop_search.stop_and_search_by_area(lat=52.629729, lng=-1.131592, date="2023-12")
print(stops)

# By polygon
polygon = "52.268,0.543:52.794,0.238:52.130,0.478"
stops = pyolice.stop_search.stop_and_search_by_area(poly=polygon, date="2023-12")
print(stops)

Stop and Search by Location

import pyolice

stops = pyolice.stop_search.stop_and_search_by_location(location_id="12345", date="2023-12")
print(stops)

Stop and Search with No Location

import pyolice

stops = pyolice.stop_search.stop_and_search_no_location(force="leicestershire", date="2023-12")
print(stops)

Stop and Search by Force

import pyolice

stops = pyolice.stop_search.stop_and_search_by_force(force="leicestershire", date="2023-12")
print(stops)

Fetching Police Force Details

Methods relating to Forces:

Listing All Police Forces

import pyolice

forces = pyolice.forces.list_forces()
print(forces)

Fetching Details of a Specific Police Force

import pyolice

details = pyolice.forces.get_force_details(force_id="leicestershire")
print(details)

Fetching Senior Officers of a Specific Police Force

import pyolice

officers = pyolice.forces.get_senior_officers(force_id="leicestershire")
print(officers)

Validation

Pyolice provides built-in validation for inputs:

  • Latitude and longitude are validated to ensure they fall within valid ranges.
  • Polygon strings for custom areas are checked for proper formatting.

Acknowledgements

This project relies on the UK Police API for data access and services.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uk_police-0.1.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uk_police-0.1.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file uk_police-0.1.0.tar.gz.

File metadata

  • Download URL: uk_police-0.1.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.0

File hashes

Hashes for uk_police-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dbfae96d7499b4260b2b00b6854053450563e06a8cf8477ef5aa77ce43e279e4
MD5 2d00c6420fd5dc67b6aa7aad6cd83541
BLAKE2b-256 ebcd2bb239ae97948df28436a0628298a78c6bb0b649a8ca7655f3218e7e96dc

See more details on using hashes here.

File details

Details for the file uk_police-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: uk_police-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.0

File hashes

Hashes for uk_police-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9777b1105ccac428f5c55d0e5a5e128c1bd67cdf9e153b1374d125443f23ae7
MD5 039fd8159c7678fb1f16ca2fd886d5cf
BLAKE2b-256 21496425d959082443cb9f23f8c1476270d20870b2bca23f5df05e4aa0caeaf5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page