Skip to content

Commit

Permalink
Add initial python client
Browse files Browse the repository at this point in the history
  • Loading branch information
Huluti committed Jan 31, 2024
1 parent a9de001 commit 0d7dc3a
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,34 @@ jobs:
git push --tags origin main
else
echo " No changes, skipping."
fi
build-python:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Build and Deploy 🚀
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm install
npm run generate-python
git clone https://[email protected]/URLR/urlr-python clones/urlr-python &> /dev/null
rsync -avI --delete --exclude='.git/' clients/urlr-python/ clones/urlr-python
cd clones/urlr-python
git status --verbose
if [ -n "$(git status --porcelain)" ]; then
git config --global user.email "[email protected]"
git config --global user.name "Hugo Posnic"
git add .
git commit --message "Deploying from urlr/api-clients-generation@${GITHUB_SHA::8}"
PACKAGE_VERSION=$(awk '/- Package version:/{print $NF}' README.md)
git tag -a $PACKAGE_VERSION -m $PACKAGE_VERSION || true
git push --tags origin main
else
echo " No changes, skipping."
fi
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The clients are automatically pushed to their own repositories thanks to a GitHu

- JavaScript: https://github.com/URLR/urlr-javascript
- PHP: https://github.com/URLR/urlr-php
- Python: https://github.com/URLR/urlr-python

## Manual Setup

Expand All @@ -27,6 +28,12 @@ npm run generate-php
npm run generate-javascript
```

### Python

```
npm run generate-python
```

### Acknowledgements

Greatly inspired by Phrase's way of doing things: https://github.com/phrase/openapi
3 changes: 3 additions & 0 deletions clients/urlr-javascript/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Prevent generator from creating these files:
git_push.sh
.travis.yml
3 changes: 3 additions & 0 deletions clients/urlr-php/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Prevent generator from creating these files:
git_push.sh
.travis.yml
3 changes: 3 additions & 0 deletions clients/urlr-python/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Prevent generator from creating these files:
git_push.sh
.travis.yml
5 changes: 5 additions & 0 deletions clients/urlr-python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## [0.0.1] - 2024-01-31

- First version of the URLR Python client
Empty file.
8 changes: 8 additions & 0 deletions openapi-generator/config-python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
projectName: URLR
packageName: urlr
packageVersion: 0.0.1
infoName: URLR
infoEmail: [email protected]
gitUserId: urlr
gitRepoId: urlr-python
templateDir: openapi-generator/templates/python
115 changes: 115 additions & 0 deletions openapi-generator/templates/python/README.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# {{{packageName}}}@{{packageVersion}}

This SDK is automatically generated with the [OpenAPI Generator](https://openapi-generator.tech) project.

- API version: {{appVersion}}
- Package version: {{packageVersion}}
{{^hideGenerationTimestamp}}
- Build date: {{generatedDate}}
{{/hideGenerationTimestamp}}
- Build package: {{generatorClass}}
{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

## Requirements

Python {{{generatorLanguageVersion}}}

## Installation & Usage

### pip install

If the python package is hosted on a repository, you can install directly using:

```sh
pip install git+https://{{gitHost}}/{{{gitUserId}}}/{{{gitRepoId}}}.git
```
(you may need to run `pip` with root permission: `sudo pip install git+https://{{gitHost}}/{{{gitUserId}}}/{{{gitRepoId}}}.git`)

Then import the package:
```python
import {{{packageName}}}
```

### Setuptools

