Skip to main content

Python SDK and CLI for Microsoft Dynamics 365 Business Central APIs

Project description

bcli

Tests License: Apache 2.0 Python

A Python SDK and CLI for Microsoft Dynamics 365 Business Central APIs, with a built-in dlt source for ETL backup pipelines.

SDK Quick Start

from bcli import AsyncBCClient

# Programmatic auth — no config files needed
async with AsyncBCClient(
    tenant_id="your-tenant-id",
    client_id="your-app-id",
    client_secret="your-secret",
    environment="Sandbox",
    company_id="your-company-id",
) as client:
    # Query with fluent OData builder
    customers = await client.query("customers").filter("city eq 'Chicago'").top(10).get()

    # Write with safety gate
    async with client.safe_write("Sandbox", "your-company-id") as sw:
        await sw.post("salesInvoices", body={"customerNumber": "10000"}, domain="finance")

Or use TOML profiles for the CLI and repeated SDK use:

from bcli import AsyncBCClient

async with AsyncBCClient(profile="production") as client:
    vendors = await client.query("vendors").select("displayName", "balance").get()

CLI Quick Start

# Install (PyPI distribution name is "bc-cli"; the binary is "bcli")
pip install bc-cli
# or
uv tool install bc-cli

# Configure (interactive — discovers companies automatically)
bcli config init

# Query standard APIs immediately
bcli get customers --top 5
bcli get vendors --filter "displayName eq 'Fabrikam'" --format json
bcli get salesInvoices --select number,totalAmountIncludingTax --top 10

# Import custom APIs from a Postman collection
bcli registry import --from-postman ./my_collection.json

# Query custom endpoints (route auto-resolved)
bcli get myCustomEntities --top 5

Features

  • Works out of the box — 79 standard BC v2.0 entities (customers, vendors, items, GL entries, ...) with zero configuration beyond auth
  • Custom API support — Import your custom API pages from Postman collections, JSON, or live $metadata
  • Three-tier endpoint resolution — Custom registry -> standard v2.0 -> fuzzy suggestions
  • Multi-company — Assign aliases to companies and query across all entities
  • OData query builder--filter, --select, --expand, --orderby, --top, --skip on every query
  • Multiple output formats — table, JSON, CSV, NDJSON for pipeline use
  • Secure auth — OS keychain integration (macOS Keychain, Windows Credential Manager), token caching, client credentials + device code flows
  • Write safety — SafeContext gate prevents wrong-environment writes, enforces draft status on financial documents
  • Programmatic auth — Pass credentials directly for MCP servers, Airflow DAGs, and containers (no config files required)
  • Batch operations — Execute sequences of API calls from YAML files
  • ETL pipeline — Built-in dlt source for incremental backup to Parquet / DuckDB / Iceberg / Postgres
  • Structured logging — JSON request logs with correlation IDs for observability

ETL Pipeline (dlt source)

Sync BC data incrementally to any dlt-supported destination — useful as a Fivetran backup, a warehouse backfill tool, or a standalone ETL runner.

Standalone (any BC tenant, no bcli config required):

import dlt
from bcli.etl import business_central, EntityDef, fivetran_stamper

source = business_central(
    tenant_id="...", client_id="...", client_secret="...",
    environment="Production",
    entities=[
        EntityDef(name="customers"),
        EntityDef(name="vendors"),
    ],
    multi_company=True,             # iterate all BC companies
    stampers=[fivetran_stamper()],  # add _fivetran_synced / _fivetran_deleted
)

pipeline = dlt.pipeline(destination="duckdb", dataset_name="bc_raw")
pipeline.run(source)

Or use the bcli bridge (reuses your profile and custom-API registry):

# List entities the pipeline will sync
bcli --profile prod etl entities

# Incremental sync (uses systemModifiedAt cursor)
bcli --profile prod etl sync --destination filesystem

# Full refresh
bcli --profile prod etl sync --destination filesystem --full-refresh

# Schedule via cron (every 10 min incremental, nightly full refresh)
*/10 * * * * bcli --profile prod etl sync --destination filesystem
0 0 * * *    bcli --profile prod etl sync --destination filesystem --full-refresh

Installation

Requires Python 3.11+.

Heads-up on the package name. The PyPI name is bc-cli, not bcli. An unrelated 2018-era package squats on the bcli name (an "EC2 Cluster Creator" with no relation to this project) — pip install bcli will install that, not this. Always pip install bc-cli. Once installed, the import name (import bcli) and the CLI binary (bcli) work as documented.

# SDK only (for libraries, MCP servers, Airflow DAGs)
pip install bc-cli

# SDK + CLI
pip install "bc-cli[cli]"

# SDK + ETL (dlt source for backup pipelines)
pip install "bc-cli[etl]"

# Everything
pip install "bc-cli[cli,etl]"

# Via uv (recommended)
uv tool install bc-cli

# From source
git clone https://github.com/igor-ctrl/bcli.git
cd bcli
pip install -e ".[dev,etl]"

Documentation

Guide Description
Getting Started First-time setup, authentication, your first query
Configuration Profiles, environments, config file format
Authentication Client credentials, device code, OS keychain
Querying Data GET, OData filters, pagination, output formats
Write Operations POST, PATCH, DELETE
Custom APIs Importing from Postman, JSON, or $metadata
Multi-Company Company aliases, cross-entity queries
Batch Operations YAML batch files
SDK Usage Python SDK for developers and MCP servers
Command Reference Complete CLI command reference
Contributing Development setup, architecture, testing

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bc_cli-0.1.0.tar.gz (336.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bc_cli-0.1.0-py3-none-any.whl (129.7 kB view details)

Uploaded Python 3

File details

Details for the file bc_cli-0.1.0.tar.gz.

File metadata

  • Download URL: bc_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 336.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for bc_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 35ec4ebbfb96774d0bd6b3e932e3c0ee4cc4ea521ead09cf312ba40a5c18e603
MD5 93d45c54940fdeaf6ca46c8370696a02
BLAKE2b-256 3081f5ae9fe3ac76edf7a3e8d2ba9d51b37e4e3e660838f7636197f71d524e86

See more details on using hashes here.

File details

Details for the file bc_cli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bc_cli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 129.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for bc_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbf11a60101cb42ba0301ca807d984d6ab88cc01b0e67ca6929c639714ea480d
MD5 1468bf1594fbcebb3593c792d583f980
BLAKE2b-256 9f5c488a3c39a65fe5da6e7f42e1239ea3f057b0eb99b224742e9bd6d4838aca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page