0
# Environment Management
1
2
GDAL environment configuration, credential management for cloud storage access, and driver management for controlling which data formats are available.
3
4
## Capabilities
5
6
### Environment Context Manager
7
8
```python { .api }
9
class Env:
10
def __init__(
11
self,
12
session=None,
13
aws_unsigned=False,
14
profile_name=None,
15
session_options=None,
16
**options
17
):
18
"""
19
Context manager for GDAL and AWS configuration.
20
21
Parameters:
22
- session: Session object for credential management
23
- aws_unsigned: bool, use unsigned requests for public data
24
- profile_name: str, AWS profile name
25
- session_options: dict, session configuration options
26
- options: dict, additional GDAL configuration options
27
"""
28
29
@classmethod
30
def from_defaults(cls, *args, **kwargs):
31
"""Create Env with default configuration options."""
32
33
@classmethod
34
def default_options(cls):
35
"""Return default configuration options."""
36
37
def credentialize(self):
38
"""Configure GDAL with credentials."""
39
40
def drivers(self):
41
"""Return mapping of registered drivers."""
42
```
43
44
#### Usage Examples
45
46
```python
47
from fiona.env import Env
48
import fiona
49
50
# Basic environment context
51
with Env():
52
with fiona.open('data.shp', 'r') as collection:
53
for feature in collection:
54
print(feature)
55
56
# AWS S3 access with credentials
57
with Env(aws_unsigned=False, profile_name='default'):
58
with fiona.open('/vsis3/bucket/data.geojson', 'r') as collection:
59
print(f"Features: {len(collection)}")
60
61
# Custom GDAL options
62
with Env(GDAL_DISABLE_READDIR_ON_OPEN='EMPTY_DIR'):
63
with fiona.open('large_directory/data.shp', 'r') as collection:
64
# Faster opening for directories with many files
65
pass
66
```
67
68
### Environment Decorators
69
70
```python { .api }
71
def ensure_env(f):
72
"""Decorator ensuring GDAL environment exists."""
73
74
def ensure_env_with_credentials(f):
75
"""Decorator ensuring environment with credentials."""
76
```