Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Usage
### Geocoding

```python
from geocodio import GeocodioClient
from geocodio import Geocodio

# Initialize the client with your API key
client = GeocodioClient("YOUR_API_KEY")
client = Geocodio("YOUR_API_KEY")

# Single forward geocode
response = client.geocode("1600 Pennsylvania Ave, Washington, DC")
Expand Down Expand Up @@ -59,10 +59,10 @@ print(data.results[0].fields.timezone.name if data.results[0].fields.timezone el
The List API allows you to manage lists of addresses or coordinates for batch processing.

```python
from geocodio import GeocodioClient
from geocodio import Geocodio

# Initialize the client with your API key
client = GeocodioClient("YOUR_API_KEY")
client = Geocodio("YOUR_API_KEY")

# Get all lists
lists = client.get_lists()
Expand Down Expand Up @@ -94,17 +94,17 @@ Error Handling
--------------

```python
from geocodio import GeocodioClient
from geocodio import Geocodio
from geocodio.exceptions import AuthenticationError, InvalidRequestError

try:
client = GeocodioClient("INVALID_API_KEY")
client = Geocodio("INVALID_API_KEY")
response = client.geocode("1600 Pennsylvania Ave, Washington, DC")
except AuthenticationError as e:
print(f"Authentication failed: {e}")

try:
client = GeocodioClient("YOUR_API_KEY")
client = Geocodio("YOUR_API_KEY")
response = client.geocode("") # Empty address
except InvalidRequestError as e:
print(f"Invalid request: {e}")
Expand All @@ -116,10 +116,10 @@ Geocodio Enterprise
To use this library with Geocodio Enterprise, pass `api.enterprise.geocod.io` as the `hostname` parameter when initializing the client:

```python
from geocodio import GeocodioClient
from geocodio import Geocodio

