Skip to content

Commit 458857c

Browse files
jseese-mdsolabutsyk-mdsol
authored andcommitted
Boilerplate Code.
1 parent 86aa544 commit 458857c

32 files changed

Lines changed: 1426 additions & 737 deletions

‎.dockerignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
**/.git*
1515
**/.*project
1616
**/.DS_Store
17-
**/._*
17+
**/._*

‎.github/pull_request_template.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- [ ] Make sure the pull request does not have excessive number of unnecessary commits. Utilize the `git commit --amend --no-edit` command to reduce commit messages when making small file changes (*like changing linespacing*).
1010
- [ ] Make sure you have added unit tests for the code changes. Tests should be added in the `tests/` folder.
1111
- [ ] Modify docs, if required. Add any new documentation in the `doc/` folder.
12-
- [ ] Rebase on latest active development branch (develop/main).
12+
- [ ] Rebase on latest active development branch (develop/main).
1313

1414
### Changes Summary
1515

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ jobs:
2929
key: ${{ runner.os }}-precommit-${{ hashFiles('.pre-commit-config.yaml') }}
3030

3131
- name: lint
32-
run: scripts/lint.sh
32+
run: |
33+
chmod +x scripts/lint.sh
34+
scripts/lint.sh
3335
3436
- name: build docker image
3537
working-directory: ${{ github.workspace }}
@@ -49,5 +51,4 @@ jobs:
4951
run: docker run dataconnect-library-python "scripts/benchmark.sh"
5052

5153
- name: typecheck
52-
run: docker run dataconnect-library-python "scripts/typecheck.sh"
53-
54+
run: docker run python-template "scripts/typecheck.sh"

‎.pre-commit-config.yaml‎

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
1+
# Pre-commit hook configuration
2+
# Docs: https://pre-commit.com/
3+
#
4+
# Install:
5+
# pip install pre-commit # or: poetry install --with lint
6+
# pre-commit install # register the git hook
7+
#
8+
# Run manually against all files:
9+
# pre-commit run --all-files
10+
#
11+
# Update hook revisions to latest:
12+
# pre-commit autoupdate
13+
14+
default_language_version:
15+
python: python3.11
16+
117
repos:
2-
- repo: https://github.com/ambv/black
3-
# rev must match pyproject.toml
4-
rev: 23.3.0
18+
# ---------------------------------------------------------------------------
19+
# General hygiene
20+
# ---------------------------------------------------------------------------
21+
- repo: https://github.com/pre-commit/pre-commit-hooks
22+
rev: v5.0.0
523
hooks:
6-
- id: black
7-
args: ["-l", "100"]
8-
- repo: https://github.com/myint/autoflake
9-
# rev must match pyproject.toml
10-
rev: v1.4 # rev depends on tag name in git not pip version number (thus the v prefix is required here)
24+
- id: trailing-whitespace # strip trailing whitespace
25+
- id: end-of-file-fixer # ensure files end with a newline
26+
- id: check-yaml # validate YAML syntax
27+
- id: check-toml # validate TOML syntax
28+
- id: check-json # validate JSON syntax
29+
- id: check-merge-conflict # forbid merge-conflict markers
30+
- id: check-added-large-files # warn on large committed files
31+
args: ["--maxkb=1024"]
32+
- id: debug-statements # catch leftover debugger imports
33+
- id: mixed-line-ending
34+
args: ["--fix=lf"]
35+
36+
# ---------------------------------------------------------------------------
37+
# Ruff – fast Python linter (replaces flake8, isort, pyupgrade, …)
38+
# ---------------------------------------------------------------------------
39+
- repo: https://github.com/astral-sh/ruff-pre-commit
40+
rev: v0.15.11
1141
hooks:
12-
- id: autoflake
13-
args:
14-
[
15-
"--in-place",
16-
"--remove-all-unused-imports",
17-
"--ignore-init-module-imports",
18-
]
19-
- repo: https://github.com/PyCQA/isort
20-
# rev must match pyproject.toml
21-
rev: 5.12.0
22-
hooks:
23-
- id: isort
24-
args: ["--profile", "black", "-l", "100"]
25-
# - repo: git@github.com:mdsol/git-config-checker.git
26-
# rev: 0.1.1
27-
# hooks:
28-
# - id: git-config-checker
29-
# args: ["--checks", "emailDomain"]
42+
- id: ruff # lint + auto-fix
43+
args: ["--fix", "--exit-non-zero-on-fix"]
44+
- id: ruff-format # format (Black-compatible)

‎LICENSE‎

Whitespace-only changes.

‎README.md‎

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,49 @@
1-
# Data Connect Python Library
2-
Python library built by Medidata for connecting to Data Connect and programmatically querying and retrieving data.
1+
from dataconnect import DataConnectClientfrom dataconnect import DataConnectClient
32

