Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
name: Publish Pypi Package

on:
push:
tags:
- '*'
push:
tags:
- '*'

jobs:
package:
runs-on: ubuntu-latest
name: Publish Pypi Package
package:
runs-on: ubuntu-latest
name: Publish Pypi Package

steps:
- name: Cloning repo
uses: actions/checkout@v2
with:
fetch-depth: 0
steps:
- name: Cloning repo
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Build and publish to pypi
uses: JRubics/poetry-publish@v1.10
with:
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
ignore_dev_requirements: "yes"
build_format: "sdist"
- name: Build and publish to pypi
uses: JRubics/poetry-publish@v1.10
with:
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
ignore_dev_requirements: 'yes'
build_format: 'sdist'
70 changes: 35 additions & 35 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
name: Formatting and Tests

on:
- pull_request
- pull_request

jobs:
test:
runs-on: ubuntu-latest
name: Pytest and Black formatting

strategy:
max-parallel: 4
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- name: Cloning repo
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install

- name: Check Formatting
run: |
poetry run black --check .
poetry run flake8 .
poetry run isort --check .

- name: Run Tests
run: poetry run pytest
test:
runs-on: ubuntu-latest
name: Pytest and Black formatting

strategy:
max-parallel: 4
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- name: Cloning repo
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install

- name: Check Formatting
run: |
poetry run black --check .
poetry run flake8 .
poetry run isort --check .

- name: Run Tests
run: poetry run pytest
9 changes: 8 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ repos:
hooks:
- id: black
language_version: python3

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
21 changes: 21 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"proseWrap": "always",
"singleQuote": true,
"printWidth": 120,
"trailingComma": "all",
"tabWidth": 4,
"overrides": [
{
"files": "**/*.md",
"options": {
"tabWidth": 1
}
},
{
"files": ["**/*.yml", "**/*.yaml"],
"options": {
"tabWidth": 2
}
}
]
}
15 changes: 10 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@

# Flagsmith Python SDK

> Flagsmith allows you to manage feature flags and remote config across multiple projects, environments and organisations.
> Flagsmith allows you to manage feature flags and remote config across multiple projects, environments and
> organisations.

The SDK for Python applications for [https://www.flagsmith.com/](https://www.flagsmith.com/).

## Adding to your project

For full documentation visit [https://docs.flagsmith.com/clients/server-side](https://docs.flagsmith.com/clients/server-side).
For full documentation visit
[https://docs.flagsmith.com/clients/server-side](https://docs.flagsmith.com/clients/server-side).

## Contributing

Please read [CONTRIBUTING.md](https://gist.github.com/kyle-ssg/c36a03aebe492e45cbd3eefb21cb0486) for details on our code of conduct, and the process for submitting pull requests
Please read [CONTRIBUTING.md](https://gist.github.com/kyle-ssg/c36a03aebe492e45cbd3eefb21cb0486) for details on our code
of conduct, and the process for submitting pull requests

## Getting Help

If you encounter a bug or feature request we would like to hear about it. Before you submit an issue please search existing issues in order to prevent duplicates.
If you encounter a bug or feature request we would like to hear about it. Before you submit an issue please search
existing issues in order to prevent duplicates.

## Get in touch

If you have any questions about our projects you can email <a href="mailto:support@flagsmith.com">support@flagsmith.com</a>.
If you have any questions about our projects you can email
<a href="mailto:support@flagsmith.com">support@flagsmith.com</a>.

## Useful links

Expand Down
14 changes: 7 additions & 7 deletions example/readme.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Flagsmith Basic Python Example

This directory contains a basic Flask application which utilises Flagsmith. To run the example application, you'll
need to go through the following steps:
This directory contains a basic Flask application which utilises Flagsmith. To run the example application, you'll need
to go through the following steps:

1. Create an account, organisation and project on [Flagsmith](https://flagsmith.com)
2. Create a feature in the project called "secret_button"
3. Give the feature a value using the json editor as follows:
3. Give the feature a value using the json editor as follows:

```json
{"colour": "#ababab"}
{ "colour": "#ababab" }
```

4. Create a .env file from the template located in this directory with the environment key of one of the environments
in flagsmith (This can be found on the 'settings' page accessed from the menu on the left under the chosen environment.)
4. Create a .env file from the template located in this directory with the environment key of one of the environments in
flagsmith (This can be found on the 'settings' page accessed from the menu on the left under the chosen environment.)
5. From a terminal window, export those environment variables (either manually or by using `export $(cat .env)`)
6. Run the app using `flask run`
7. Browse to http://localhost:5000

Now you can play around with the 'secret_button' feature in flagsmith, turn it on to show it and edit the colour in the
json value to edit the colour of the button. You can also identify as a given user and then update the settings for the
secret button feature for that user in the flagsmith interface to see the affect that has too.
secret button feature for that user in the flagsmith interface to see the affect that has too.
31 changes: 15 additions & 16 deletions example/templates/home.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
<!doctype html>
<!DOCTYPE html>
<head>
<style></style>
</head>
<title>Flagsmith Example</title>
<body>
<p>Hello, {{ identifier or 'World' }}.</p>
{% if show_button %}
<button style="background-color: {{ button_colour }}">A secret button</button>
{% endif %}
<p>Hello, {{ identifier or 'World' }}.</p>
{% if show_button %}
<button style="background-color: {{ button_colour }}">A secret button</button>
{% endif %}

<p></p>
<p></p>

<form action="/" method="GET">
<h3>Identify as a user</h3>
<label for="identifier">Identifier: </label><input name="identifier" id="identifier"><br>
<form action="/" method="GET">
<h3>Identify as a user</h3>
<label for="identifier">Identifier: </label><input name="identifier" id="identifier" /><br />

<p>... with an optional user trait</p>
<label for="trait-key">Trait key: </label><input name="trait-key" id="trait-key"><br>
<label for="trait-value">Trait value: </label><input name="trait-value" id="trait-value"><br><br>
<p>... with an optional user trait</p>
<label for="trait-key">Trait key: </label><input name="trait-key" id="trait-key" /><br />
<label for="trait-value">Trait value: </label><input name="trait-value" id="trait-value" /><br /><br />

<button type="submit">Identify!</button>
</form>

</body>
<button type="submit">Identify!</button>
</form>
</body>
102 changes: 51 additions & 51 deletions tests/data/environment.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
{
"api_key": "B62qaMZNwfiqT76p38ggrQ",
"project": {
"name": "Test project",
"organisation": {
"feature_analytics": false,
"name": "Test Org",
"id": 1,
"persist_trait_data": true,
"stop_serving_flags": false
},
"id": 1,
"hide_disabled_flags": false,
"segments": [
{
"api_key": "B62qaMZNwfiqT76p38ggrQ",
"project": {
"name": "Test project",
"organisation": {
"feature_analytics": false,
"name": "Test Org",
"id": 1,
"persist_trait_data": true,
"stop_serving_flags": false
},
"id": 1,
"name": "Test segment",
"rules": [
{
"type": "ALL",
"rules": [
{
"type": "ALL",
"rules": [],
"conditions": [
{
"operator": "EQUAL",
"property_": "foo",
"value": "bar"
}
"hide_disabled_flags": false,
"segments": [
{
"id": 1,
"name": "Test segment",
"rules": [
{
"type": "ALL",
"rules": [
{
"type": "ALL",
"rules": [],
"conditions": [
{
"operator": "EQUAL",
"property_": "foo",
"value": "bar"
}
]
}
]
}
]
}
]
}
}
]
}
},
"segment_overrides": [],
"id": 1,
"feature_states": [
{
"multivariate_feature_state_values": [],
"feature_state_value": "some-value",
"id": 1,
"featurestate_uuid": "40eb539d-3713-4720-bbd4-829dbef10d51",
"feature": {
"name": "some_feature",
"type": "STANDARD",
"id": 1
},
"segment_id": null,
"enabled": true
}
]
},
"segment_overrides": [],
"id": 1,
"feature_states": [
{
"multivariate_feature_state_values": [],
"feature_state_value": "some-value",
"id": 1,
"featurestate_uuid": "40eb539d-3713-4720-bbd4-829dbef10d51",
"feature": {
"name": "some_feature",
"type": "STANDARD",
"id": 1
},
"segment_id": null,
"enabled": true
}
]
}
}
2 changes: 1 addition & 1 deletion tests/data/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"identity": null,
"feature_segment": null
}
]
]
2 changes: 1 addition & 1 deletion tests/data/identities.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
"feature_segment": null
}
]
}
}