API reference¶
Clients¶
DRSClient
¶
DRSClient(
api_key: str | None = None,
*,
base_url: str = DEFAULT_BASE_URL,
timeout: float | Timeout = DEFAULT_TIMEOUT,
max_retries: int = DEFAULT_MAX_RETRIES,
http_client: Client | None = None,
)
Synchronous client for the FAA DRS API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | None
|
DRS API key. Defaults to the |
None
|
base_url
|
str
|
API root. Change only for testing. |
DEFAULT_BASE_URL
|
timeout
|
float | Timeout
|
Seconds, or an |
DEFAULT_TIMEOUT
|
max_retries
|
int
|
Retries for connection errors, timeouts, HTTP 429 and 5xx. |
DEFAULT_MAX_RETRIES
|
http_client
|
Client | None
|
Your own |
None
|
Example
list_documents
¶
list_documents(
doctype: str,
*,
offset: int = 0,
modified_after: DateLike | None = None,
sort: SortOrder | str | None = None,
filters: Filters | None = None,
keywords: Iterable[str] | str | None = None,
) -> Page
Get one page of up to 750 documents.
Without filters or keywords this calls GET /{doctype}. With them it calls
POST /{doctype}/filtered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doctype
|
str
|
Document type code, for example |
required |
offset
|
int
|
Number of documents to skip. |
0
|
modified_after
|
DateLike | None
|
Return only documents modified after this time (UTC). |
None
|
sort
|
SortOrder | str | None
|
Sort by last-modified date. |
None
|
filters
|
Filters | None
|
Metadata filters, for example |
None
|
keywords
|
Iterable[str] | str | None
|
Full-text search terms. A document matches if it has any term. |
None
|
iter_pages
¶
iter_pages(
doctype: str,
*,
offset: int = 0,
modified_after: DateLike | None = None,
sort: SortOrder | str | None = DESC,
filters: Filters | None = None,
keywords: Iterable[str] | str | None = None,
) -> Iterator[Page]
Get all pages, one request per page.
The default sort is newest-modified first, and documents with no date come last.
Paging uses offsets. With this order, an update to DRS during a long read can
repeat a document but does not skip one that did not change. A document that
changes during the read can be missed, but it is newer than the first document,
so a later read with modified_after gets it. Use sort=None for the API
default order.
iter_documents
¶
iter_documents(
doctype: str,
*,
offset: int = 0,
modified_after: DateLike | None = None,
sort: SortOrder | str | None = DESC,
filters: Filters | None = None,
keywords: Iterable[str] | str | None = None,
limit: int | None = None,
) -> Iterator[Document]
Get all matching documents. Pages are requested as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int | None
|
Stop after this many documents. |
None
|
Other arguments are the same as iter_pages.
get_attachments
¶
get_attachments(source: Document | str) -> list[Attachment]
download
¶
download(source: FileSource) -> bytes
Download a file into memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
FileSource
|
A |
required |
download_to
¶
Stream a file to disk and return its path.
If dest is an existing directory, or ends with /, the file is saved in it. The
file name comes from the document or attachment, else from the response. The write
is atomic. A partial file is never left at the destination.
AsyncDRSClient
¶
AsyncDRSClient(
api_key: str | None = None,
*,
base_url: str = DEFAULT_BASE_URL,
timeout: float | Timeout = DEFAULT_TIMEOUT,
max_retries: int = DEFAULT_MAX_RETRIES,
http_client: AsyncClient | None = None,
)
Asynchronous client for the FAA DRS API.
The methods and arguments are the same as DRSClient.
Example
list_documents
async
¶
list_documents(
doctype: str,
*,
offset: int = 0,
modified_after: DateLike | None = None,
sort: SortOrder | str | None = None,
filters: Filters | None = None,
keywords: Iterable[str] | str | None = None,
) -> Page
Get one page of up to 750 documents. See DRSClient.list_documents.
iter_pages
async
¶
iter_pages(
doctype: str,
*,
offset: int = 0,
modified_after: DateLike | None = None,
sort: SortOrder | str | None = DESC,
filters: Filters | None = None,
keywords: Iterable[str] | str | None = None,
) -> AsyncIterator[Page]
Get all pages. See DRSClient.iter_pages.
iter_documents
async
¶
iter_documents(
doctype: str,
*,
offset: int = 0,
modified_after: DateLike | None = None,
sort: SortOrder | str | None = DESC,
filters: Filters | None = None,
keywords: Iterable[str] | str | None = None,
limit: int | None = None,
) -> AsyncIterator[Document]
Get all matching documents. See DRSClient.iter_documents.
get_attachments
async
¶
get_attachments(source: Document | str) -> list[Attachment]
Get the additional attachments of a document. See DRSClient.get_attachments.
Models¶
Page
¶
Document
¶
Bases: _Model
One DRS document.
Common fields are typed attributes. Only guid is always present. Fields specific to
the document type are in metadata, keyed by their API name (for example
drs:title). The value _EMPTY_ from the API is converted to None.
Attachment
¶
Bases: _Model
An additional file attached to a document.
Document types¶
DocType
¶
catalog
¶
Document types and their metadata fields.
Source: the FAA "DRS Document Types Metadata Mapping" spreadsheet, corrected against the live API.
DocTypeInfo
dataclass
¶
DocTypeInfo(
code: str,
name: str,
service: str,
sort_field: str | None,
internal_only: bool,
fields: Mapping[str, FieldInfo],
content_fields: tuple[str, ...],
)
FieldInfo
dataclass
¶
FieldType
¶
get_doctype
¶
get_doctype(code: str) -> DocTypeInfo
Return the document type for a code.
Raises:
| Type | Description |
|---|---|
KeyError
|
The catalog does not have the code. |
find_doctype
¶
find_doctype(code: str) -> DocTypeInfo | None
Return the document type for a code, or None if the catalog does not have it.
list_doctypes
¶
list_doctypes(
*,
service: str | None = None,
include_internal: bool = False,
) -> list[DocTypeInfo]
Errors¶
UnknownFieldWarning
¶
Bases: UserWarning
A filter field is not in the catalog for its document type.
The client sends the filter anyway, because the catalog can be behind the API. If the
API does not know the field either, the request fails with BadRequestError.
InvalidQueryError
¶
Bases: DRSError, ValueError
The query fails local validation. No request was sent.
DRSTimeoutError
¶
Bases: DRSConnectionError
The request exceeded the configured timeout.