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.1.3.tar.gz (8.2 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.1.3-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file django_device_tracker-0.1.3.tar.gz.

File metadata

  • Download URL: django_device_tracker-0.1.3.tar.gz
  • Upload date:
  • Size: 8.2 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.1.3.tar.gz
Algorithm Hash digest
SHA256 f79e132cd4898f1efc0f32cd43693ddf9a689732f96535a6c97cd5824e09c2a6
MD5 dc06fd1b6bca0981d9618fd2705fe2e9
BLAKE2b-256 abbaecea496582e6a0afb7865c4b0e3b4ed837a4003a572d83e2cb4b6b3abfb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_device_tracker-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b383199a41426201180072940efbdf5a31f5162c4ada655ec2002022d47aea59
MD5 a65393c2aa9349bb15c7af4f14378153
BLAKE2b-256 bac79d537dcf7481be072f956898546dd92889830c403f27a5341ac0b2a54a61

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