Skip to main content

ModelSensor 🌍

Let LLM sense the world - A Python library for detecting system information, location, time, and environment to enhance AI model awareness.

PyPI version Python 3.7+ License: MIT

🚀 Features

  • 🕒 Time Detection: Current time, timezone, UTC time, and formatted timestamps
  • 🌍 Location Information: IP-based geolocation with country, city, coordinates
  • 💻 System Information: OS, hardware, processor, Python environment details
  • 📊 Resource Monitoring: CPU usage, memory, disk space, network statistics
  • 🔧 Environment Detection: Working directory, virtual environments, runtime context
  • 🌐 Network Information: Network interfaces, default gateway, connection details
  • 📄 Multiple Output Formats: JSON, Markdown, and summary formats
  • 🔌 Easy Integration: Perfect for Ollama and other LLM applications

📦 Installation

From PyPI (Recommended)

pip install modelsensor

From Source

git clone https://github.com/EasyCam/modelsensor.git
cd modelsensor
pip install -e .

🛠️ Usage

Command Line Interface

# Basic usage - JSON output
modelsensor

# Include location information
modelsensor --location

# Markdown format
modelsensor --format markdown

# Save to file
modelsensor --output system_info.json

# Compact JSON
modelsensor --compact

# Quick summary
modelsensor --format summary

Python API

from modelsensor import ModelSensor

# Create sensor instance
sensor = ModelSensor()

# Collect all system information
data = sensor.collect_all_data(include_location=True)

# Get JSON output
json_output = sensor.to_json(indent=2)
print(json_output)

# Get specific information
time_info = sensor.get_time_info()
system_info = sensor.get_system_info()
resource_info = sensor.get_resource_info()

With Formatters

from modelsensor import ModelSensor, MarkdownFormatter, JSONFormatter

sensor = ModelSensor()
data = sensor.collect_all_data()

# Markdown output
markdown_report = MarkdownFormatter.format(data)
print(markdown_report)

# Compact JSON
compact_json = JSONFormatter.format_compact(data)
print(compact_json)

# Summary
summary = MarkdownFormatter.format_summary(data)
print(summary)

🤖 Integration with Ollama

Perfect for providing system context to your local LLM:

import ollama
from modelsensor import ModelSensor

# Get system information
sensor = ModelSensor()
system_context = sensor.to_json(include_location=True, mode="full")

# Create enhanced prompt
prompt = f"""
System Context:
{system_context}

User Question: What can you tell me about my current system?
"""

# Send to Ollama
response = ollama.chat(model='qwen3:0.6b', messages=[
    {'role': 'user', 'content': prompt}
])

print(response['message']['content'])

📊 Example Output

JSON Format

{
  "sensor_info": {
    "library": "modelsensor",
    "version": "1.1.1",
    "collection_time": "2024-01-15T10:30:45.123456"
  },
  "time": {
    "current_time": "2024-01-15T10:30:45.123456",
    "utc_time": "2024-01-15T15:30:45.123456",
    "timezone": "EST",
    "weekday": "Monday",
    "formatted_time": "2024-01-15 10:30:45"
  },
  "system": {
    "system": "Darwin",
    "platform": "macOS-12.6-x86_64-i386-64bit",
    "machine": "x86_64",
    "processor": "i386",
    "python_version": "3.9.16"
  },
  "resources": {
    "cpu": {
      "usage_percent": 15.2,
      "count": 8,
      "physical_cores": 4
    },
    "memory": {
      "total_gb": 16.0,
      "used_gb": 8.5,
      "available_gb": 7.5,
      "percentage": 53.1
    }
  }
}

Markdown Format

# System Information Report
*Generated by ModelSensor at 2024-01-15T10:30:45.123456*

## 🕒 Time Information
- **Current Time**: 2024-01-15 10:30:45
- **UTC Time**: 2024-01-15T15:30:45.123456
- **Timezone**: EST
- **Day of Week**: Monday

## 💻 System Information
- **Operating System**: Darwin 21.6.0
- **Platform**: macOS-12.6-x86_64-i386-64bit
- **Machine**: x86_64
- **Python Version**: 3.9.16

🎯 Use Cases

  • 🤖 AI/LLM Context: Provide real-world awareness to language models
  • 📊 System Monitoring: Track system resources and performance
  • 🔍 Environment Detection: Identify runtime environments and configurations
  • 📋 System Reporting: Generate comprehensive system reports
  • 🛠️ DevOps Tools: System information for deployment and monitoring scripts

🔧 API Reference

ModelSensor Class

  • collect_all_data(include_location=False) - Gather all available information
  • to_json(indent=2, include_location=False, mode="brief") - JSON string output(mode 可选 "brief" 或 "full",默认 "brief")
  • to_dict(include_location=False, mode="brief") - Dictionary output(mode 可选 "brief" 或 "full",默认 "brief")

Formatters

  • JSONFormatter.format(data, indent=2) - Pretty JSON formatting
  • JSONFormatter.format_compact(data) - Compact JSON formatting
  • MarkdownFormatter.format(data) - Full Markdown report
  • MarkdownFormatter.format_summary(data) - Brief summary

Screenshots

Use Directly

Use in Python

Use with Ollama

🚨 Privacy Notice

  • Location data is optional and only collected when explicitly requested
  • No data is transmitted except for optional IP geolocation lookup
  • Environment variables are included but can be filtered in your application
  • All data collection is local and transparent

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🔗 Links

📝 Changelog

Version 1.1.1

  • Initial release
  • Core system information detection
  • JSON and Markdown formatters
  • Command line interface
  • Location detection support
  • Ollama integration examples

Metadata

Release files for modelsensor 1.1.1

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

Source distribution (sdist)

Source distribution for modelsensor 1.1.1
File Size Uploaded Provenance
modelsensor-1.1.1.tar.gz 15.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for modelsensor 1.1.1
File Interpreter ABI Platform
modelsensor-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 27.7 kB

Release files / modelsensor-1.1.1.tar.gz

Download URL modelsensor-1.1.1.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
219c1899d40fbbea97175d74d5ff97bb5cb1180d5311fc554b4c249f72cbae56
BLAKE2b-256 checksum
How to use checksums
5589808e6f465be07bcab4073014c37b8944d955231b2d500e5bf0bbba2bbda3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / modelsensor-1.1.1-py3-none-any.whl

Download URL modelsensor-1.1.1-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4648b9b7149199e2175dc7ddfeac7fbc93903c1155102e409d39b3963a4113b0
BLAKE2b-256 checksum
How to use checksums
eeefe58a3e5247bc6d19eccba4747fbeb1f7a93473df8c9e4f192ab89525a4e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for modelsensor 1.1.1

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.

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files No provenance

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