├── .gitignore ├── LICENSE ├── README.md ├── example.py └── life360.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Harper Reed 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # life360-python 2 | A simple python life360 client 3 | 4 | I built this because I couldn't find a straight forward life360 client that wasn't based on some curl commands. It works. 5 | 6 | ## Usage 7 | 8 | It is pretty straight forward and should be easy to integrate with any project. 9 | 10 | 11 | # basic authorization hash (base64 if you want to decode it and see the sekrets) 12 | # this is a googleable or sniffable value. i imagine life360 changes this sometimes. 13 | authorization_token = "Y2F0aGFwYWNyQVBoZUtVc3RlOGV2ZXZldnVjSGFmZVRydVl1ZnJhYzpkOEM5ZVlVdkE2dUZ1YnJ1SmVnZXRyZVZ1dFJlQ1JVWQ==" 14 | 15 | # your username and password (hope they are secure!) 16 | username = "email@address.com" 17 | password = "super long password" 18 | 19 | #instantiate the API 20 | api = life360(authorization_token=authorization_token, username=username, password=password) 21 | 22 | #Authenticate! 23 | if api.authenticate(): 24 | 25 | #Grab some circles returns json 26 | circles = api.get_circles() 27 | 28 | #grab id 29 | id = circles[0]['id'] 30 | 31 | #Let's get your circle! 32 | circle = api.get_circle(id) 33 | 34 | ## Next? 35 | 36 | Would love to see this integrated into some home assistant projects. Maybe pushing the updates to MQTT. 37 | 38 | ## HMU 39 | 40 | harper@nata2.org 41 | 42 | @harper 43 | -------------------------------------------------------------------------------- /example.py: -------------------------------------------------------------------------------- 1 | from life360 import life360 2 | import datetime 3 | 4 | #This is only here to make the example display nicer 5 | def prettydate( d): 6 | diff = datetime.datetime.utcnow() - d 7 | s = diff.seconds 8 | if diff.days > 7 or diff.days < 0: 9 | return d.strftime('%d %b %y') 10 | elif diff.days == 1: 11 | return '1 day ago' 12 | elif diff.days > 1: 13 | return '{} days ago'.format(diff.days) 14 | elif s <= 1: 15 | return 'just now' 16 | elif s < 60: 17 | return '{} seconds ago'.format(s) 18 | elif s < 120: 19 | return '1 minute ago' 20 | elif s < 3600: 21 | return '{} minutes ago'.format(s/60) 22 | elif s < 7200: 23 | return '1 hour ago' 24 | else: 25 | return '{} hours ago'.format(s/3600) 26 | 27 | if __name__ == "__main__": 28 | 29 | # basic authorization hash (base64 if you want to decode it and see the sekrets) 30 | # this is a googleable or sniffable value. i imagine life360 changes this sometimes. 31 | # authorization_token = "cFJFcXVnYWJSZXRyZTRFc3RldGhlcnVmcmVQdW1hbUV4dWNyRUh1YzptM2ZydXBSZXRSZXN3ZXJFQ2hBUHJFOTZxYWtFZHI0Vg==" 32 | 33 | # updated token on 8/1/2023 @ryanbuckner 34 | authorization_token = "Y2F0aGFwYWNyQVBoZUtVc3RlOGV2ZXZldnVjSGFmZVRydVl1ZnJhYzpkOEM5ZVlVdkE2dUZ1YnJ1SmVnZXRyZVZ1dFJlQ1JVWQ==" 35 | 36 | # your username and password (hope they are secure!) 37 | username = "email@address.com" 38 | password = "super long password" 39 | 40 | #instantiate the API 41 | api = life360(authorization_token=authorization_token, username=username, password=password) 42 | if api.authenticate(): 43 | 44 | #Grab some circles returns json 45 | circles = api.get_circles() 46 | 47 | #grab id 48 | id = circles[0]['id'] 49 | 50 | #Let's get your circle! 51 | circle = api.get_circle(id) 52 | 53 | #Let's display some goodies 54 | 55 | print("Circle name:", circle['name']) 56 | print("Members (" + circle['memberCount'] + "):") 57 | for m in circle['members']: 58 | 59 | print("\tName:", m['firstName'], m['lastName']) 60 | print("\tLocation:" , m['location']['name']) 61 | print("\tLatLng:" , m['location']['latitude'] +", "+ m['location']['longitude']) 62 | print("\tHas been at " + str(m['location']['name']) +" since " + prettydate(datetime.datetime.fromtimestamp(int(str(m['location']['since']))))) 63 | print("\tBattery level:" , m['location']['battery'] +"%") 64 | print("\t") 65 | else: 66 | print("Error authenticating") 67 | -------------------------------------------------------------------------------- /life360.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | 4 | class life360: 5 | 6 | # base_url = "https://api.life360.com/v3/" 7 | base_url = "https://api-cloudfront.life360.com/v3/" 8 | base_url_v4 = "https://api-cloudfront.life360.com/v4/ 9 | token_url = "oauth2/token" 10 | circles_url = "circles" 11 | circle_url = "circles/" 12 | user_agent = "com.life360.android.safetymapd/KOKO/23.49.0 android/13" 13 | 14 | 15 | def __init__(self, authorization_token=None, username=None, password=None): 16 | self.authorization_token = authorization_token 17 | self.username = username 18 | self.password = password 19 | 20 | def make_request(self, url, params=None, method='GET', authheader=None): 21 | headers = {'Accept': 'application/json', "user-agent": self.user_agent} 22 | if authheader: 23 | headers.update({'Authorization': authheader, 'cache-control': "no-cache",}) 24 | 25 | if method == 'GET': 26 | r = requests.get(url, headers=headers) 27 | elif method == 'POST': 28 | r = requests.post(url, data=params, headers=headers) 29 | 30 | return r.json() 31 | 32 | def authenticate(self): 33 | 34 | url = self.base_url + self.token_url 35 | params = { 36 | "grant_type":"password", 37 | "username":self.username, 38 | "password":self.password, 39 | } 40 | 41 | r = self.make_request(url=url, params=params, method='POST', authheader="Basic " + self.authorization_token) 42 | try: 43 | self.access_token = r['access_token'] 44 | return True 45 | except: 46 | return False 47 | 48 | def get_circles(self): 49 | url = self.base_url_v4 + self.circles_url 50 | authheader="bearer " + self.access_token 51 | r = self.make_request(url=url, method='GET', authheader=authheader) 52 | return r['circles'] 53 | 54 | def get_circle(self, circle_id): 55 | url = self.base_url + self.circle_url + circle_id 56 | authheader="bearer " + self.access_token 57 | r = self.make_request(url=url, method='GET', authheader=authheader) 58 | return r 59 | 60 | 61 | --------------------------------------------------------------------------------