Install via [Setuptools](http://pypi.python.org/pypi/setuptools).

```sh
python setup.py install --user
```
(or `sudo python setup.py install` to install the package for all users)

Then import the package:
```python
import {{{packageName}}}
```

### Tests

Execute `pytest` to run the tests.

## Getting Started

Please follow the [installation procedure](#installation--usage) and then run the following:

```python
```

A complete example is [available here](examples/example1.py).

## API Endpoints

All URIs are relative to *{{{basePath}}}*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{summary}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}

## Models

{{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}{{{classname}}}.md)
{{/model}}{{/models}}

<a id="documentation-for-authorization"></a>

## Authorization

{{^authMethods}}Endpoints do not require authorization.{{/authMethods}}
{{#hasAuthMethods}}Authentication schemes defined for the API:{{/hasAuthMethods}}
{{#authMethods}}
<a id="{{name}}"></a>
### {{{name}}}

{{#isApiKey}}
- **Type**: API key
- **API key parameter name**: {{{keyParamName}}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}
{{#isBasicBasic}}
- **Type**: HTTP basic authentication
{{/isBasicBasic}}
{{#isBasicBearer}}
- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}
{{/isBasicBearer}}
{{#isHttpSignature}}
- **Type**: HTTP signature authentication
{{/isHttpSignature}}
{{/isBasic}}
{{#isOAuth}}
- **Type**: OAuth
- **Flow**: {{{flow}}}
- **Authorization URL**: {{{authorizationUrl}}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}} - **{{{scope}}}**: {{{description}}}
{{/scopes}}
{{/isOAuth}}

{{/authMethods}}

## Get help / support

Please contact [[email protected]](mailto:[email protected]?subject=[GitHub]%urlr-python) and we can take more direct action toward finding a solution.
82 changes: 82 additions & 0 deletions openapi-generator/templates/python/pyproject.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
[tool.poetry]
name = "{{{packageName}}}"
version = "{{{packageVersion}}}"
description = "Python client for URLR"
authors = ["{{infoName}}{{^infoName}}OpenAPI Generator Community{{/infoName}} <{{infoEmail}}{{^infoEmail}}[email protected]{{/infoEmail}}>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/{{{gitUserId}}}/{{{gitRepoId}}}"
keywords = ["link shortener", "api", "sdk", "client"]
include = ["{{packageName}}/py.typed"]

[tool.poetry.dependencies]
python = "^3.7"

urllib3 = ">= 1.25.3"
python-dateutil = ">=2.8.2"
{{#asyncio}}
aiohttp = ">= 3.8.4"
aiohttp-retry = ">= 2.8.3"
{{/asyncio}}
{{#tornado}}
tornado = ">=4.2,<5"
{{/tornado}}
{{#hasHttpSignatureMethods}}
pem = ">= 19.3.0"
pycryptodome = ">= 3.9.0"
{{/hasHttpSignatureMethods}}
pydantic = ">=2"
typing-extensions = ">=4.7.1"

[tool.poetry.dev-dependencies]
pytest = ">=7.2.1"
tox = ">=3.9.0"
flake8 = ">=4.0.0"
types-python-dateutil = ">=2.8.19.14"
mypy = "1.4.1"


[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.pylint.'MESSAGES CONTROL']
extension-pkg-whitelist = "pydantic"

[tool.mypy]
files = [
"{{{packageName}}}",
#"test", # auto-generated tests
"tests", # hand-written tests
]
# TODO: enable "strict" once all these individual checks are passing
# strict = true

# List from: https://mypy.readthedocs.io/en/stable/existing_code.html#introduce-stricter-options
warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true

## Getting these passing should be easy
strict_equality = true
strict_concatenate = true

## Strongly recommend enabling this one as soon as you can
check_untyped_defs = true

## These shouldn't be too much additional work, but may be tricky to
## get passing if you use a lot of untyped libraries
disallow_subclassing_any = true
disallow_untyped_decorators = true
disallow_any_generics = true

### These next few are various gradations of forcing use of type annotations
#disallow_untyped_calls = true
#disallow_incomplete_defs = true
#disallow_untyped_defs = true
#
### This one isn't too hard to get passing, but return on investment is lower
#no_implicit_reexport = true
#
### This one can be tricky to get passing if you use a lot of untyped libraries
#warn_return_any = true
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
},
"scripts": {
"generate-php": "npx openapi-generator-cli generate -g php-nextgen -o clients/urlr-php -i openapi.yaml -c openapi-generator/config-php.yaml",
"generate-javascript": "npx openapi-generator-cli generate -g typescript-fetch -o clients/urlr-javascript -i openapi.yaml -c openapi-generator/config-javascript.yaml"
"generate-javascript": "npx openapi-generator-cli generate -g typescript-fetch -o clients/urlr-javascript -i openapi.yaml -c openapi-generator/config-javascript.yaml",
"generate-python": "npx openapi-generator-cli generate -g python -o clients/urlr-python -i openapi.yaml -c openapi-generator/config-python.yaml"
}
}

0 comments on commit 0d7dc3a

Please sign in to comment.