Titiler

Latest version: v0.18.2

Safety actively analyzes 630052 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 15 of 16

0.1.0alpha.6

* refactor CacheControl Middleware
* rename headers value `X-Server-Timings` to `Server-Timing`.
* add `total;dur={}` in response header `Server-Timing`, using new `titiler.middleware.TotalTimeMiddleware` middleware (113)

python
from titiler.middleware import CacheControlMiddleware, TotalTimeMiddleware
from fastapi import FastAPI

app.add_middleware(CacheControlMiddleware, cachecontrol="public, max-age=3600")
app.add_middleware(TotalTimeMiddleware)


* Add Brotli compression support (126, author kylebarron)
* Numerous fix to CDK app.py (co-author kylebarron)

0.1.0alpha.5

* exclude `tests/` an `stack/` in titiler python package.
* add `EPSG6933` in TMS

**breaking changes**
* [FACTORY] the `additional_dependency` should be a Callable which return a dict.

python
dataclass type: ignore
class BaseFactory(metaclass=abc.ABCMeta):
"""BaseTiler Factory."""
...
provide custom dependency
additional_dependency: Callable[..., Dict] = field(default=lambda: dict())


python
def AssetsParams(
assets: Optional[str] = Query(
None,
title="Asset indexes",
description="comma (',') delimited asset names (might not be an available options of some readers)",
)
) -> Dict:
"""Assets Dependency."""
kwargs = {}
if assets:
kwargs["assets"] = assets.split(",")
return kwargs

* [FACTORY] remove `_` prefix in factory methods (e.g `_tile` -> `tile`)
* [FACTORY] refactor dependencies to better align with rio_tiler.io.BaseReader method definition.

Example:

In the `metadata`, the `MetadataParams` will be used to pass `pmin` and `pmax` because they are the only
required parameters for the metadata method. All other params will be passed to a `kwargs` dict.

python
dataclass
class MetadataParams(DefaultDependency):
"""Common Metadada parameters."""
Required params
pmin: float = Query(2.0, description="Minimum percentile")
pmax: float = Query(98.0, description="Maximum percentile")
Optional parameters
bidx: Optional[str] = Query(
None, title="Band indexes", description="comma (',') delimited band indexes",
)
...
def __post_init__(self):
"""Post Init."""

if self.bidx is not None:
self.kwargs["indexes"] = tuple(
int(s) for s in re.findall(r"\d+", self.bidx)
)
...

metadata method in factory
def metadata(
src_path=Depends(self.path_dependency),
metadata_params=Depends(self.metadata_dependency),
kwargs: Dict = Depends(self.additional_dependency),
):
"""Return metadata."""
reader = src_path.reader or self.reader
with reader(src_path.url, **self.reader_options) as src_dst:
info = src_dst.metadata(
metadata_params.pmin,
metadata_params.pmax,
**metadata_params.kwargs,
**kwargs,
)
return info

* [FACTORY] refactor dependencies definition
python
dataclass type: ignore
class BaseFactory(metaclass=abc.ABCMeta):
"""BaseTiler Factory."""

reader: default_readers_type = field(default=COGReader)
reader_options: Dict = field(default_factory=dict)

FastAPI router
router: APIRouter = field(default_factory=APIRouter)

Path Dependency
path_dependency: Type[PathParams] = field(default=PathParams)

Rasterio Dataset Options (nodata, unscale, resampling)
dataset_dependency: default_deps_type = field(default=DatasetParams)

Indexes/Expression Dependencies
layer_dependency: default_deps_type = field(default=BidxExprParams)

Image rendering Dependencies
render_dependency: default_deps_type = field(default=RenderParams)

TileMatrixSet dependency
tms_dependency: Callable[..., TileMatrixSet] = WebMercatorTMSParams

provide custom dependency
additional_dependency: Callable[..., Dict] = field(default=lambda: dict())


* remove `PathParams.reader` attribute. This option was not used and would have been technically difficult to use.
python
dataclass
class PathParams:
"""Create dataset path from args"""

url: str = Query(..., description="Dataset URL")

0.1.0alpha.4

* Update `.npy` output format to follow the numpyTile format (103)

python
import numpy
import requests
from io import BytesIO

endpoint = ...
url = "https://opendata.digitalglobe.com/events/mauritius-oil-spill/post-event/2020-08-12/105001001F1B5B00/105001001F1B5B00.tif"

r = requests.get(f"{endpoint}/cog/tiles/14/10818/9146.npy",
params = {
"url": url,
}
)
data = numpy.load(BytesIO(r.content))
print(data.shape)
> (4, 256, 256)


* Add `titiler.custom.routing.apiroute_factory`. This function enable the creation of custom fastapi.routing.APIRoute class with `rasterio.Env()` block.

python
from fastapi import FastAPI, APIRouter
from rasterio._env import get_gdal_config
from titiler.custom.routing import apiroute_factory

app = FastAPI()
route_class = apiroute_factory({"GDAL_DISABLE_READDIR_ON_OPEN": "FALSE"})
router = APIRouter(route_class=route_class)

router.get("/simple")
def simple():
"""should return FALSE."""
res = get_gdal_config("GDAL_DISABLE_READDIR_ON_OPEN")
return {"env": res}

app.include_router(router)


Note: This has only be tested for python 3.6 and 3.7.

0.1.0alpha.3

* add custom `url_for` method in TilerFactory to retrieve `prefixed` endpoint URL (95)
* remove magic `titiler.dependencies.PathParams` mosaicid path translation, where a user could pass `url=mosaicid://` to the endpoint.
* switch to `pydantic.BaseSettings` for FastAPI application setting management.

List of Settings:

python
name: str = "titiler"
cors_origins: str = "*"
cachecontrol: str = "public, max-age=3600"


API Settings can now be set by adding a `.env` file in your local project or by setting environment variables (e.g `API_CORS_ORIGIN="https://mywebsite.com/*"`)

0.1.0alpha.2

* add Transform and CRS information in `/part` GeoTIFF output
* pin **rio-tiler-crs** to `>=3.0b4,<3.1` and **cogeo-mosaic** to `>=3.0a10,<3.1`

0.1.0alpha.1

* rename titiler.models.cog.py to titiler.models.dataset.py
* remove cog* prefix to Bounds, Info and Metadata models
* allow Union[str, int] for key in Metadata.statistics (as defined in rio-tiler-pds)

e.g Create a Landsat 8 Tiler
python
from titiler.endpoints.factory import TilerFactory, MosaicTilerFactory
from titiler.dependencies import BandsParams

from rio_tiler_pds.landsat.aws.landsat8 import L8Reader Not in TiTiler dependencies

from fastapi import FastAPI

app = FastAPI(title="Landsat Tiler", openapi_url="/api/v1/openapi.json")
scene = TilerFactory(
reader=L8Reader, additional_dependency=BandsParams, router_prefix="scenes"
)
mosaic = MosaicTilerFactory(
dataset_reader=L8Reader,
additional_dependency=BandsParams,
add_update=False,
add_create=False,
router_prefix="mosaic",
)
app.include_router(scene.router, prefix="/scenes", tags=["Scenes"])
app.include_router(mosaic.router, prefix="/mosaic", tags=["Mosaic"])

Page 15 of 16

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.