semvec/pypi-packages huggingface dataset:
Py-IP-Check 1.1.4
Get IP data

IPChecker is a simple module that can get IP info with api

	``>>> import ipcheck
	>>> data = IP('88.88.88.88')
	>>> data.country
	'Norway'
	>>> data.latitude
	59.2675699``
	

	You can use these variables

	IP
	IPtype
	continent
	continent_code
	country
	conutry_code
	region
	region_code
	city
	lat
	lon
	postal
	calling_code
	capital
	borders
	emoji
	emoji_unicode
	connection_asn
	connection_org
	connection_isp
	connection_domain
	timezone_id
	timezone_abbr
	timezone_offset
	timezone_utc
	current_time
django-stack-inspector 1.0.0
Inspect the current Python call stack to determine if the Django app is just starting up or already running.
Requires Python: >=3.9,<4.0

# Django Stack Inspector

The Django Stack Inspector package is useful to inspect the current call stack of a Django application and determine if it is starting up or already running.

It is likely that the 99% of applications do not have a need for this, but in specific niche scenarios it can be very useful. For example, when implementing a model manager that limits queries to items owned by a specific tenant by overriding the `get_queryset()` method filtered using data stored in a `ContextVar` or thread-local set by a request middleware. It may be desired that if queries are executed without the `ContextVar` being appropriately set (e.g. queries via asynchronous background workers or via admin commands) then the `get_queryset()` method fails-closed by throwing an exception warning the user that the required context is not set. However, this fail-closed behaviour breaks the management commands for migrations by throwing the exception. 

## Installation

`pip install django_stack_inspector`

## Usage

An example of how to use when creating a custom model manager to restrict queries to specific tenants.


```python
from django_stack_inspector import StackInspector

def get_queryset(self):
    """
    Override the default queryset behaviour to enforce a filter dependent on the tenant context
    The queryset will fail-closed if a query is ran without a context, either by returning no results in the
    queryset or by raising an exception.
    """
    try:
        ctx = get_request_context()
    except RequestContextNotSet as exc:
        # Context not set so fail-closed
        if StackInspector().is_app_startup():
            # Silence exception and return empty queryset as app starting (i.e. is a management command)
            return super().get_queryset().none()
        # Raise exception to alert developer
        raise exc

    # Perform filtering
    return super().get_queryset().filter(tenant=ctx.tenant)
```