Skip to content

chore: unreleased changes #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 1, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__
dist

.env
codegen.log
47 changes: 26 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ pip install finch-api
```python
from finch import Finch

finch = Finch(
client = Finch(
access_token="my access token",
)

candidate = finch.ats.candidates.retrieve(
candidate = client.ats.candidates.retrieve(
"<candidate id>",
)
print(candidate.first_name)
Expand All @@ -38,13 +38,13 @@ Simply import `AsyncFinch` instead of `Finch` and use `await` with each API call
```python
from finch import AsyncFinch

finch = AsyncFinch(
client = AsyncFinch(
access_token="my access token",
)


async def main():
candidate = await finch.ats.candidates.retrieve(
candidate = await client.ats.candidates.retrieve(
"<candidate id>",
)
print(candidate.first_name)
Expand All @@ -70,11 +70,11 @@ This library provides auto-paginating iterators with each list response, so you
```python
import finch

finch = Finch()
client = Finch()

all_jobs = []
# Automatically fetches more pages as needed.
for job in finch.ats.jobs.list():
for job in client.ats.jobs.list():
# Do something with job here
all_jobs.append(job)
print(all_jobs)
Expand All @@ -86,13 +86,13 @@ Or, asynchronously:
import asyncio
import finch

finch = AsyncFinch()
client = AsyncFinch()


async def main() -> None:
all_jobs = []
# Iterate through items across all pages, issuing requests as needed.
async for job in finch.ats.jobs.list():
async for job in client.ats.jobs.list():
all_jobs.append(job)
print(all_jobs)

Expand All @@ -103,7 +103,7 @@ asyncio.run(main())
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:

```python
first_page = await finch.ats.jobs.list()
first_page = await client.ats.jobs.list()
if first_page.has_next_page():
print(f"will fetch next page using these details: {first_page.next_page_info()}")
next_page = await first_page.get_next_page()
Expand All @@ -115,7 +115,7 @@ if first_page.has_next_page():
Or just work directly with the returned data:

```python
first_page = await finch.ats.jobs.list()
first_page = await client.ats.jobs.list()

print(
f"the current start offset for this page: {first_page.paging.offset}"
Expand All @@ -133,9 +133,9 @@ Nested parameters are dictionaries, typed using `TypedDict`, for example:
```python
from finch import Finch

finch = Finch()
client = Finch()

finch.hris.directory.list_individuals(
client.hris.directory.list_individuals(
path_params=[],
params={},
)
Expand All @@ -151,12 +151,13 @@ response), a subclass of `finch.APIStatusError` will be raised, containing `stat
All errors inherit from `finch.APIError`.

```python
import finch
from finch import Finch

finch = Finch()
client = Finch()

try:
finch.hris.directory.list_individuals()
client.hris.directory.list_individuals()
except finch.APIConnectionError as e:
print("The server could not be reached")
print(e.__cause__) # an underlying Exception, likely raised within httpx.
Expand Down Expand Up @@ -193,13 +194,13 @@ You can use the `max_retries` option to configure or disable this:
from finch import Finch

# Configure the default for all requests:
finch = Finch(
client = Finch(
# default is 2
max_retries=0,
)

# Or, configure per-request:
finch.with_options(max_retries=5).hris.directory.list_individuals()
client.with_options(max_retries=5).hris.directory.list_individuals()
```

### Timeouts
Expand All @@ -211,18 +212,18 @@ which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advan
from finch import Finch

# Configure the default for all requests:
finch = Finch(
client = Finch(
# default is 60s
timeout=20.0,
)

# More granular control:
finch = Finch(
client = Finch(
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
)

# Override per-request:
finch.with_options(timeout=5 * 1000).hris.directory.list_individuals()
client.with_options(timeout=5 * 1000).hris.directory.list_individuals()
```

On timeout, an `APITimeoutError` is thrown.
Expand All @@ -240,7 +241,7 @@ Be aware that doing so may result in incorrect types and other unexpected or und
```python
from finch import Finch

finch = Finch(
client = Finch(
default_headers={"Finch-API-Version": "My-Custom-Value"},
)
```
Expand All @@ -253,7 +254,7 @@ You can configure the following keyword arguments when instantiating the client:
import httpx
from finch import Finch

finch = Finch(
client = Finch(
# Use a custom base URL
base_url="http://my.test.server.example.com:8083",
proxies="http://my.test.proxy.example.com",
Expand All @@ -263,6 +264,10 @@ finch = Finch(

See the httpx documentation for information about the [`proxies`](https://www.python-httpx.org/advanced/#http-proxying) and [`transport`](https://www.python-httpx.org/advanced/#custom-transports) keyword arguments.

## Advanced: Managing HTTP resources

By default we will close the underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__) is called but you can also manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.

## Status

This package is in beta. Its internals and interfaces are not stable and subject to change without a major semver bump;
Expand Down
96 changes: 48 additions & 48 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ distro = ">= 1.7.0, < 2"


[tool.poetry.group.dev.dependencies]
pyright = "1.1.297"
pyright = "1.1.318"
mypy = "1.1.1"
black = "22.10.0"
respx = "0.19.2"
Expand Down
Loading