Reusable device tracking app for Django projects
Project description
Django Device Tracker
A reusable Django app to track user login devices — plug-and-play for any Django project using session or JWT-based authentication.
🔧 Features
- Track IP address and user-agent per login
- Compatible with JWT (e.g., simplejwt)
- Saves login timestamp and refresh token
jti - Admin panel support
- Lightweight, no external dependencies
- API to list user devices
- API to logout from specific device
📦 Installation
pip install django-device-tracker
Add to your INSTALLED_APPS:
INSTALLED_APPS += ["device_tracker"]
Apply migrations:
python manage.py migrate device_tracker
🚀 Usage
Manual tracking per login (JWT):
In your login/signup/OTP views:
from device_tracker.utils import track_device
# After creating refresh token:
track_device(request, user, refresh_token)
The refresh_token is optional but strongly recommended for managing sessions.
What it stores:
user: ForeignKey to your user modelip_address: Auto-resolved from request headersdevice_name: User-Agent headerrefresh_token_jti: Extracted from token if providedlast_seen: Timestamp of loginis_active: Boolean flag (you can control this)
📡 API Endpoints
Include in your root urls.py:
path("api/", include("device_tracker.urls")),
GET /api/devices/
Returns list of active/inactive devices for current user.
POST /api/devices/<id>/logout/
Deactivates the given device (if owned by current user) and blacklists the refresh token if provided.
🛠 Admin Support
Device tracking entries are available in Django admin under Device model.
🔍 Advanced Integration Ideas (Optional)
- Custom middleware to track every request or session
- Show user active devices (already provided)
- Revoke session by removing device entry or blacklisting token (already supported)
📂 Development
To install locally:
git clone https://github.com/yourusername/django-device-tracker.git
cd django-device-tracker
pip install -e .
🪪 License
MIT License. See LICENSE file.
✍️ Author
Developed by [mejomba]. Contributions and feedback welcome!
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_device_tracker-0.3.0.tar.gz.
File metadata
- Download URL: django_device_tracker-0.3.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a72d38dc20be742b421d5bca029c425c4a05ca71c0ab64ac8a45d56904f7ff83
|
|
| MD5 |
0f4fab53b004792b369ca25b6c79b971
|
|
| BLAKE2b-256 |
56658c792a4a4548e7dd4624e09669896acad33e8bc6894a68934e2f59c32a16
|
File details
Details for the file django_device_tracker-0.3.0-py3-none-any.whl.
File metadata
- Download URL: django_device_tracker-0.3.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0132c79ebf51cd04c66021ab1747d6661197179e4d54cb56d6a57dcccacd9d69
|
|
| MD5 |
6426ed4af94033869481d32f07272f84
|
|
| BLAKE2b-256 |
14f0b7a41e2bb8fa681c8626d6c2fbbf853d96cb738714e7ecddc7a4694e125a
|