3+
# dataconnect-library-python
4+
5+
Python SDK for the [Medidata DataConnect](https://github.com/mdsol/dataconnect-library-r) service.
6+
7+
---
8+
9+
## Transport note
10+
11+
The DataConnect service uses **Apache Arrow Flight** (gRPC binary protocol),
12+
**not** a plain REST/HTTP API. `pyarrow.flight` is the primary transport
13+
dependency.
14+
15+
---
416

517
## Installation
618

7-
See [CONTRIBUTING.md](./CONTRIBUTING.md) for installation instructions.
19+
```bash
20+
pip install dataconnect # core (pyarrow + pydantic + httpx)
21+
pip install dataconnect[pandas] # + pandas for .to_pandas() on results
22+
```
823

9-
## To Dos
24+
Requires **Python ≥ 3.10**.
1025

11-
The following actions are needed when using this as the template for a new python project:
26+
---
1227

13-
- [ ] Update `readme.md` for new project
14-
- [ ] Update `factbook.yaml` for new project
15-
- [ ] Update `pyproject.toml` with relevant `name`, `description`, and `authors` and remove unneeded dep groups
28+
## Quick start
1629

17-
- [ ] Remove all example code files (leave `__init__.py` in place)
18-
- [X] Rename all references to `python-template` and `python_template` to new module/folder names
19-
- [ ] Remove all example test files and all code from `conftest.py` (leave the docstring in place)
20-
- [ ] Add placeholder tests so PR passes
21-
- [ ] Get GH Admins to add mdsol robot key so PR passes
22-
- [ ] Add Artifactory robot account info so PR passes
30+
```python
31+
import pyarrow as pa
32+
from dataconnect import DataConnectClient
2333

24-
## Contributing
2534

26-
See [CONTRIBUTING](CONTRIBUTING.md).
35+
with DataConnectClient.connect(
36+
host="dataconnect.example.com",
37+
port=443,
38+
token="your-bearer-token",
39+
) as client:
2740

28-
## Contact
41+
studies = client.studies(search_study_name="ACME", page=1, page_size=10)
42+
study = studies[0]
43+
```
44+
## Development
2945

30-
See the [factbook](factbook.yaml).
46+
```bash
47+
pip install -e ".[dev]"
48+
pytest
49+
```

‎README_orig.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Python Template
2+
3+
This repository is meant to establish useful practices for python projects.
4+
5+
## Installation
6+
7+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for installation instructions.
8+
9+
## To Dos
10+
11+
The following actions are needed when using this as the template for a new python project:
12+
13+
- [ ] Update `readme.md` for new project
14+
- [ ] Update `factbook.yaml` for new project
15+
- [ ] Update `pyproject.toml` with relevant `name`, `description`, and `authors` and remove unneeded dep groups
16+
- [ ] Update `python_template` folder to match new project name
17+
- [ ] Remove all example code files (leave `__init__.py` in place)
18+
- [ ] Rename all references to `python-template` and `python_template` to new module/folder names
19+
- [ ] Remove all example test files and all code from `conftest.py` (leave the docstring in place)
20+
- [ ] Add placeholder tests so PR passes
21+
- [ ] Get GH Admins to add mdsol robot key so PR passes
22+
- [ ] Add Artifactory robot account info so PR passes
23+
24+
## Contributing
25+
26+
See [CONTRIBUTING](CONTRIBUTING.md).
27+
28+
## Contact
29+
30+
See the [factbook](factbook.yaml).

‎dataconnect/__init__.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""dataconnect — Python SDK for the Medidata DataConnect service."""
2+
3+
from __future__ import annotations
4+
5+
from dataconnect.client import DataConnectClient
6+
from dataconnect.exceptions import AuthenticationError, ConnectionError, DataConnectError
7+
from dataconnect.models import (
8+
Dataset,
9+
DatasetVersion,
10+
Study,
11+
StudyEnvironment,
12+
)
13+
14+
__all__ = [
15+
"DataConnectClient",
16+
"Study",
17+
"StudyEnvironment",
18+
"Dataset",
19+
"DatasetVersion",
20+
"DataConnectError",
21+
"ConnectionError",
22+
"AuthenticationError",
23+
]

‎dataconnect/_encoding.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Encoding utilities for DataConnect."""
2+
3+
from __future__ import annotations
4+
5+
import json
6+
from typing import Any
7+
8+
9+
def dumps(obj: Any) -> bytes:
10+
"""Serialize *obj* to JSON (bytes)."""
11+
return json.dumps(obj, separators=(",", ":")).encode("utf-8")
12+
13+
14+
def loads(data: bytes) -> Any:
15+
"""Deserialize JSON from *data* (bytes)."""
16+
return json.loads(data.decode("utf-8"))

‎dataconnect/auth.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Authentication and authorization utilities for DataConnect."""
2+
3+
from __future__ import annotations
4+
5+
from dataclasses import dataclass
6+
7+
8+
class Credentials:
9+
"""Marker base class for all credentials types."""
10+
11+
12+
@dataclass(frozen=True)
13+
class BearerTokenAuth(Credentials):
14+
"""Bearer token authentication credentials (OAuth access token)."""
15+
16+
token: str

0 commit comments

Comments
 (0)