Metadata-Version: 2.5
Name: semanticfed-sdk
Version: 2026.1107.2
Summary: Official Python SDK for SemanticFed, the federated semantic layer (thin shell over burdenoff-sdk-libs)
Project-URL: Homepage, https://semanticfed.com
Project-URL: Documentation, https://github.com/algoshred/semanticfed-sdk-python#readme
Project-URL: Repository, https://github.com/algoshred/semanticfed-sdk-python
Project-URL: Issues, https://github.com/algoshred/semanticfed-sdk-python/issues
Project-URL: Changelog, https://github.com/algoshred/semanticfed-sdk-python/blob/main/CHANGELOG.md
Author-email: "Vignesh T.V" <vignesh@algoshred.com>
Maintainer-email: "Vignesh T.V" <vignesh@algoshred.com>
License: Copyright (c) 2025 Burdenoff Consultancy Services Private Limited, Algoshred Technologies Private Limited and all sister companies.
        
        All rights reserved.
        
        This software is proprietary and confidential. Unauthorized copying, modification, distribution, or use of this software, via any medium, is strictly prohibited without the express written permission of the copyright holders.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        
        For licensing inquiries, please contact: legal@algoshred.com
License-File: LICENSE
Keywords: api-client,burdenoff,graphql,python,sdk,semantic-layer,semanticfed
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: Other/Proprietary License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: burdenoff-sdk-libs>=2026.1107.4
Requires-Dist: httpx>=0.24.0
Requires-Dist: typing-extensions>=4.0.0; python_version < '3.11'
Provides-Extra: dev
Requires-Dist: black>=23.0.0; extra == 'dev'
Requires-Dist: flake8>=6.0.0; extra == 'dev'
Requires-Dist: graphql-core>=3.2.0; extra == 'dev'
Requires-Dist: isort>=5.12.0; extra == 'dev'
Requires-Dist: mypy>=1.0.0; extra == 'dev'
Requires-Dist: pre-commit>=3.0.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Requires-Dist: respx>=0.21.0; extra == 'dev'
Provides-Extra: docs
Requires-Dist: sphinx-autodoc-typehints>=1.19.0; extra == 'docs'
Requires-Dist: sphinx-rtd-theme>=1.2.0; extra == 'docs'
Requires-Dist: sphinx>=6.0.0; extra == 'docs'
Provides-Extra: test
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'test'
Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
Requires-Dist: pytest>=7.0.0; extra == 'test'
Requires-Dist: respx>=0.21.0; extra == 'test'
Description-Content-Type: text/markdown

# semanticfed-sdk

