Is there a way to control home assistant with a python script?

Let’s say I have a script running opencv and other scripts processing other data and writing their outputs to a database.

  1. Is there a way for me to access the device ids ,states and sensor outputs from outside home assistant (ie. from whatever script i want to run)?
  2. I want another script to process the data from the database and switch devices on home assistant.
  3. Is there a way for me to send commands to the home assistant ( lets say its running on a rpi) from another computer on the same network without using the ui.
    Are there any option available which will let me do so
    Thank you