# Initialize client for Geocodio Enterprise
client = GeocodioClient(
client = Geocodio(
"YOUR_API_KEY",
hostname="api.enterprise.geocod.io"
)
Expand Down
4 changes: 2 additions & 2 deletions smoke.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from geocodio import GeocodioClient
from geocodio import Geocodio
from dotenv import load_dotenv
import os
import json
Expand All @@ -10,7 +10,7 @@
load_dotenv()

# Initialize the client with your API key
client = GeocodioClient(os.getenv("GEOCODIO_API_KEY"))
client = Geocodio(os.getenv("GEOCODIO_API_KEY"))

# Single forward geocode
print("\nSingle forward geocode:")
Expand Down
4 changes: 2 additions & 2 deletions smoke_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import time
import logging
from geocodio import GeocodioClient
from geocodio import Geocodio
from geocodio.models import ListProcessingState
from dotenv import load_dotenv

Expand Down Expand Up @@ -51,7 +51,7 @@ def main():
logger.error("GEOCODIO_API_KEY not set in environment.")
exit(1)

client = GeocodioClient(api_key)
client = Geocodio(api_key)

# Step 1: Create a list
logger.info("Creating a new list...")
Expand Down
4 changes: 2 additions & 2 deletions src/geocodio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"""

from ._version import __version__
from .client import GeocodioClient
from .client import Geocodio

__all__ = ["GeocodioClient", "__version__"]
__all__ = ["Geocodio", "__version__"]
2 changes: 1 addition & 1 deletion src/geocodio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from geocodio.exceptions import InvalidRequestError, AuthenticationError, GeocodioServerError, BadRequestError


class GeocodioClient:
class Geocodio:
BASE_PATH = "/v1.9" # keep in sync with Geocodio's current version
DEFAULT_SINGLE_TIMEOUT = 5.0
DEFAULT_BATCH_TIMEOUT = 1800.0 # 30 minutes
Expand Down
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
from dotenv import load_dotenv
import pytest
from geocodio import GeocodioClient
from geocodio import Geocodio

# Load environment variables from .env file
load_dotenv()
Expand All @@ -18,15 +18,15 @@

@pytest.fixture
def client(request):
"""Create a GeocodioClient instance with test configuration"""
"""Create a Geocodio instance with test configuration"""
# Use TEST_KEY for all tests except e2e tests
if "e2e" in request.node.fspath.strpath:
logger.debug("Running e2e tests - using API key from environment")
api_key = os.getenv("GEOCODIO_API_KEY")
if not api_key:
logger.warning("GEOCODIO_API_KEY not set - skipping e2e test")
pytest.skip("GEOCODIO_API_KEY environment variable not set")
return GeocodioClient(api_key=api_key)
return Geocodio(api_key=api_key)
else:
logger.debug("Running unit tests - using TEST_KEY with api.test hostname")
return GeocodioClient(api_key="TEST_KEY", hostname="api.test")
return Geocodio(api_key="TEST_KEY", hostname="api.test")
4 changes: 2 additions & 2 deletions tests/e2e/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import os
import pytest
from geocodio import GeocodioClient
from geocodio import Geocodio
from geocodio.exceptions import GeocodioError


Expand All @@ -15,7 +15,7 @@ def client():
api_key = os.getenv("GEOCODIO_API_KEY")
if not api_key:
pytest.skip("GEOCODIO_API_KEY environment variable not set")
return GeocodioClient(api_key)
return Geocodio(api_key)


def test_integration_geocode(client):
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/test_batch_reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import pytest
from geocodio import GeocodioClient
from geocodio import Geocodio


def test_batch_reverse_geocoding(client):
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/test_lists_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
import time
from unittest.mock import patch
from geocodio import GeocodioClient
from geocodio import Geocodio
from geocodio.models import ListResponse, PaginatedResponse, ListProcessingState
from geocodio.exceptions import GeocodioServerError
import logging
Expand All @@ -22,7 +22,7 @@ def client():
api_key = os.getenv("GEOCODIO_API_KEY")
if not api_key:
pytest.skip("GEOCODIO_API_KEY environment variable not set")
return GeocodioClient(api_key)
return Geocodio(api_key)


@pytest.fixture
Expand Down Expand Up @@ -59,8 +59,8 @@ def wait_for_list_processed(client, list_id, timeout=120):

def test_create_list(client):
"""
Test creating a list with GeocodioClient.create_list()
:param client: GeocodioClient instance
Test creating a list with Geocodio.create_list()
:param client: Geocodio instance
"""
new_list = client.create_list(file="Zip\n20003\n20001", filename="test_list.csv")

Expand All @@ -69,8 +69,8 @@ def test_create_list(client):

def test_get_list_status(client, list_response):
"""
Test retrieving the status of a list with GeocodioClient.get_list_status()
:param client: GeocodioClient instance
Test retrieving the status of a list with Geocodio.get_list_status()
:param client: Geocodio instance
:param list_response: List object created in the fixture
"""
# Get the status of the test list
Expand Down
30 changes: 15 additions & 15 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
"""
Tests for the GeocodioClient class
Tests for the Geocodio class
"""

import pytest
import httpx
from geocodio import GeocodioClient
from geocodio import Geocodio
from geocodio.exceptions import AuthenticationError


@pytest.fixture
def mock_request(mocker):
"""Mock the _request method."""
return mocker.patch('geocodio.client.GeocodioClient._request')
return mocker.patch('geocodio.client.Geocodio._request')


def test_client_initialization():
"""Test that the client can be initialized with an API key"""
client = GeocodioClient(api_key="test-key")
client = Geocodio(api_key="test-key")
assert client.api_key == "test-key"
assert client.hostname == "api.geocod.io"


def test_client_initialization_with_env_var(monkeypatch):
"""Test that the client can be initialized with an environment variable"""
monkeypatch.setenv("GEOCODIO_API_KEY", "env-key")
client = GeocodioClient()
client = Geocodio()
assert client.api_key == "env-key"


Expand All @@ -33,7 +33,7 @@ def test_client_initialization_no_key(monkeypatch):
# Ensure environment variable is not set
monkeypatch.delenv("GEOCODIO_API_KEY", raising=False)
with pytest.raises(AuthenticationError, match="No API key supplied and GEOCODIO_API_KEY is not set"):
GeocodioClient()
Geocodio()


def test_geocode_with_census_data(mock_request):
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_geocode_with_census_data(mock_request):
}]
})

client = GeocodioClient("fake-key")
client = Geocodio("fake-key")
response = client.geocode(
{"street": "1109 N Highland St", "city": "Arlington", "state": "VA"},
fields=["census2010"]
Expand Down Expand Up @@ -102,7 +102,7 @@ def test_geocode_with_acs_data(mock_request):
}]
})

client = GeocodioClient("fake-key")
client = Geocodio("fake-key")
response = client.geocode(
{"street": "1109 N Highland St", "city": "Arlington", "state": "VA"},
fields=["acs"]
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_geocode_batch_with_custom_keys(mock_request):
]
})

client = GeocodioClient("fake-key")
client = Geocodio("fake-key")
response = client.geocode({
"address1": "1109 N Highland St, Arlington, VA",
"address2": "525 University Ave, Toronto, ON, Canada"
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_geocode_with_congressional_districts(mock_request):
}]
})

client = GeocodioClient("fake-key")
client = Geocodio("fake-key")
response = client.geocode(
{"street": "1109 N Highland St", "city": "Arlington", "state": "VA"},
fields=["cd"]
Expand Down Expand Up @@ -229,7 +229,7 @@ def test_user_agent_header_in_request(mocker):
}]
})

client = GeocodioClient("test-api-key")
client = Geocodio("test-api-key")
client.geocode("1109 N Highland St, Arlington, VA")

# Verify request was made with correct headers
Expand All @@ -247,7 +247,7 @@ def test_user_agent_header_format():
"""Test that the User-Agent header has the correct format."""
from geocodio import __version__

client = GeocodioClient("test-api-key")
client = Geocodio("test-api-key")
expected_user_agent = f"geocodio-library-python/{__version__}"
assert client.USER_AGENT == expected_user_agent

Expand All @@ -262,7 +262,7 @@ def test_user_agent_header_in_batch_request(mocker):
"results": []
})

client = GeocodioClient("test-api-key")
client = Geocodio("test-api-key")
client.geocode(["Address 1", "Address 2"])

# Verify headers in batch request
Expand Down Expand Up @@ -295,7 +295,7 @@ def test_user_agent_header_in_reverse_geocode(mocker):
}]
})

client = GeocodioClient("test-api-key")
client = Geocodio("test-api-key")
client.reverse("38.886665,-77.094733")

# Verify headers in reverse geocode request
Expand All @@ -321,7 +321,7 @@ def test_user_agent_header_in_list_api(mocker):
"per_page": 10
})

client = GeocodioClient("test-api-key")
client = Geocodio("test-api-key")
client.get_lists()

# Verify headers in list API request
Expand Down
Loading