This Python project is a toolkit of utility scripts and Jupyter notebooks designed to ingest, query, and analyze a database of cyber-attacks based on data collected by the Cyber Peace Institute. No installation is required; just download the scripts or notebooks you want to use.
Download the repository and navigate to the project directory where you can directly execute the Python scripts or open the Jupyter notebooks.
Create an SQLite database with tables named 'events', 'threat_actors', and 'sources'.
from your_module import create_database
# Initialize the database
create_database()
Insert a batch of cyber-attack data into the SQLite database.
Fetch data from the Cyber Conflicts API and save it to a JSON file.
from funcs import *
DATABASE_NAME = 'events2.db'
filename = get_cpi_data()
# Initialize the database
create_database()
# Example of loading data from a file
with open(filename, 'r') as f:
data = json.load(f)
# Insert the data into the database
insert_data(data)
Here are some notable query functions, designed to help you query specific information easily.
search_threat_actor(threat_actor_key: str) -> None
search_events_by_date_range(start_date: str, end_date: str) -> List[Tuple]
search_ukraine_attacked_by_russia() -> List[Tuple]
search_cyber_attacks_by_date_range_and_allegiance(start_date: str, end_date: str, allegiance: str) -> List[Tuple]
search_by_threat_actor_key(threat_actor_key: str) -> List[Tuple]
Write the query results to a CSV file.
from funcs import *
DATABASE_NAME = 'events2.db'
results = search_events_by_date_range('2022-01-01', '2022-02-01')
write_to_csv(results, 'events_january.csv')
get_unique_event_types() -> Set[str]
get_unique_threat_actor_names() -> Set[str]
get_unique_event_types_with_count() -> Dict[str, int]
Interested in contributing? Please read through our CONTRIBUTING.md.
This toolkit is licensed under the MIT License. For more details, see LICENSE.md.
Feel free to adapt this README.md
according to your project's specific needs. The code examples are placeholders; please replace them with the actual functions from your modules.