Skip to content

Commit 249f133

Browse files
Merge pull request #144 from datajoint/docs/config-override-syntax
2 parents 963c3fa + 5def3d3 commit 249f133

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/reference/configuration.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,47 @@ export DJ_PASS=secret
241241

242242
**Note:** Per-store credentials must be configured in `datajoint.json` or `.secrets/` — environment variable overrides are not supported for nested store configurations.
243243

244+
## Programmatic Access
245+
246+
### Reading and Writing Settings
247+
248+
Access settings using dot notation on `dj.config`:
249+
250+
```python
251+
import datajoint as dj
252+
253+
# Read settings
254+
print(dj.config.database.host)
255+
print(dj.config.display.diagram_direction)
256+
257+
# Write settings
258+
dj.config.database.host = "mysql.example.com"
259+
dj.config.display.diagram_direction = "TB"
260+
```
261+
262+
### Temporary Overrides
263+
264+
Use `dj.config.override()` to temporarily change settings within a context:
265+
266+
```python
267+
with dj.config.override(safemode=False):
268+
# safemode is False here
269+
(Table & key).delete()
270+
# safemode is restored to original value
271+
```
272+
273+
**Nested settings syntax:** Since Python doesn't allow dots in keyword argument names, use double underscores (`__`) to access nested settings in `override()`:
274+
275+
```python
276+
# These are equivalent:
277+
dj.config.display.diagram_direction = "TB" # direct assignment
278+
279+
with dj.config.override(display__diagram_direction="TB"): # in override()
280+
...
281+
```
282+
283+
The double underscore maps to the dot-notation path: `display__diagram_direction``display.diagram_direction`.
284+
244285
## API Reference
245286

246287
See [Settings API](../api/datajoint/settings.md) for programmatic access.

0 commit comments

Comments
 (0)