Skip to main content

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 model
  • ip_address: Auto-resolved from request headers
  • device_name: User-Agent header
  • refresh_token_jti: Extracted from token if provided
  • last_seen: Timestamp of login
  • is_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

django_device_tracker-0.3.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

django_device_tracker-0.3.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

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

Hashes for django_device_tracker-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a72d38dc20be742b421d5bca029c425c4a05ca71c0ab64ac8a45d56904f7ff83
MD5 0f4fab53b004792b369ca25b6c79b971
BLAKE2b-256 56658c792a4a4548e7dd4624e09669896acad33e8bc6894a68934e2f59c32a16

See more details on using hashes here.

File details

Details for the file django_device_tracker-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_device_tracker-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0132c79ebf51cd04c66021ab1747d6661197179e4d54cb56d6a57dcccacd9d69
MD5 6426ed4af94033869481d32f07272f84
BLAKE2b-256 14f0b7a41e2bb8fa681c8626d6c2fbbf853d96cb738714e7ecddc7a4694e125a

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