Skip to main content

python-safer

PyPI version

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.

Here is how you search for companies using python-safer

from safer import CompanySnapshot

client = CompanySnapshot()

results = client.search('python')
for company in results:
    print(company)
<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>
company = results[0].get_company_snapshot()
print(company.legal_name)
PYTHON CORPORATION

Todo

  • Write some tests.

Issues

If there are any problems, just open issue.

Installation

Prerequisites

lxml - the C bindings are needed as well. Just follow the installation instructions, should be fine.

Install using pip
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

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()

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.

company = client.get_by_usdot_number(698887)
print(company.to_json())
{
  "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.

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

Company Object Properties

company.legal_name
'PYTHON CORPORATION'
company.drivers
7
company.power_units
8
company.phone_number
'(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.

Metadata

Release files for python-safer 2.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 python-safer 2.0
File Size Uploaded Provenance Actions
python_safer-2.0.tar.gz 10.7 kB Without provenance Details for python_safer-2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-safer 2.0
File Interpreter ABI Platform Actions
python_safer-2.0-py3-none-any.whl Python 3 none any Details for python_safer-2.0-py3-none-any.whl

Total release size: 22.8 kB

Release files / python_safer-2.0.tar.gz

Download URL python_safer-2.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0f88dddf00d876fb19aeb9418be95f0bdedf93fdff0c365f2001fcfca657e210
BLAKE2b-256 checksum
How to use checksums
dcd85e1583b6bba885fe47850a160ea16c0938f70e694e7ec53e79eeadaa93da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Release files / python_safer-2.0-py3-none-any.whl

Download URL python_safer-2.0-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
357959da82eb45e54dadaa90ab6b8c7bcb49df8caf48303202ffd6debc91ecc8
BLAKE2b-256 checksum
How to use checksums
9a0254977fa8224e521073bed62d2b90b65dbf3d750b14a41a847df8617347de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Security for python-safer 2.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