Skip to content

Commit

Permalink
Merge pull request #2 from AnkurAnand11/issue-1-create-initial-direct…
Browse files Browse the repository at this point in the history
…ory-structure

create initial directory structure
  • Loading branch information
tkaitchuck authored Oct 27, 2023
2 parents 62b376b + 4153155 commit cbcddf2
Show file tree
Hide file tree
Showing 30 changed files with 2,874 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Contributing to Pravega
======================================

Pravega community follows specific rules and principles. If you're already familiar with them, you'll feel right at home.

Otherwise, please go read Pravega's
* [Contributions guidelines](https://github.com/pravega/pravega/wiki/Contributing)
* [Issue triaging and labeling](https://github.com/pravega/pravega/wiki/Issues-Triaging-and-Labeling)
* [Review process](https://github.com/pravega/pravega/wiki/Pull-Request-and-Reviews)

Happy hacking!
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**Problem description**


**Problem location**


**Suggestions for an improvement**
11 changes: 11 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
**Change log description**
(2-3 concise points about the changes in this PR. When committing this PR, the committer is expected to copy the content of this section to the merge description box)

**Purpose of the change**
(_e.g._, Fixes #666, Closes #1234)

**What the code does**
(Detailed description of the code changes)

**How to verify it**
(Optional: steps to verify that the changes are effective)
34 changes: 34 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: documentation

on:
push:
branches:
- master
pull_request:

jobs:
generate_documentation:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.10'

- name: Generate Pravega Python API documentation.
run: |
pip install 'maturin>=0.14,<0.15' virtualenv pdoc3
virtualenv venv
source venv/bin/activate
maturin develop -m Cargo.toml
pdoc --html pravega_client
mkdir -p book/book/python
cp html/pravega_client/pravega_client.html book/book/python
- name: Deploy
uses: actions/checkout@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./book/book/
56 changes: 56 additions & 0 deletions .github/workflows/python_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: pythontest

on:
# Trigger the workflow on push or pull request,
# but only for the master branch
push:
branches:
- master
pull_request:

jobs:
test_tox:
name: run-tox
runs-on: ubuntu-20.04
timeout-minutes: 25
steps:
- uses: actions/checkout@v2
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
default: true
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: actions/setup-java@v1
with:
java-version: '11' # The JDK version to make available on the path.
- name: Download and Run Pravega standalone
run: |
wget https://github.com/pravega/pravega/releases/download/v0.13.0-rc1/pravega-0.13.0.tgz
tar -xzvf pravega-0.13.0.tgz
pravega-0.13.0/bin/pravega-standalone > pravega.log 2>&1 &
sleep 120 && echo "Started standalone"
tail pravega.log
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install maturin and tox
run: pip install 'maturin>=0.14,<0.15' virtualenv tox==3.28.0 tox-pyo3
- name: Test with tox
run: tox -c tox.ini
- name: Upload Pravega standalone logs
uses: actions/upload-artifact@v2
if: always()
with:
name: pravega-standalone-log
path: pravega.log
retention-days: 5
5 changes: 5 additions & 0 deletions .github/workflows/ubuntu-install-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

sudo apt-get update
sudo apt-get install -y --no-install-recommends \
musl-tools libprotobuf-dev protobuf-compiler
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Cargo
# will have compiled files and executables
/target/
*/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# These are things that generated by integration_test
*/pravega/
pravega-*.tgz

.idea
*.iml
.vscode
/shared/target/
.gradle
/integration_test/*.log
/integration_test/log
*.log
__pycache__/
book/book
html/
python_binding/.tox/

46 changes: 46 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[package]
name = "pravega"
version = "0.3.5"
edition = "2018"
categories = ["network-programming"]
keywords = ["streaming", "client", "pravega"]
readme = "README.md"
repository = "https://github.com/pravega/pravega-client-python"
license = "Apache-2.0"
description = "Pravega client"
authors = ["Pravega Community"]


[lib]
name = "pravega_client"
crate-type = ["cdylib"]

[features]
default = ["python_binding"]
javascript_binding = ["wasm-bindgen"]
python_binding = ["pyo3", "pyo3-asyncio"]

#Run tests for bindings using command cargo test --no-default-features

[dependencies]
tracing = "0.1.17"
tracing-futures = "0.2.4"
tracing-subscriber = "0.2.2"
pravega-client = {version = "0.3"}
pravega-client-shared = {version = "0.3"}
pravega-controller-client = {version = "0.3"}
pravega-wire-protocol = {version = "0.3"}
pravega-client-retry = {version = "0.3"}
pravega-connection-pool = {version = "0.3"}
pravega-client-config = {version = "0.3"}
tokio = "1.1"
lazy_static = "1.4.0"
uuid = {version = "0.8", features = ["v4"]}
futures = "0.3.5"
derive-new = "0.5"
#Python bindings
pyo3 = { version = "0.14.5" , features = ["extension-module", "multiple-pymethods"], optional = true }
pyo3-asyncio = { version = "0.14", features = ["tokio-runtime"], optional = true }
#WASM bindings
wasm-bindgen = { version = "0.2.63", optional = true }
cfg-if = "0.1.10"
7 changes: 7 additions & 0 deletions HEADER
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) Dell Inc., or its subsidiaries. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
1 change: 1 addition & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Copyright (c) 2019-2020 Dell Inc., or its subsidiaries. All Rights Reserved.
21 changes: 21 additions & 0 deletions PythonBinding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Steps to generate python bindings for Pravega:

*Pre-requisites*
- Python 3.8 and up.

1. Ensure `cargo build` works fine.
2. There are two ways of running generating bindings. This describes the steps where maturin is manually installed.
- Manually install [maturin](https://github.com/PyO3/maturin) via `pip install maturin`
- `maturin build --release --no-sdist --strip --manylinux off` This command auto detects the python interpreter and uses it. To
specify a specific interpreter using `--interpreter` option.
- `maturin sdist` to generate the source distribution.
3. Steps to generate bindings using a docker approach.
- `docker run --rm -v --release --no-sdist --strip --manylinux off`
4. After the bindings are generated by either 2 or 3 the next step is to publish the artifacts.
- The artifacts can be published via [twine](https://github.com/pypa/twine)
- `pip install twine`
- `twine upload -r testpypi target/*` this command uploads the artifacts to test.pypi
- `twine upload target/*` this command uploads the artifacts to pypi.
- The artifacts can be published via [maturin](https://github.com/PyO3/maturin)
- `maturin publish -b pyo3 -p XXX -u YYY -r https://test.pypi.org/legacy/` this publishes the bindings to test.pypi
- `maturin publish -b pyo3 -p XXX -u YYY` This publishes the bindings to pypi.
57 changes: 55 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,55 @@
# pravega-client-python
Python client repository
# Pravega Python client.

This project provides a way to interact with [Pravega](http://pravega.io) using Python client.

Pravega is an open source distributed storage service implementing Streams. It offers Stream as the main primitive for
the foundation of reliable storage systems: a high-performance, durable, elastic, and unlimited append-only byte stream
with strict ordering and consistency.

This project supports interaction with Pravega for Python versions 3.8+.
## Install

The client library can be installed using pip.
```shell
pip install pravega
```
The users can also choose to generate the bindings using the commands specified at [PythonBinding](./PythonBinding.md) .

## Example
### Write events
```python
import pravega_client
# assuming Pravega controller is listening at 127.0.0.1:9090
stream_manager = pravega_client.StreamManager("tcp://127.0.0.1:9090")

scope_result = stream_manager.create_scope("scope_foo")
self.assertEqual(True, scope_result, "Scope creation status")

stream_result = stream_manager.create_stream("scope_foo", "stream_bar", 1) # initially stream contains 1 segment
self.assertEqual(True, stream_result, "Stream creation status")

writer = stream_manager.create_writer("scope_foo","stream_bar")
writer.write_event("hello world")
```
### Read events
```python
import pravega_client
# assuming Pravega controller is listening at 127.0.0.1:9090
stream_manager = pravega_client.StreamManager("tcp://127.0.0.1:9090")

reader_group = stream_manager.create_reader_group("my_reader_group", "scope_foo", "stream_bar")

reader = reader_group.create_reader("my_reader");

# acquire a segment slice to read
slice = await reader.get_segment_slice_async()
for event in slice:
print(event.data())

# after calling release segment, data in this segment slice will not be read again by
# readers in the same reader group.
reader.release_segment(slice)

# remember to mark the finished reader as offline.
reader.reader_offline()
```
1 change: 1 addition & 0 deletions book/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
book
23 changes: 23 additions & 0 deletions book/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[book]
authors = ["Tom Kaitchuck <[email protected]>", "Wenqi Mou <[email protected]>", "Sandeep Shridhar <[email protected]>", "thekingofcity <[email protected]>"]
language = "en"
multilingual = false
src = "src"
title = "Pravega Native Client"

[output.html]
mathjax-support = true
site-url = "/book/"

[output.html.playground]
editable = true
line-numbers = true

[output.html.search]
limit-results = 20
use-boolean-and = true
boost-title = 2
boost-hierarchy = 2
boost-paragraph = 1
expand = true
heading-split-level = 2
Loading

0 comments on commit cbcddf2

Please sign in to comment.