API reference¶
This page documents the public surface exposed at the top of the restgdf
namespace: the FeatureLayer and Directory
entry points, the ArcGISTokenSession wrapper, and the
migration helpers in restgdf.compat.
The pydantic response models (LayerMetadata, FeaturesResponse,
CrawlReport and friends) live on Pydantic models. Internal utility modules
are on Utilities.
FeatureLayer¶
- class restgdf.FeatureLayer(url, session, where='1=1', token=None, **kwargs)[source]¶
Bases:
objectA class for interacting with an ArcGIS REST FeatureLayer.
- Variables:
metadata (
restgdf.LayerMetadata) – Pydantic-validated layer metadata (name, fields, max record count, advanced query capabilities, …). Replaces the pre-2.0 rawdict. Extra keys sent by the server are preserved viaextra="allow"and reachable throughmetadata.model_extra.name (
str) – Convenience alias formetadata.name.fields (
tuple[str,]) – Field names consumed by restgdf.object_id_field (
str) – Resolved object-id field name ("OBJECTID"when the server omits it).count (
int) – Feature count, validated viaCountResponseat prep time.
- async row_dict_generator(**kwargs)[source]¶
Asynchronously yield rows from a GeoDataFrame as dictionaries.
- async getoids()[source]¶
Deprecated alias for
get_oids().
- async samplegdf(n=10)[source]¶
Deprecated alias for
sample_gdf().
- async headgdf(n=10)[source]¶
Deprecated alias for
head_gdf().
- async getuniquevalues(fields, sortby=None)[source]¶
Deprecated alias for
get_unique_values().
- async getvaluecounts(field)[source]¶
Deprecated alias for
get_value_counts().
- async getnestedcount(fields)[source]¶
Deprecated alias for
get_nested_count().
Directory¶
- class restgdf.Directory(url, session, token=None)[source]¶
Bases:
objectA class for interacting with ArcGIS Server directories.
- Variables:
metadata (
Optional[restgdf.LayerMetadata]) – Pydantic-validated root metadata populated byprep().Noneuntilprep(orfrom_url()) has run.services (
Optional[list[restgdf.CrawlServiceEntry]]) – Services discovered by the most recentcrawl()call. Each entry carriesname,url,type, and a parsedmetadata(LayerMetadataorNoneif that service’s metadata call failed).services_with_feature_count (
Optional[list[restgdf.CrawlServiceEntry]]) – Same asservicesbut populated with feature counts whencrawl()was invoked withreturn_feature_count=True.report (
Optional[restgdf.CrawlReport]) – The full crawl report (services + per-stage errors + root metadata) from the most recentcrawl()call. Use this when you need to inspect failures that were silently captured instead of raised.
Token session¶
- class restgdf.ArcGISTokenSession(session, credentials=None, token_url='https://www.arcgis.com/sharing/rest/generateToken', token_refresh_threshold=60, token=None, expires=None, verify_ssl=True, config=None)[source]¶
Bases:
objectWrap an aiohttp session with ArcGIS token refresh behavior.
Construction knobs (
token_url,token_refresh_threshold,credentials) are validated viaTokenSessionConfigin__post_init__()so a bogus scheme or zero-length username fails fast withRestgdfResponseErrorrather than surfacing as a 401 or anaiohttperror deep in the request path.- session: ClientSession¶
- credentials: AGOLUserPass | None = None¶
- config: TokenSessionConfig | None = None¶
- update_dict(input_dict=None)[source]¶
Return a request payload/query dict merged with the active token.
- async update_token()[source]¶
Update the token by making a request to the token URL.
The
/generateTokenpayload is validated againstTokenResponse(strict tier) so malformed/error envelopes raiseRestgdfResponseErrorinstead ofKeyErrordeep in caller code paths.
Errors¶
- exception restgdf.RestgdfResponseError(message, *, model_name, context, raw)[source]¶
Bases:
ValueErrorRaised when a strict-tier ArcGIS response fails validation.
- Variables:
model_name – The pydantic model class name that rejected the payload (for example
"CountResponse").context – A short identifier describing where the response came from (for example the request URL or a helper name). Used by operators triaging ArcGIS vendor variance.
raw – The raw JSON-decoded payload that failed validation. Kept on the exception so callers can log or re-raise without re-reading the response body.
Runtime settings¶
See Pydantic models for the Settings model; the helpers below
read it from the environment.
Migration helpers¶
Compatibility helpers for the 1.x → 2.x migration.
Downstream code that indexed the legacy dict-based public surface (for
example metadata["name"], crawl_result["services"]) needs a
short-term way to keep working during its own upgrade window. These
helpers convert the 2.x pydantic models back into plain Python
structures on demand.
They are migration aids, not the primary API — prefer direct
attribute access (metadata.name) and model_dump() in new code.
These helpers will stay available for the 2.x series but may be removed
in 3.x.
- restgdf.compat.as_dict(obj)[source]¶
Return a plain Python dict view of a restgdf pydantic model.
If
objis apydantic.BaseModelinstance, returnsobj.model_dump(mode="python", by_alias=False)— a dict keyed by the model’s Python (snake_case) field names, with nested models also recursively dumped.If
objis anything else (already-a-dict,None, primitive, list), it is returned unchanged. This lets migration code wrap heterogeneous values uniformly:for entry in report.services: row = as_dict(entry) # dict whether entry is model or already dict save(row["name"], row.get("url"))
This helper is intentionally conservative: it does not recurse into containers of models and does not coerce
by_alias=True. Callers that need the ArcGIS-native camelCase round-trip should callmodel_dump()explicitly.
- restgdf.compat.as_json_dict(obj)[source]¶
Return a JSON-safe dict view of a restgdf pydantic model.
Like
as_dict(), but usesmodel_dump(mode="json")so every nested value is a JSON-serializable primitive (SecretStr→"**********"placeholder,datetime→ ISO string, etc.). Handy for structured logging of a model without carrying unserializable objects into the log record.Non-model values are returned unchanged.