python-safer


Namepython-safer JSON
Version 1.5 PyPI version JSON
download
home_pagehttps://github.com/arthurtyukayev/python-safer
SummaryA web scraping API written in Python to fetch data from the Department of Transportation's Safety and Fitness Electronic Records System http://www.safersys.org/
upload_time2023-10-24 20:11:34
maintainer
docs_urlNone
authorArthur Tyukayev
requires_python
licenseMIT
keywords safer safer department transportation fitness electronic records system
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # python-safer
[![PyPI version](https://badge.fury.io/py/python-safer.svg)](https://badge.fury.io/py/python-safer)

python-safer is an web scraping API wrapper written in Python to fetch data from the [Department of Transportation's Safety and Fitness Electronic Records System](https://safer.fmcsa.dot.gov/CompanySnapshot.aspx).

### If you plan to use this package in any capacity, it's highly recommended to cache all of the results you get from the SAFER website. The SAFER website is highly unreliable and will randomly go down.

Here is how you search for companies using python-safer

```python
from safer import CompanySnapshot

client = CompanySnapshot()

results = client.search('python')
for company in results:
    print(company)
```

```console
<SearchResult PYTHON CORPORATION (698887) from  Lacombe, LA>
<SearchResult PYTHON PRESSURE PUMPING LLC (2346443) from  Ada, OK>
<SearchResult PYTHON SERVICES LLC (918670) from  Brighton, CO>
<SearchResult PYTHON TRANSPORT CORP (2379682) from  Dania Beach, FL>
<SearchResult PYTHON TRANSPORTS LLC (2642177) from  Fort Worth, TX>
<SearchResult PYTHON'S OF ST CLOUD INC (604262) from  St Cloud, MN>
```

```python
company = results[0].get_company_snapshot()
print(company.legal_name)
```
```console
PYTHON CORPORATION
```


### Todo

- Write some tests.

### Issues

If there are any problems, just open issue.

### Installation

##### Prerequisites
[lxml](http://lxml.de) - the C bindings are needed as well. Just follow the installation instructions, should be fine.
##### Install using pip

```python
pip install python-safer
```

### Usage

This was written with Python 3.5, but it will probably work for any Python 3 version

**Be prepared to wait for results, the SAFER CompanySnapshot website is very slow, and half the time it's down.**

**Import and create CompanySnapshot**
```python
from safer import CompanySnapshot

client = CompanySnapshot()
```

**Search by Name**

Searching by name will return a SearchResultSet object that can be iterated through,
each item in the SearchResultSet is a SearchResult object, to get the Company Snapshot of that object
you can call `get_company_snapshot()`
```python
for company in client.search('python'):
    company.get_company_snapshot()
```
Getting the company snapshot will return a Company Object.

**Search by USDOT Number**

Searching by USDOT will return a Company object or raise a `CompanySnapshotNotFoundException` exception for that USDOT.

```python
company = client.get_by_usdot_number(698887)
print(company.to_json())
```
```console
{
  "operation_classification": [
    "Private(Property)"
  ],
  "physical_address": "29279 HWY 190 LACOMBE, LA  70445",
  "united_states_inspections": {
    "hazmat": {
      "out_of_service": "0",
      "inspections": "0",
      "out_of_service_percent": "0%",
      "national_average": "4.50%"
    },
    "driver": {
      "out_of_service": "0",
      "inspections": "0",
      "out_of_service_percent": "0%",
      "national_average": "5.51%"
    },
    "iep": {
      "out_of_service": 0,
      "inspections": 0,
      "out_of_service_percent": "0%",
      "national_average": "N/A"
    },
    "vehicle": {
      "out_of_service": "0",
      "inspections": "0",
      "out_of_service_percent": "0%",
      "national_average": "20.72%"
    }
  },
  "state_carrier_id": "",
  "mc_mx_ff_numbers": null,
  "out_of_service_date": null,
  "mcs_150_form_date": "05/13/2016",
  "safety_rating": null,
  "carrier_operation": [
    "Interstate"
  ],
  "hm_shipper_operation": null,
  "safety_review_date": null,
  "canada_crashes": {
    "injury": 0,
    "total": 0,
    "fatal": 0,
    "tow": 0
  },
  "mcs_150_mileage_year": {
    "year": 2015,
    "mileage": 200000
  },
  "mailing_address": "PO BOX 790 LACOMBE, LA  70445",
  "power_units": 8,
  "dba_name": "",
  "entity_type": "CARRIER",
  "safety_rating_date": null,
  "safety_type": null,
  "duns_number": null,
  "drivers": 7,
  "us_inspections": {
    "hazmat": {
      "out_of_service": 0,
      "inspections": 0,
      "out_of_service_percent": "0%",
      "national_average": "4.50%"
    },
    "vehicle": {
      "out_of_service": 0,
      "inspections": 0,
      "out_of_service_percent": "0%",
      "national_average": "20.72%"
    },
    "iep": {
      "out_of_service": 0,
      "inspections": 0,
      "out_of_service_percent": "0%",
      "national_average": "N/A"
    },
    "driver": {
      "out_of_service": 0,
      "inspections": 0,
      "out_of_service_percent": "0%",
      "national_average": "5.51%"
    }
  },
  "united_states_crashes": {
    "injury": 0,
    "total": 0,
    "fatal": 0,
    "tow": 0
  },
  "phone": "(985) 882-6101",
  "usdot": "698887",
  "url": "http://www.safersys.org/query.asp?searchtype=ANY&query_type=queryCarrierSnapshot&query_param=USDOT&original_query_param=NAME&query_string=698887",
  "legal_name": "PYTHON CORPORATION",
  "latest_update": "09/12/2017",
  "cargo_carried": [
    "Building Materials"
  ],
  "operating_status": "ACTIVE",
  "canada_inspections": {
    "vehicle": {
      "out_of_service": 0,
      "inspections": 0,
      "out_of_service_percent": "0%"
    },
    "driver": {
      "out_of_service": 0,
      "inspections": 0,
      "out_of_service_percent": "0%"
    }
  }
}
```

**Viewing Company Snapshots in a web browser**

Using the `open_url()` function on a Company object, will open the Company Snapshot on the SAFER website.

```python
company = client.get_by_usdot_number(698887)
company.open_url()
```

**Company Object Properties**
```python
company.legal_name
```
```console
'PYTHON CORPORATION'
```
```python
company.drivers
```
```console
7
```
```python
company.power_units
```
```console
8
```
```python
company.phone_number
```
```console
'(985) 882-6101'
```

There is more, just look at the source code. However all values that are shown on the Company Snapshot website are available in the Company class.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/arthurtyukayev/python-safer",
    "name": "python-safer",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "SAFER safer department transportation fitness electronic records system",
    "author": "Arthur Tyukayev",
    "author_email": "arthurtyukayev@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/bd/fb/351f000c79a7190ee087ee5109ba70953171d9ea551cb73e155390121d33/python-safer-1.5.tar.gz",
    "platform": null,
    "description": "# python-safer\n[![PyPI version](https://badge.fury.io/py/python-safer.svg)](https://badge.fury.io/py/python-safer)\n\npython-safer is an web scraping API wrapper written in Python to fetch data from the [Department of Transportation's Safety and Fitness Electronic Records System](https://safer.fmcsa.dot.gov/CompanySnapshot.aspx).\n\n### If you plan to use this package in any capacity, it's highly recommended to cache all of the results you get from the SAFER website. The SAFER website is highly unreliable and will randomly go down.\n\nHere is how you search for companies using python-safer\n\n```python\nfrom safer import CompanySnapshot\n\nclient = CompanySnapshot()\n\nresults = client.search('python')\nfor company in results:\n    print(company)\n```\n\n```console\n<SearchResult PYTHON CORPORATION (698887) from  Lacombe, LA>\n<SearchResult PYTHON PRESSURE PUMPING LLC (2346443) from  Ada, OK>\n<SearchResult PYTHON SERVICES LLC (918670) from  Brighton, CO>\n<SearchResult PYTHON TRANSPORT CORP (2379682) from  Dania Beach, FL>\n<SearchResult PYTHON TRANSPORTS LLC (2642177) from  Fort Worth, TX>\n<SearchResult PYTHON'S OF ST CLOUD INC (604262) from  St Cloud, MN>\n```\n\n```python\ncompany = results[0].get_company_snapshot()\nprint(company.legal_name)\n```\n```console\nPYTHON CORPORATION\n```\n\n\n### Todo\n\n- Write some tests.\n\n### Issues\n\nIf there are any problems, just open issue.\n\n### Installation\n\n##### Prerequisites\n[lxml](http://lxml.de) - the C bindings are needed as well. Just follow the installation instructions, should be fine.\n##### Install using pip\n\n```python\npip install python-safer\n```\n\n### Usage\n\nThis was written with Python 3.5, but it will probably work for any Python 3 version\n\n**Be prepared to wait for results, the SAFER CompanySnapshot website is very slow, and half the time it's down.**\n\n**Import and create CompanySnapshot**\n```python\nfrom safer import CompanySnapshot\n\nclient = CompanySnapshot()\n```\n\n**Search by Name**\n\nSearching by name will return a SearchResultSet object that can be iterated through,\neach item in the SearchResultSet is a SearchResult object, to get the Company Snapshot of that object\nyou can call `get_company_snapshot()`\n```python\nfor company in client.search('python'):\n    company.get_company_snapshot()\n```\nGetting the company snapshot will return a Company Object.\n\n**Search by USDOT Number**\n\nSearching by USDOT will return a Company object or raise a `CompanySnapshotNotFoundException` exception for that USDOT.\n\n```python\ncompany = client.get_by_usdot_number(698887)\nprint(company.to_json())\n```\n```console\n{\n  \"operation_classification\": [\n    \"Private(Property)\"\n  ],\n  \"physical_address\": \"29279 HWY 190 LACOMBE, LA  70445\",\n  \"united_states_inspections\": {\n    \"hazmat\": {\n      \"out_of_service\": \"0\",\n      \"inspections\": \"0\",\n      \"out_of_service_percent\": \"0%\",\n      \"national_average\": \"4.50%\"\n    },\n    \"driver\": {\n      \"out_of_service\": \"0\",\n      \"inspections\": \"0\",\n      \"out_of_service_percent\": \"0%\",\n      \"national_average\": \"5.51%\"\n    },\n    \"iep\": {\n      \"out_of_service\": 0,\n      \"inspections\": 0,\n      \"out_of_service_percent\": \"0%\",\n      \"national_average\": \"N/A\"\n    },\n    \"vehicle\": {\n      \"out_of_service\": \"0\",\n      \"inspections\": \"0\",\n      \"out_of_service_percent\": \"0%\",\n      \"national_average\": \"20.72%\"\n    }\n  },\n  \"state_carrier_id\": \"\",\n  \"mc_mx_ff_numbers\": null,\n  \"out_of_service_date\": null,\n  \"mcs_150_form_date\": \"05/13/2016\",\n  \"safety_rating\": null,\n  \"carrier_operation\": [\n    \"Interstate\"\n  ],\n  \"hm_shipper_operation\": null,\n  \"safety_review_date\": null,\n  \"canada_crashes\": {\n    \"injury\": 0,\n    \"total\": 0,\n    \"fatal\": 0,\n    \"tow\": 0\n  },\n  \"mcs_150_mileage_year\": {\n    \"year\": 2015,\n    \"mileage\": 200000\n  },\n  \"mailing_address\": \"PO BOX 790 LACOMBE, LA  70445\",\n  \"power_units\": 8,\n  \"dba_name\": \"\",\n  \"entity_type\": \"CARRIER\",\n  \"safety_rating_date\": null,\n  \"safety_type\": null,\n  \"duns_number\": null,\n  \"drivers\": 7,\n  \"us_inspections\": {\n    \"hazmat\": {\n      \"out_of_service\": 0,\n      \"inspections\": 0,\n      \"out_of_service_percent\": \"0%\",\n      \"national_average\": \"4.50%\"\n    },\n    \"vehicle\": {\n      \"out_of_service\": 0,\n      \"inspections\": 0,\n      \"out_of_service_percent\": \"0%\",\n      \"national_average\": \"20.72%\"\n    },\n    \"iep\": {\n      \"out_of_service\": 0,\n      \"inspections\": 0,\n      \"out_of_service_percent\": \"0%\",\n      \"national_average\": \"N/A\"\n    },\n    \"driver\": {\n      \"out_of_service\": 0,\n      \"inspections\": 0,\n      \"out_of_service_percent\": \"0%\",\n      \"national_average\": \"5.51%\"\n    }\n  },\n  \"united_states_crashes\": {\n    \"injury\": 0,\n    \"total\": 0,\n    \"fatal\": 0,\n    \"tow\": 0\n  },\n  \"phone\": \"(985) 882-6101\",\n  \"usdot\": \"698887\",\n  \"url\": \"http://www.safersys.org/query.asp?searchtype=ANY&query_type=queryCarrierSnapshot&query_param=USDOT&original_query_param=NAME&query_string=698887\",\n  \"legal_name\": \"PYTHON CORPORATION\",\n  \"latest_update\": \"09/12/2017\",\n  \"cargo_carried\": [\n    \"Building Materials\"\n  ],\n  \"operating_status\": \"ACTIVE\",\n  \"canada_inspections\": {\n    \"vehicle\": {\n      \"out_of_service\": 0,\n      \"inspections\": 0,\n      \"out_of_service_percent\": \"0%\"\n    },\n    \"driver\": {\n      \"out_of_service\": 0,\n      \"inspections\": 0,\n      \"out_of_service_percent\": \"0%\"\n    }\n  }\n}\n```\n\n**Viewing Company Snapshots in a web browser**\n\nUsing the `open_url()` function on a Company object, will open the Company Snapshot on the SAFER website.\n\n```python\ncompany = client.get_by_usdot_number(698887)\ncompany.open_url()\n```\n\n**Company Object Properties**\n```python\ncompany.legal_name\n```\n```console\n'PYTHON CORPORATION'\n```\n```python\ncompany.drivers\n```\n```console\n7\n```\n```python\ncompany.power_units\n```\n```console\n8\n```\n```python\ncompany.phone_number\n```\n```console\n'(985) 882-6101'\n```\n\nThere is more, just look at the source code. However all values that are shown on the Company Snapshot website are available in the Company class.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A web scraping API written in Python to fetch data from the Department of Transportation's Safety and Fitness Electronic Records System http://www.safersys.org/",
    "version": "1.5",
    "project_urls": {
        "Homepage": "https://github.com/arthurtyukayev/python-safer"
    },
    "split_keywords": [
        "safer",
        "safer",
        "department",
        "transportation",
        "fitness",
        "electronic",
        "records",
        "system"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "14c04114a1c6505f3e0982565b9ec2a68ebb505c4122d6f2cf19e618d610054c",
                "md5": "4dc3178fa5901744fd5a0744aebedea7",
                "sha256": "ddb19a3cc98db2506f8ff0b6cf0fa510269c515981c30b5b1222579befbc0c00"
            },
            "downloads": -1,
            "filename": "python_safer-1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4dc3178fa5901744fd5a0744aebedea7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11972,
            "upload_time": "2023-10-24T20:11:33",
            "upload_time_iso_8601": "2023-10-24T20:11:33.111197Z",
            "url": "https://files.pythonhosted.org/packages/14/c0/4114a1c6505f3e0982565b9ec2a68ebb505c4122d6f2cf19e618d610054c/python_safer-1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bdfb351f000c79a7190ee087ee5109ba70953171d9ea551cb73e155390121d33",
                "md5": "ac3764e4ba375199dd1c826060511303",
                "sha256": "3393fa85b0e02e84c09d2e755e44a5499f87667a70a1f5511358921fa51158e1"
            },
            "downloads": -1,
            "filename": "python-safer-1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "ac3764e4ba375199dd1c826060511303",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10408,
            "upload_time": "2023-10-24T20:11:34",
            "upload_time_iso_8601": "2023-10-24T20:11:34.512454Z",
            "url": "https://files.pythonhosted.org/packages/bd/fb/351f000c79a7190ee087ee5109ba70953171d9ea551cb73e155390121d33/python-safer-1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-24 20:11:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "arthurtyukayev",
    "github_project": "python-safer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "python-safer"
}
        
Elapsed time: 1.82068s