Skip to content

Add module-level exports via __all__ in package __init__.py files#165

Open
abelmilash-msft wants to merge 3 commits intomainfrom
users/abelmilash/module-level-exports
Open

Add module-level exports via __all__ in package __init__.py files#165
abelmilash-msft wants to merge 3 commits intomainfrom
users/abelmilash/module-level-exports

Conversation

@abelmilash-msft
Copy link
Copy Markdown
Contributor

Summary

  • Populate __all__ in models/, core/, and operations/ package __init__.py files so users can import directly from the top-level package instead of navigating submodule paths.
  • Update all user-facing examples, README, and skill docs to use the new shorter import paths
  • Fix pre-existing RelationshipInfo dict-style access bugs in relationships.py example

Before / After

# Before
from PowerPlatform.Dataverse.models.record import Record
from PowerPlatform.Dataverse.core.errors import DataverseError

# After
from PowerPlatform.Dataverse.models import Record
from PowerPlatform.Dataverse.core import DataverseError

Abel Milash and others added 3 commits April 21, 2026 21:33
Populate __all__ in models, core, and operations package __init__.py
files so public symbols are importable directly from the package
namespace. Update all user-facing examples, README, and skill docs
to use the new shorter import paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
RelationshipInfo is a dataclass — use attribute access (.relationship_schema_name,
.lookup_schema_name, .relationship_id) instead of dict subscript.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace all remaining .get('Key') dict-style calls with proper
attribute access on RelationshipInfo dataclass fields.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 22, 2026 06:09
@abelmilash-msft abelmilash-msft requested a review from a team as a code owner April 22, 2026 06:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR flattens the public import surface of the Dataverse SDK by adding package-level re-exports via __all__ in models/, core/, and operations/, and updates docs/examples to use the shorter import paths. It also fixes the RelationshipInfo usage in the relationships example to use attribute access instead of dict-style access.

Changes:

  • Populate __all__ and re-export key symbols in src/PowerPlatform/Dataverse/{models,core,operations}/__init__.py.
  • Update README and skill/example docs to use package-level imports (e.g., from ...models import Record).
  • Fix RelationshipInfo example code to use typed attributes (result.relationship_id, etc.).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/PowerPlatform/Dataverse/operations/init.py Re-export operation namespaces/classes from the package root.
src/PowerPlatform/Dataverse/models/init.py Re-export key model types/helpers (filters, record, query builder, relationship metadata, etc.).
src/PowerPlatform/Dataverse/core/init.py Re-export config/logging/errors at PowerPlatform.Dataverse.core.
src/PowerPlatform/Dataverse/claude_skill/dataverse-sdk-use/SKILL.md Update documentation examples to use new package-level imports.
examples/basic/installation_example.py Update example imports to use PowerPlatform.Dataverse.operations and PowerPlatform.Dataverse.core.
examples/basic/functional_testing.py Update example imports to use PowerPlatform.Dataverse.models and PowerPlatform.Dataverse.core.
examples/advanced/walkthrough.py Update example imports to use PowerPlatform.Dataverse.models and PowerPlatform.Dataverse.core.
examples/advanced/relationships.py Update imports and fix RelationshipInfo attribute access usage.
examples/advanced/alternate_keys_upsert.py Update example imports to use PowerPlatform.Dataverse.models.
docs/spec-module-level-exports.md Add a spec describing the module-level export goal and rationale.
README.md Update user-facing snippets to use the new package-level imports.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +11 to +25
from .batch import (
BatchDataFrameOperations,
BatchOperations,
BatchQueryOperations,
BatchRecordOperations,
BatchRequest,
BatchTableOperations,
ChangeSet,
ChangeSetRecordOperations,
)
from .dataframe import DataFrameOperations
from .files import FileOperations
from .query import QueryOperations
from .records import RecordOperations
from .tables import TableOperations
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PowerPlatform.Dataverse.operations now imports all operation submodules (including batch/dataframe) eagerly at package import time. This increases import-time overhead for callers that only need RecordOperations/TableOperations and can also amplify side effects from heavy dependencies. Consider using lazy re-exports (PEP 562 __getattr__) or limiting eager imports to the most common namespaces to keep import PowerPlatform.Dataverse.operations lightweight.

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +43
__all__ = [
# batch
"BatchDataFrameOperations",
"BatchOperations",
"BatchQueryOperations",
"BatchRecordOperations",
"BatchRequest",
"BatchTableOperations",
"ChangeSet",
"ChangeSetRecordOperations",
# other operations
"DataFrameOperations",
"FileOperations",
"QueryOperations",
"RecordOperations",
"TableOperations",
]
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces new package-level imports (from PowerPlatform.Dataverse.operations import RecordOperations, etc.), but there are no tests verifying these exports. Consider adding a small unit test that imports the expected classes from PowerPlatform.Dataverse.operations (and optionally validates __all__) so refactors don't silently break the new public API.

