Skip to main content

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!

Metadata

Release files for django-device-tracker 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-device-tracker 0.3.0
File Size Uploaded Provenance
django_device_tracker-0.3.0.tar.gz 8.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-device-tracker 0.3.0
File Interpreter ABI Platform
django_device_tracker-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / django_device_tracker-0.3.0.tar.gz

Download URL django_device_tracker-0.3.0.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a72d38dc20be742b421d5bca029c425c4a05ca71c0ab64ac8a45d56904f7ff83
BLAKE2b-256 checksum
How to use checksums
56658c792a4a4548e7dd4624e09669896acad33e8bc6894a68934e2f59c32a16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.17

Release files / django_device_tracker-0.3.0-py3-none-any.whl

Download URL django_device_tracker-0.3.0-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0132c79ebf51cd04c66021ab1747d6661197179e4d54cb56d6a57dcccacd9d69
BLAKE2b-256 checksum
How to use checksums
14f0b7a41e2bb8fa681c8626d6c2fbbf853d96cb738714e7ecddc7a4694e125a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.17

Security for django-device-tracker 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page