Official Python SDK for [SemanticFed](https://semanticfed.com), the federated semantic layer. It gives scripts, notebooks, CI/CD jobs and data pipelines async, typed access to connectors, data sources, semantic models, entities, dimensions, metrics, relationships, governed queries and access policies.

This SDK is a thin shell over [`burdenoff-sdk-libs`](https://pypi.org/project/burdenoff-sdk-libs/). It talks to the Burdenoff production gateways by default and presents the SemanticFed app Origin, so product access and RBAC resolve to SemanticFed for every call.

Node.js users: see [`@burdenoff/semanticfed-sdk`](https://www.npmjs.com/package/@burdenoff/semanticfed-sdk).

## Features

- Async/await throughout, built on `httpx`
- Workspace-token auth for pipelines, plus email/password, device code, PKCE and client credentials
- Automatic token refresh and a typed error hierarchy
- 23 mounted modules: the shared platform set, `semanticfed` and `sandbox`
- Full type hints with a `py.typed` marker; Python 3.10+

## Installation

```bash
pip install semanticfed-sdk
# or
uv add semanticfed-sdk
```

## Quick start

```python
import asyncio
import os

from semanticfed_sdk import SemanticfedSDK


async def main() -> None:
    # Production gateways are the default. A workspace-scoped token is all a
    # pipeline needs; the access token is used to mint or refresh it.
    sdk = SemanticfedSDK(
        access_token=os.environ["SEMANTICFED_ACCESS_TOKEN"],
        workspace_token=os.environ["SEMANTICFED_WORKSPACE_TOKEN"],
    )
    try:
        connectors = await sdk.semanticfed.connectors.list()
        models = await sdk.semanticfed.models.list(status="PUBLISHED")
        print(len(connectors.items), "connectors,", len(models.items), "published models")
    finally:
        await sdk.close()


asyncio.run(main())
```

## Managing a semantic model

```python
from burdenoff_sdk_libs.modules.semanticfed.types import (
    SemCreateConnectorInput,
    SemCreateDataSourceInput,
    SemCreateDimensionInput,
    SemCreateEntityInput,
    SemCreateMetricInput,
    SemCreateModelInput,
)

s = sdk.semanticfed
connector = await s.connectors.create(SemCreateConnectorInput(name="Warehouse", kind="POSTGRES"))
source = await s.data_sources.create(
    SemCreateDataSourceInput(connector_id=connector.id, name="analytics")
)
model = await s.models.create(SemCreateModelInput(name="Revenue", tags=["finance"]))
orders = await s.entities.create(
    SemCreateEntityInput(
        model_id=model.id,
        name="orders",
        kind="TABLE",
        data_source_id=source.id,
        physical_name="public.orders",
        primary_key="id",
    )
)
await s.dimensions.create(SemCreateDimensionInput(entity_id=orders.id, name="region", data_type="STRING"))
await s.metrics.create(
    SemCreateMetricInput(entity_id=orders.id, name="gmv", aggregation="SUM", expression="amount")
)
await s.models.publish(model.id)
```

## Running a governed query

```python
from burdenoff_sdk_libs.modules.semanticfed.types import SemCreateQueryInput, SemPaginationInput

query = await s.queries.create(
    SemCreateQueryInput(
        name="GMV by region",
        model_id=model.id,
        query_text="SELECT region, gmv FROM orders",
        cacheable=True,
        cache_ttl_seconds=300,
    )
)
await s.queries.publish(query.id)

run = await s.queries.run(query.id)
finished = await s.query_runs.get(run.id)
result = await s.query_runs.result(run.id, SemPaginationInput(limit=100))
print(finished.status if finished else None, [c.name for c in result.columns], result.rows)
```

Access policies (`s.access_policies.list/create/set_active`) apply to every query the SDK runs, exactly as they do in the app.

## API surface

| Namespace | Operations |
|---|---|
| `connectors` | `get`, `list`, `create`, `update`, `archive` |
| `data_sources` | `get`, `list`, `create`, `update`, `archive`, `transition` |
| `connections` | `list`, `record` |
| `models` | `get`, `list`, `create`, `update`, `archive`, `publish` |
| `entities` | `get`, `list`, `create`, `update`, `delete` |
| `dimensions`, `metrics` | `create` |
| `relationships` | `list`, `create` |
| `queries` | `get`, `list`, `create`, `update`, `archive`, `publish`, `run` |
| `query_runs` | `get`, `list`, `result` |
| `access_policies` | `list`, `create`, `set_active` |
| `health` | `check` |

Every document the SDK sends is validated in CI against the production workspace supergraph (`tests/test_graphql_documents.py`).

## Modules

All methods are async. The following modules are mounted on the `SemanticfedSDK`
instance: `auth`, `billing`, `channels`, `conversations`, `devportal`,
`export`, `files`, `groups`, `health`, `integrations`, `semanticfed`,
`notifications`, `organizations`, `products`, `rbac`, `sandbox`, `scheduler`,
`security`, `store`, `support`, `tags`, `tours`, `workspaces`.

## Configuration

```python
from semanticfed_sdk import SemanticfedSDK

sdk = SemanticfedSDK(
    workspace_endpoint=None,   # SEMANTICFED_WORKSPACE_ENDPOINT, BURDENOFF_WORKSPACE_ENDPOINT, then prod
    global_endpoint=None,      # SEMANTICFED_GLOBAL_ENDPOINT, BURDENOFF_GLOBAL_ENDPOINT, then prod
    product_origin=None,       # SEMANTICFED_ORIGIN, then the app shell of a known gateway
    client_id="burdenoff_cli_semanticfed",   # default
    oidc_issuer=None,                       # derived from global_endpoint
    api_key=None,
    access_token=None,
    refresh_token=None,
    workspace_token=None,
    timeout=30.0,
    auto_refresh=True,
)
```

## Error Handling

```python
from semanticfed_sdk import (
    SemanticfedError,
    AuthenticationError,
    AuthorizationError,
    NetworkError,
    ValidationError,
    RateLimitError,
    DeviceCodeExpiredError,
    DeviceCodeDeniedError,
)

try:
    await sdk.auth.sign_in(email="user@example.com", password="wrong")
except AuthenticationError:
    print("Invalid credentials")
except NetworkError:
    print("Could not reach the API")
except SemanticfedError as e:
    print(f"SDK error: {e}")
```

## Development

```bash
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"

make format        # black + isort
make lint          # flake8
make type-check    # mypy (strict)
make test          # pytest
make sanity        # format-check + lint + type-check + test (cov>=80) + build
```

The release install is hash-locked: `uv sync --locked --all-extras` reproduces it.

## Releasing

Releases are cut from `main` by `.github/workflows/release.yml` (shared G60
workflow): push a CalVer tag (`2026.1031.1`) or dispatch the workflow with an
empty version. The run gates and builds from `uv.lock`, uploads to PyPI,
smoke-imports the published wheel and creates the git tag and GitHub Release.

## License

Proprietary — Copyright Burdenoff Consultancy Services Pvt. Ltd.

## Support

- Issues: [GitHub Issues](https://github.com/algoshred/semanticfed-sdk-python/issues)