Copilot uses AI. Check for mistakes.
Comment on lines +56 to +60
- `models.filters` → `eq`, `ne`, `gt`, `lt`, `ge`, `le`, `contains`, `startswith`, `endswith`, `filter_in`, `between`, `and_`, `or_`, `not_`
- `models.batch` → `BatchItemResponse`, `BatchResult`
- `models.record` → `Record`
- `models.table_info` → `TableInfo`, `ColumnInfo`, `AlternateKeyInfo`
- `models.relationship` → `OneToManyRelationship`, `ManyToManyRelationship`, `RelationshipInfo` (etc.)
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec lists exports that don't match the current implementation: models.filters does not define and_/or_/not_ helpers (composition is via &, |, ~), and relationship classes are named OneToManyRelationshipMetadata/ManyToManyRelationshipMetadata (not OneToManyRelationship/ManyToManyRelationship). To avoid confusion for contributors, update this spec section to reflect the actual public symbols (or add the missing helpers/types if they are intended).

Suggested change
- `models.filters``eq`, `ne`, `gt`, `lt`, `ge`, `le`, `contains`, `startswith`, `endswith`, `filter_in`, `between`, `and_`, `or_`, `not_`
- `models.batch``BatchItemResponse`, `BatchResult`
- `models.record``Record`
- `models.table_info``TableInfo`, `ColumnInfo`, `AlternateKeyInfo`
- `models.relationship``OneToManyRelationship`, `ManyToManyRelationship`, `RelationshipInfo` (etc.)
- `models.filters``eq`, `ne`, `gt`, `lt`, `ge`, `le`, `contains`, `startswith`, `endswith`, `filter_in`, `between`
- `models.batch``BatchItemResponse`, `BatchResult`
- `models.record``Record`
- `models.table_info``TableInfo`, `ColumnInfo`, `AlternateKeyInfo`
- `models.relationship``OneToManyRelationshipMetadata`, `ManyToManyRelationshipMetadata`, `RelationshipInfo` (etc.)

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +23
from .config import DataverseConfig
from .errors import DataverseError, HttpError, MetadataError, SQLParseError, ValidationError
from .log_config import LogConfig

__all__ = [
"DataverseConfig",
"DataverseError",
"HttpError",
"LogConfig",
"MetadataError",
"SQLParseError",
"ValidationError",
]
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a new package-level export surface for PowerPlatform.Dataverse.core, but there are no unit tests ensuring imports like from PowerPlatform.Dataverse.core import DataverseError, DataverseConfig, LogConfig work. A small unit test covering these imports would help catch accidental regressions when modules are reorganized.

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +36
from .labels import Label, LocalizedLabel
from .query_builder import ExpandOption, QueryBuilder, QueryParams
from .record import Record
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PowerPlatform.Dataverse.models now eagerly imports query_builder (and other submodules) at package import time. Since query_builder imports pandas at module scope, from PowerPlatform.Dataverse.models import Record will also load pandas/numpy even when the caller only needs lightweight models. Consider switching these re-exports to lazy loading (e.g., module-level __getattr__/__dir__ per PEP 562, or otherwise deferring pandas-dependent imports) to avoid a noticeable import-time/perf hit for common imports.

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +90
__all__ = [
# batch
"BatchItemResponse",
"BatchResult",
# filters
"FilterExpression",
"between",
"contains",
"endswith",
"eq",
"filter_in",
"ge",
"gt",
"is_not_null",
"is_null",
"le",
"lt",
"ne",
"not_between",
"not_in",
"raw",
"startswith",
# labels
"Label",
"LocalizedLabel",
# query builder
"ExpandOption",
"QueryBuilder",
"QueryParams",
# record
"Record",
# relationship
"CascadeConfiguration",
"LookupAttributeMetadata",
"ManyToManyRelationshipMetadata",
"OneToManyRelationshipMetadata",
"RelationshipInfo",
# table info
"AlternateKeyInfo",
"ColumnInfo",
"TableInfo",
# upsert
"UpsertItem",
]
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a new public import surface (from PowerPlatform.Dataverse.models import ...), but there are no unit tests asserting these package-level exports work (and stay working) for key symbols like Record, QueryBuilder, and filter helpers. Adding a small test that imports these names from PowerPlatform.Dataverse.models (and optionally validates __all__) would help prevent regressions.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants