ohgo


Nameohgo JSON
Version 1.0.4 PyPI version JSON
download
home_pageNone
SummaryA wrapper for the OHGO API
upload_time2024-10-23 23:46:01
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords api cameras ohgo ohio traffic wrapper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # OHGO Wrapper

This is a python package that provides a simple interface to the [OHGO API](https://publicapi.ohgo.com/). 

## Installation
```bash
pip install ohgo
```

## Examples
### Authentication
```python
from ohgo import OHGOClient

# Register with OHGo for an API Key (https://publicapi.ohgo.com/docs/registration)
client = OHGOClient(api_key='YOUR-API-KEY')
```

### Get Cameras (default page size is 500)
```python
cameras = client.get_cameras()
```

### Get All Cameras
```python
from ohgo.models import QueryParams
params = QueryParams(page_all=True)
cameras = client.get_cameras(params=params)
```

### Get Cameras by Filter
```python
from ohgo.models import QueryParams
from ohgo.types import Region
params = QueryParams(county=Region.COLUMBUS, page_size=10, page=2)
cameras = client.get_cameras(params=params)
```

### Get Camera by ID
```python
camera = client.get_camera(camera_id='YOUR-CAMERA-ID')
```

### Get Images from Camera
```python
camera = client.get_camera(camera_id='YOUR-CAMERA-ID')
images = client.get_images(camera, "small") # Returns [ Image, Image, ... ]

# OR 
camera_view = camera.camera_views[0]
images = client.get_image(camera_view, "small") # Returns Image
```

### Other Endpoints
```python
client.get_digital_signs() # -> List[DigitalSign]
client.get_constructions() # -> List[Construction]
client.get_weather_sensor_sites() # -> List[WeatherSensorSite]
client.get_incidents() # -> List[Incident]
client.get_dangerous_slowdowns() # -> List[DangerousSlowdown]
client.get_travel_delays() # -> List[TravelDelay]
client.get_cameras() # -> List[Camera]
```

### Other Query Objects
```python
from ohgo.models import QueryParams, DigitalSignParams, ConstructionParams, WeatherSensorSiteParams
from ohgo.types import Region, SignType
import datetime
    
# Note: If you use *all* these params you will probably get no results
params = QueryParams(page_size=10, page=2, region=Region.COLUMBUS, map_bounds_sw=(39.9612, -82.9988), map_bounds_ne=(40.0150, -82.8874), radius=(39.9612, -82.9988, 10))
digital_sign_params = DigitalSignParams(sign_type=SignType.DMS)
    
# You can use string in the format 'YYYY-MM-DD', but it is recommended to use datetime objects
construction_params = ConstructionParams(include_future=datetime.datetime.now(), future_only=datetime.datetime.now())
weather_sensor_site_params = WeatherSensorSiteParams(hazards_only=True)

# All params inherit default attributes from QueryParams
```

### Cacheing Responses (ETag)
For convenience, the OHGo API supports ETag headers. If you pass an etag value in the request, 
the API will return an empty list if there are no changes since the last request. 
This can be useful for reducing the number of requests made to the API. This applies to all endpoints.

```python
cameras = client.get_cameras() # -> Technically returns CameraListResult object
etag = cameras.etag # -> Store this etag value and pass it in the next request
new_cameras = client.get_cameras(etag=etag) # -> Returns empty list if no changes since last request
cached = new_cameras.cached # -> True if the response was cached
if (cached):
    # use your original set of data
    return cameras
else:
    # use the new set of data
    return new_cameras
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ohgo",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "api, cameras, ohgo, ohio, traffic, wrapper",
    "author": null,
    "author_email": "Tom Casavant <tfcasavant@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/d5/78/8a764a1af80ed7565e0b662fa8b500b4ce2e5a30fce18525deb515936005/ohgo-1.0.4.tar.gz",
    "platform": null,
    "description": "# OHGO Wrapper\n\nThis is a python package that provides a simple interface to the [OHGO API](https://publicapi.ohgo.com/). \n\n## Installation\n```bash\npip install ohgo\n```\n\n## Examples\n### Authentication\n```python\nfrom ohgo import OHGOClient\n\n# Register with OHGo for an API Key (https://publicapi.ohgo.com/docs/registration)\nclient = OHGOClient(api_key='YOUR-API-KEY')\n```\n\n### Get Cameras (default page size is 500)\n```python\ncameras = client.get_cameras()\n```\n\n### Get All Cameras\n```python\nfrom ohgo.models import QueryParams\nparams = QueryParams(page_all=True)\ncameras = client.get_cameras(params=params)\n```\n\n### Get Cameras by Filter\n```python\nfrom ohgo.models import QueryParams\nfrom ohgo.types import Region\nparams = QueryParams(county=Region.COLUMBUS, page_size=10, page=2)\ncameras = client.get_cameras(params=params)\n```\n\n### Get Camera by ID\n```python\ncamera = client.get_camera(camera_id='YOUR-CAMERA-ID')\n```\n\n### Get Images from Camera\n```python\ncamera = client.get_camera(camera_id='YOUR-CAMERA-ID')\nimages = client.get_images(camera, \"small\") # Returns [ Image, Image, ... ]\n\n# OR \ncamera_view = camera.camera_views[0]\nimages = client.get_image(camera_view, \"small\") # Returns Image\n```\n\n### Other Endpoints\n```python\nclient.get_digital_signs() # -> List[DigitalSign]\nclient.get_constructions() # -> List[Construction]\nclient.get_weather_sensor_sites() # -> List[WeatherSensorSite]\nclient.get_incidents() # -> List[Incident]\nclient.get_dangerous_slowdowns() # -> List[DangerousSlowdown]\nclient.get_travel_delays() # -> List[TravelDelay]\nclient.get_cameras() # -> List[Camera]\n```\n\n### Other Query Objects\n```python\nfrom ohgo.models import QueryParams, DigitalSignParams, ConstructionParams, WeatherSensorSiteParams\nfrom ohgo.types import Region, SignType\nimport datetime\n    \n# Note: If you use *all* these params you will probably get no results\nparams = QueryParams(page_size=10, page=2, region=Region.COLUMBUS, map_bounds_sw=(39.9612, -82.9988), map_bounds_ne=(40.0150, -82.8874), radius=(39.9612, -82.9988, 10))\ndigital_sign_params = DigitalSignParams(sign_type=SignType.DMS)\n    \n# You can use string in the format 'YYYY-MM-DD', but it is recommended to use datetime objects\nconstruction_params = ConstructionParams(include_future=datetime.datetime.now(), future_only=datetime.datetime.now())\nweather_sensor_site_params = WeatherSensorSiteParams(hazards_only=True)\n\n# All params inherit default attributes from QueryParams\n```\n\n### Cacheing Responses (ETag)\nFor convenience, the OHGo API supports ETag headers. If you pass an etag value in the request, \nthe API will return an empty list if there are no changes since the last request. \nThis can be useful for reducing the number of requests made to the API. This applies to all endpoints.\n\n```python\ncameras = client.get_cameras() # -> Technically returns CameraListResult object\netag = cameras.etag # -> Store this etag value and pass it in the next request\nnew_cameras = client.get_cameras(etag=etag) # -> Returns empty list if no changes since last request\ncached = new_cameras.cached # -> True if the response was cached\nif (cached):\n    # use your original set of data\n    return cameras\nelse:\n    # use the new set of data\n    return new_cameras\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A wrapper for the OHGO API",
    "version": "1.0.4",
    "project_urls": {
        "Homepage": "https://github.com/TomCasavant/ohgo-wrapper",
        "Issues": "https://github.com/TomCasavant/ohgo-wrapper/issues"
    },
    "split_keywords": [
        "api",
        " cameras",
        " ohgo",
        " ohio",
        " traffic",
        " wrapper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d5788a764a1af80ed7565e0b662fa8b500b4ce2e5a30fce18525deb515936005",
                "md5": "919a2cc6bfd14ac573ea26cf1738af34",
                "sha256": "d4aa7f13f77a58911fc0898c7e2b958a72bc74a195450ccc979f590e55cc687a"
            },
            "downloads": -1,
            "filename": "ohgo-1.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "919a2cc6bfd14ac573ea26cf1738af34",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 17044,
            "upload_time": "2024-10-23T23:46:01",
            "upload_time_iso_8601": "2024-10-23T23:46:01.915404Z",
            "url": "https://files.pythonhosted.org/packages/d5/78/8a764a1af80ed7565e0b662fa8b500b4ce2e5a30fce18525deb515936005/ohgo-1.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-23 23:46:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TomCasavant",
    "github_project": "ohgo-wrapper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ohgo"
}
        
Elapsed time: 0.75384s