Skip to content

Commit c7496a7

Browse files
committed
docs: update README with verified examples and installation instructions
- Replace fictional addresses with real, valid addresses (White House, Apple HQ) - Fix List API examples to use correct .data attribute for paginated responses - Add working error handling examples with proper exception types - Update development installation instructions to use -e flag - Improve code examples to show actual output rather than raw objects - All examples tested and verified to work with live API
1 parent 320eca4 commit c7496a7

File tree

1 file changed

+44
-62
lines changed

1 file changed

+44
-62
lines changed

README.md

Lines changed: 44 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ Development Installation
2929

3030
2. Create and activate a virtual environment:
3131
```bash
32-
python -m .venv venv
33-
source .venv/bin/activate # On Windows: venv\Scripts\activate
32+
python -m venv venv
33+
source venv/bin/activate # On Windows: venv\Scripts\activate
3434
```
3535

3636
3. Install development dependencies:
3737
```bash
38-
pip install .
39-
pip install .[dev]
38+
pip install -e .
4039
pip install -r requirements-dev.txt
4140
```
4241

@@ -52,27 +51,28 @@ from geocodio import GeocodioClient
5251
client = GeocodioClient("YOUR_API_KEY")
5352
5453
# Single forward geocode
55-
response = client.geocode("123 Anywhere St, Chicago, IL")
56-
print(response)
54+
response = client.geocode("1600 Pennsylvania Ave, Washington, DC")
55+
print(response.results[0].formatted_address)
5756
5857
# Batch forward geocode
5958
addresses = [
60-
"123 Anywhere St, Chicago, IL",
61-
"456 Oak St, Los Angeles, CA"
59+
"1600 Pennsylvania Ave, Washington, DC",
60+
"1 Infinite Loop, Cupertino, CA"
6261
]
6362
batch_response = client.geocode(addresses)
64-
print(batch_response)
63+
for result in batch_response.results:
64+
print(result.formatted_address)
6565
6666
# Single reverse geocode
6767
rev = client.reverse("38.9002898,-76.9990361")
68-
print(rev)
68+
print(rev.results[0].formatted_address)
6969
7070
# Append additional fields
7171
data = client.geocode(
72-
"123 Anywhere St, Chicago, IL",
72+
"1600 Pennsylvania Ave, Washington, DC",
7373
fields=["cd", "timezone"]
7474
)
75-
print(data)
75+
print(data.results[0].fields.timezone.name if data.results[0].fields.timezone else "No timezone data")
7676
```
7777
7878
### List API
@@ -85,68 +85,50 @@ from geocodio import GeocodioClient
8585
# Initialize the client with your API key
8686
client = GeocodioClient("YOUR_API_KEY")
8787
88-
# Create a new list
89-
new_list = client.create_list(
90-
name="My Addresses",
91-
description="A list of addresses to geocode",
92-
items=[
93-
"1600 Pennsylvania Ave, Washington, DC",
94-
"1 Infinite Loop, Cupertino, CA"
95-
]
96-
)
97-
print(new_list)
98-
9988
# Get all lists
10089
lists = client.get_lists()
101-
print(lists)
90+
print(f"Found {len(lists.data)} lists")
10291
103-
# Get a specific list
104-
list_id = new_list.list.id
105-
list_details = client.get_list(list_id)
106-
print(list_details)
107-
108-
# Update a list
109-
updated_list = client.update_list(
110-
list_id=list_id,
111-
name="Updated List Name",
112-
description="Updated description"
113-
)
114-
print(updated_list)
115-
116-
# Add items to a list
117-
added_items = client.add_items_to_list(
118-
list_id=list_id,
119-
items=[
120-
"123 Anywhere St, Chicago, IL",
121-
"456 Oak St, Los Angeles, CA"
122-
]
123-
)
124-
print(added_items)
92+
# Create a new list from a file
93+
with open("addresses.csv", "rb") as f:
94+
new_list = client.create_list(
95+
file=f,
96+
filename="addresses.csv",
97+
direction="forward"
98+
)
99+
print(f"Created list: {new_list.id}")
125100
126-
# Geocode all items in a list
127-
geocoded_list = client.geocode_list(
128-
list_id=list_id,
129-
fields=["timezone", "cd"]
130-
)
131-
print(geocoded_list)
101+
# Get a specific list
102+
list_details = client.get_list(new_list.id)
103+
print(f"List status: {list_details.status}")
132104
133-
# Remove items from a list
134-
item_ids = [item.id for item in added_items.items]
135-
client.remove_items_from_list(
136-
list_id=list_id,
137-
item_ids=item_ids
138-
)
105+
# Download a completed list
106+
if list_details.status and list_details.status.get("state") == "COMPLETED":
107+
file_content = client.download(new_list.id, "downloaded_results.csv")
108+
print("List downloaded successfully")
139109
140110
# Delete a list
141-
client.delete_list(list_id)
111+
client.delete_list(new_list.id)
142112
```
143113
144114
Error Handling
145115
--------------
146116
147-
- `GeocodioAuthError` is raised for authentication failures (HTTP 403).
148-
- `GeocodioDataError` is raised for invalid requests (HTTP 422).
149-
- `GeocodioServerError` is raised for server-side errors (HTTP 5xx).
117+
```python
118+
from geocodio import GeocodioClient, AuthenticationError, InvalidRequestError
119+
120+
try:
121+
client = GeocodioClient("INVALID_API_KEY")
122+
response = client.geocode("1600 Pennsylvania Ave, Washington, DC")
123+
except AuthenticationError as e:
124+
print(f"Authentication failed: {e}")
125+
126+
try:
127+
client = GeocodioClient("YOUR_API_KEY")
128+
response = client.geocode("") # Empty address
129+
except InvalidRequestError as e:
130+
print(f"Invalid request: {e}")
131+
```
150132
151133
Documentation
152134
-------------

0 commit comments

Comments
 (0)