= API Reference
:description: Overview of all ECM API namespaces: ecm.dms (objects), ecm.security (users/groups), ecm.db (SQL), ecm.system (server definition). Entry point: ECM() factory.
:keywords: API, ecm.dms, ecm.security, ecm.db, ecm.system, ECM, namespaces, ECM() factory
:page-tags: api, overview

The API is accessible via the `ECM()` factory and is split into the following namespaces:

[cols="1,3,1"]
|===
|Namespace |Description |Reference

|`ecm.dms`
|Folder, register, and document operations
|xref:api/dms/index.adoc[→ ecm.dms]

|`ecm.security`
|User and group management
|xref:api/security/index.adoc[→ ecm.security]

|`ecm.system`
|Server metadata and object definitions
|xref:api/system/index.adoc[→ ecm.system]

|`ecm.db`
|Direct SQL access via ADO
|xref:api/db/index.adoc[→ ecm.db]
|===

== ECM factory

[source,python]
----
from ecmind_blue_client.ecm import ECM
from ecmind_blue_client.pool import SyncPoolClient

client = SyncPoolClient(servers="<host>:4000:1", username="<username>", password="<password>")
ecm = ECM(client)
----

The `ECM()` function is overloaded: passing a `SyncPoolClient` returns `ECMSync`; passing an `AsyncPoolClient` returns `ECMAsync`.

== impersonate()

[source,python]
----
ecm.impersonate(username: str) -> ECMSync | ECMAsync
----

Returns a new ECM instance that injects the given user context into every request (`$$$SwitchContextUserName$$$`).
The executing user requires the *Context Switch* system role.

Supports both direct usage and use as a context manager (`with` / `async with`).

[tabs]
====
Sync::
+
[source,python]
----
with ecm.impersonate("john") as ecm_john:
    ecm_john.dms.insert(MyFolder(Title="Test"))
----

Async::
+
[source,python]
----
async with ecm.impersonate("john") as ecm_john:
    await ecm_john.dms.insert(MyFolder(Title="Test"))
----
====
