Skip to content

cedwardsmedia/everyoneapi.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EveryoneAPI.py v0.1.2

Source Version License Gratipay Say Thanks!

EveryoneAPI.py is a Python 3 module for querying EveryoneAPI. It is based on EveryonePHP and was written to provide a Python class for EveryoneAPI as well as a Python learning project for myself.

In order to use EveryoneAPI.py, you must have an EveryoneAPI account with available funds.

Usage

I have never been a great programmer. As such, I strived to make EveryoneAPI.py as simple to use as possible and I'm always looking to simplify it even more. Let's build a basic EveryoneAPI client using EveryoneAPI.py:

Step 1: Install Python Requests

$ pip3 install requests

Install Python Requests using pip

Step 2: Import the EveryoneAPI module and instantiate the object

# Import EveryoneAPI
import everyoneapi

Instantiate EveryoneAPI

api = everyoneapi.EveryoneAPI()

Creating a new EveryoneAPI.py object allows us to interact with the class.

### Step 3: Set EveryoneAPI Credentials
```python3
# Set EveryoneAPI Credentials
api.sid = "9e3cef42da225d42bd86feaa80ff47";
api.token = "65f3ef01462c62f7f4ce7d2156ceee";

EveryoneAPI.py needs these credentials in order to query EveryoneAPI. Otherwise, the query will fail. How you obtain and store these credentials is completely up to you, just be sure to set them for each instance of EveryoneAPI.py before calling query().

Step 4: Set EveryoneAPI Data Points

// Set EveryoneAPI Data Points
api.datapoints = ["name", "profile", "cnam", "gender", "image", "address", "location", "line_provider", "carrier", "carrier_o", "linetype"]

Each data point is optional and all data points are returned by default, unless otherwise specified. In the same way EveryoneAPI uses a comma separated list of identifiers, EveryoneAPI.py uses a simple list to specify the data points you wish to retrieve. EveryoneAPI.py passes these identifiers directly to EveryoneAPI so you will use the same identifiers here as you would in a cURL request.

For a full list of available Data Points, check the EveryoneAPI Docs.

Step 5: Perform EveryoneAPI Query

// Perform EveryoneAPI query
api.query(phone);

Only phone is required for this function. The function performs the query against EveryoneAPI and stores the results in a dict, in this example, api.results.

Step 6: Print the Results

// Print results

// Print first name
print("Name: " + api.results['data']['expanded_name']['first'])

// Print last name
print("Name: " + api.results['data']['expanded_name']['last'])

// Print carrier name
print("Name: " + api.results['data']['carrier']['name'])

EveryoneAPI.py converts the JSON response from EveryoneAPI into a dict. This allows us to access the entire response for our application. In the above example, we print the first name, last name, and carrier for the given phone number.

Optional: Error Checking

// Check for Error
if (api.error):                     // If there's an error
    print("Error: " + api.error)    // Print it out
    exit(1)                         // Exit with status 1

EveryoneAPI.py will assign error messages, if one occurs, to api.error. You can use this in an if statement, as shown above, to halt your application if something has gone wrong.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request ^^,

Credits

Concept and original codebase: Corey Edwards (@cedwardsmedia)

Optimization and Debugging: Brian Seymour (@eBrian)

License

EveryoneAPI.py is licensed under the BSD Simplified License. See LICENSE for more.


Disclaimer: EveryoneAPI.py is not endorsed by, sponsored by, or otherwise associated with OpenCNAM, EveryoneAPI, or Telo USA, Inc.