Skip to content

Commit 6f83afe

Browse files
author
Tristen Harr
committed
update docs
1 parent 76a3d43 commit 6f83afe

File tree

9 files changed

+275
-81
lines changed

9 files changed

+275
-81
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This changelog documents the changes between release versions.
44
## [Unreleased]
55
Changes to be included in the next upcoming release
66

7+
## [0.1.0] - 2024-08-22
8+
* Update Documentation for ndc-hub
9+
710
## [0.0.45] - 2024-08-19
811
* Update SDK to fix input type casts
912

README.md

Lines changed: 59 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,102 @@
1-
### Hasura Python Lambda Connector
1+
# Hasura Python Lambda Connector
2+
<a href="https://www.python.org/"><img src="https://github.com/hasura/ndc-python-lambda/blob/main/docs/logo.svg" align="right" width="200"></a>
3+
4+
[![Docs](https://img.shields.io/badge/docs-v3.x-brightgreen.svg?style=flat)](https://hasura.io/connectors/python)
5+
[![ndc-hub](https://img.shields.io/badge/ndc--hub-python-blue.svg?style=flat)](https://hasura.io/connectors/python)
6+
[![License](https://img.shields.io/badge/license-Apache--2.0-purple.svg?style=flat)](https://github.com/hasura/ndc-python-lambda/blob/main/LICENSE.txt)
7+
[![Status](https://img.shields.io/badge/status-alpha-yellow.svg?style=flat)](https://github.com/hasura/ndc-python-lambda/blob/main/README.md)
28

39
This connector allows you to write Python code and call it using Hasura!
410

511
With Hasura, you can integrate -- and even host -- this business logic directly with Hasura DDN and your API.
612

713
You can handle custom business logic using the Python Lambda data connector. Using this connector, you can transform or enrich data before it reaches your customers, or perform any other business logic you may need.
814

9-
You can then integrate these functions as individual commands in your metadata and API.
10-
This process enables you to simplify client applications and speed up your backend development!
15+
You can then integrate these functions as individual commands in your metadata and API. This process enables you to simplify client applications and speed up your backend development!
1116

12-
## Setting up the Python Lambda connector
17+
This connector is built using the [Python Data Connector SDK](https://github.com/hasura/ndc-sdk-python) and implements the [Data Connector Spec](https://github.com/hasura/ndc-spec).
1318

14-
### Prerequisites:
15-
In order to follow along with this guide, you will need:
16-
* [The DDN CLI, VS Code extension, and Docker installed](https://hasura.io/docs/3.0/getting-started/build/prerequisites/)
17-
* Python version `>= 3.11`
19+
## Before you get Started
1820

19-
In this guide we will setup a new Hasura DDN project from scratch.
21+
1. The [DDN CLI](https://hasura.io/docs/3.0/cli/installation) and [Docker](https://docs.docker.com/engine/install/) installed
22+
2. A [supergraph](https://hasura.io/docs/3.0/getting-started/init-supergraph)
23+
3. A [subgraph](https://hasura.io/docs/3.0/getting-started/init-subgraph)
2024

21-
### Step-by-step guide
25+
The steps below explain how to Initialize and configure a connector for local development. You can learn how to deploy a connector — after it's been configured — [here](https://hasura.io/docs/3.0/getting-started/deployment/deploy-a-connector).
2226

23-
Create a new directory that will contain your Hasura project and change directories into it.
27+
## Using the Python connector
2428

25-
```mkdir ddn && cd ddn```
29+
### Step 1: Authenticate your CLI session
2630

27-
Create a new supergraph:
31+
```bash
32+
ddn auth login
33+
```
2834

29-
```ddn supergraph init --dir .```
35+
### Step 2: Configure the connector
3036

31-
Start a watch session, additionally split of a new terminal to continue running commands from.
37+
Once you have an initialized supergraph and subgraph, run the initialization command in interactive mode while providing a name for the connector in the prompt:
3238

33-
```HASURA_DDN_PAT=$(ddn auth print-pat) docker compose up --build --watch```
39+
```bash
40+
ddn connector init python -i
41+
```
3442

35-
In the new terminal, perform a local build:
43+
#### Step 2.1: Choose the `hasura/python` option from the list
3644

37-
```ddn supergraph build local --output-dir engine```
45+
#### Step 2.2: Choose a port for the connector
3846

39-
Initialize a subgraph:
47+
The CLI will ask for a specific port to run the connector on. Choose a port that is not already in use or use the default suggested port.
4048

41-
```
42-
ddn subgraph init python \
43-
--dir python \
44-
--target-supergraph supergraph.local.yaml \
45-
--target-supergraph supergraph.cloud.yaml
46-
```
49+
### Step 3: Introspect the connector
4750

48-
Initialize a Python connector:
51+
Introspecting the connector will generate a `config.json` file and a `python.hml` file.
4952

50-
```
51-
ddn connector init python \
52-
--subgraph python/subgraph.yaml \
53-
--hub-connector hasura/python \
54-
--configure-port 8085 \
55-
--add-to-compose-file compose.yaml
53+
```bash
54+
ddn connector introspect python
5655
```
5756

58-
In the `.env.local` you will need to remove the `HASURA_CONNECTOR_PORT` variable which is set to `8085`. This is because the connector will run on that port but the docker-mapping is set to map 8085 -> 8080.
57+
### Step 4: Add your resources
5958

60-
Before:
61-
```
62-
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://local.hasura.dev:4317
63-
OTEL_SERVICE_NAME=python_python
64-
HASURA_CONNECTOR_PORT=8085
65-
```
59+
You can add the models, commands, and relationships to your API by tracking them which generates the HML files.
6660

67-
After:
68-
```
69-
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://local.hasura.dev:4317
70-
OTEL_SERVICE_NAME=python_python
61+
```bash
62+
ddn connector-link add-resources python
7163
```
7264

73-
Add the connector link:
65+
### Step 5: Run your connector
7466

75-
```
76-
ddn connector-link add python \
77-
--subgraph python/subgraph.yaml \
78-
--configure-host http://local.hasura.dev:8085 \
79-
--target-env-file python/.env.python.local
80-
```
67+
You can run your connector locally, or include it in the docker setup.
8168

82-
Stop the watch session using Ctrl-C and restart it.
69+
#### Run the connector in Docker
8370

84-
```
85-
HASURA_DDN_PAT=$(ddn auth print-pat) docker compose up --build --watch
71+
To include your connector in the docker setup, include its compose file at the top of your supergraph `compose.yaml` file like this:
72+
73+
```yaml
74+
include:
75+
- path: app/connector/python/compose.yaml
8676
```
8777
88-
Once the connector is running, you can update the connector-link.
78+
#### Run the connector locally
8979
90-
```
91-
ddn connector-link update python \
92-
--subgraph python/subgraph.yaml \
93-
--env-file python/.env.python.local \
94-
--add-all-resources
95-
```
80+
To run your connector outside of Docker first go into the connector directory:
9681
97-
Push the build to the locally running engine:
82+
`cd app/connector/python`
9883

99-
```
100-
ddn supergraph build local \
101-
--output-dir engine \
102-
--subgraph-env-file python:python/.env.python.local
103-
```
84+
Install the requirements:
10485

105-
Now you should be able to write your code in the `functions.py` file, and each time you make changes and save the connector should automatically restart inside the watch session, you'll then need to track those changes and push them to engine.
86+
`pip3 install -r requirements.txt`
10687

107-
You can do that by re-running the above commands:
88+
Then run the connector locally:
10889

109-
To track the changes:
90+
```ddn connector setenv --connector connector.yaml -- python3 functions.py serve```
11091

111-
```
112-
ddn connector-link update python \
113-
--subgraph python/subgraph.yaml \
114-
--env-file python/.env.python.local \
115-
--add-all-resources
116-
```
92+
## Documentation
11793

118-
To push these changes to engine:
94+
View the full documentation for the Python Lambda connector [here](https://github.com/hasura/ndc-python-lambda/blob/main/docs/index.md).
11995

120-
```
121-
ddn supergraph build local \
122-
--output-dir engine \
123-
--subgraph-env-file python:python/.env.python.local
124-
```
96+
## Contributing
97+
98+
Check out our [contributing guide](https://github.com/hasura/ndc-python-lambda/blob/main/docs/contributing.md) for more details.
99+
100+
## License
101+
102+
The Turso connector is available under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).

docs/code-of-conduct.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Hasura Community Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to make participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
- Using welcoming, inclusive and gender-neutral language (example: instead of "Hey guys",
18+
you could use "Hey folks" or "Hey all")
19+
- Being respectful of differing viewpoints and experiences
20+
- Gracefully accepting constructive criticism
21+
- Focusing on what is best for the community
22+
- Showing empathy towards other community members
23+
24+
Examples of unacceptable behavior by participants include:
25+
26+
- The use of sexualized language or imagery and unwelcome sexual attention or
27+
advances
28+
- Trolling, insulting/derogatory comments, and personal or political attacks
29+
- Public or private harassment
30+
- Publishing others' private information, such as a physical or electronic
31+
address, without explicit permission
32+
- Other conduct which could reasonably be considered inappropriate in a
33+
professional setting
34+
35+
## Our Responsibilities
36+
37+
Project maintainers are responsible for clarifying the standards of acceptable
38+
behavior and are expected to take appropriate and fair corrective action in
39+
response to any instances of unacceptable behavior.
40+
41+
Project maintainers have the right and responsibility to remove, edit, or
42+
reject comments, commits, code, wiki edits, issues, and other contributions
43+
that are not aligned to this Code of Conduct, or to ban temporarily or
44+
permanently any contributor for other behaviors that they deem inappropriate,
45+
threatening, offensive, or harmful.
46+
47+
## Scope
48+
49+
This Code of Conduct applies both within project spaces and in public spaces
50+
when an individual is representing the project or its community. Examples of
51+
representing a project or community include using an official project e-mail
52+
address, posting via an official social media account, or acting as an appointed
53+
representative at an online or offline event. Representation of a project may be
54+
further defined and clarified by project maintainers.
55+
56+
## Enforcement
57+
58+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
59+
reported by contacting the project team at [email protected]. All
60+
complaints will be reviewed and investigated and will result in a response that
61+
is deemed necessary and appropriate to the circumstances. The project team is
62+
obligated to maintain confidentiality with regard to the reporter of an incident.
63+
Further details of specific enforcement policies may be posted separately.
64+
65+
Project maintainers who do not follow or enforce the Code of Conduct in good
66+
faith may face temporary or permanent repercussions as determined by other
67+
members of the project's leadership.
68+
69+
## Attribution
70+
71+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
72+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
73+
74+
[homepage]: https://www.contributor-covenant.org

docs/contributing.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Contributing
2+
3+
_First_: if you feel insecure about how to start contributing, feel free to ask us on our
4+
[Discord channel](https://discordapp.com/invite/hasura) in the #contrib channel. You can also just go ahead with your contribution and we'll give you feedback. Don't worry - the worst that can happen is that you'll be politely asked to change something. We appreciate any contributions, and we don't want a wall of rules to stand in the way of that.
5+
6+
However, for those individuals who want a bit more guidance on the best way to contribute to the project, read on. This document will cover what we're looking for. By addressing the points below, the chances that we can quickly merge or address your contributions will increase.
7+
8+
## 1. Code of conduct
9+
10+
Please follow our [Code of conduct](./code-of-conduct.md) in the context of any contributions made to Hasura.
11+
12+
## 2. CLA
13+
14+
For all contributions, a CLA (Contributor License Agreement) needs to be signed
15+
[here](https://cla-assistant.io/hasura/ndc-python-lambda) before (or after) the pull request has been submitted. A bot will prompt contributors to sign the CLA via a pull request comment, if necessary.
16+
17+
## 3. Ways of contributing
18+
19+
### Reporting an Issue
20+
21+
- Make sure you test against the latest released cloud version. It is possible that we may have already fixed the bug you're experiencing.
22+
- Provide steps to reproduce the issue, including Database (e.g. Postgres) version and Hasura DDN version.
23+
- Please include logs, if relevant.
24+
- Create a [issue](https://github.com/hasura/ndc-python-lambda/issues/new/choose).
25+
26+
### Working on an issue
27+
28+
- We use the [fork-and-branch git workflow](https://blog.scottlowe.org/2015/01/27/using-fork-branch-git-workflow/).
29+
- Please make sure there is an issue associated with the work that you're doing.
30+
- If you're working on an issue, please comment that you are doing so to prevent duplicate work by others also.
31+
- Squash your commits and refer to the issue using `fix #<issue-no>` or `close #<issue-no>` in the commit message, at the end. For example: `resolve answers to everything (fix #42)` or `resolve answers to everything, fix #42`
32+
- Rebase master with your branch before submitting a pull request.
33+
34+
## 6. Commit messages
35+
36+
- The first line should be a summary of the changes, not exceeding 50 characters, followed by an optional body which has more details about the changes. Refer to [this link](https://github.com/erlang/otp/wiki/writing-good-commit-messages) for more information on writing good commit messages.
37+
- Use the imperative present tense: "add/fix/change", not "added/fixed/changed" nor "adds/fixes/changes".
38+
- Don't capitalize the first letter of the summary line.
39+
- Don't add a period/dot (.) at the end of the summary line.

docs/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Python Lambda Documentation
2+
3+
The Python Lambda connector is a [Hasura](https://hasura.io/) Native Data Connector.
4+
5+
- [Code of Conduct](./code-of-conduct.md)
6+
- [Contributing](./contributing.md)
7+
- [Production](./production.md)
8+
- [Support](./support.md)
9+
- [Security](./security.md)

docs/logo.svg

Lines changed: 2 additions & 0 deletions
Loading

docs/production.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Hasura Python Lambda Connector in Production
2+
We ship the Python connectors as Docker images.
3+
4+
You can look at the Dockerfile in the root of the repository to see how the image is built.
5+
6+
The connector can be run via a docker-compose file:
7+
8+
```
9+
services:
10+
app_python:
11+
build:
12+
context: .
13+
dockerfile: .hasura-connector/Dockerfile
14+
develop:
15+
watch:
16+
- path: requirements.txt
17+
action: rebuild
18+
target: /functions/requirements.txt
19+
- path: ./
20+
action: sync+restart
21+
target: /functions
22+
environment:
23+
HASURA_SERVICE_TOKEN_SECRET: $APP_PYTHON_HASURA_SERVICE_TOKEN_SECRET
24+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: $APP_PYTHON_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
25+
OTEL_SERVICE_NAME: $APP_PYTHON_OTEL_SERVICE_NAME
26+
extra_hosts:
27+
- local.hasura.dev=host-gateway
28+
ports:
29+
- mode: ingress
30+
target: 8080
31+
published: "8265"
32+
protocol: tcp
33+
```
34+
35+
The Dockerfile for this connector looks like:
36+
37+
```
38+
FROM ghcr.io/hasura/ndc-python-lambda:v0.0.41
39+
40+
COPY requirements.txt /functions/
41+
42+
WORKDIR /functions
43+
RUN python3 -m venv venv && \
44+
. venv/bin/activate && \
45+
pip install -r requirements.txt
46+
47+
COPY ./ /functions
48+
```

0 commit comments

Comments
 (0)