Skip to content
Open
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
3 changes: 0 additions & 3 deletions .coveragerc

This file was deleted.

5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

126 changes: 4 additions & 122 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,131 +1,13 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

.idea/
.env*.python-version
*.egg-info
.env
.envrc
2 changes: 0 additions & 2 deletions .isort.cfg

This file was deleted.

58 changes: 33 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
default_language_version:
python: python3.12

default_stages: [pre-commit, pre-push]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
args: ['--unsafe']
- id: end-of-file-fixer
- id: trailing-whitespace
- id: flake8
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
language_version: python3.9
args: [--config=pyproject.toml]
- repo: https://github.com/asottile/seed-isort-config
rev: v2.1.1
hooks:
- id: seed-isort-config
args: [--exclude=templates/]
- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
hooks:
- id: isort
types: [file, python]
args: [--settings-path=pyproject.toml]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
args: ['--maxkb=1024']
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
exclude: LICENSE

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.13.0
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format

- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
- id: detect-secrets
args: ['--baseline', '.secrets.baseline']
exclude: 'poetry.lock|docs/.*\.mdx|opennem/db/migrations/versions/.*\.py|opennem/db/migrations/versions_old/.*\.py|tests/.*\.py'

# - repo: https://github.com/RobertCraigie/pyright-python
# rev: v1.1.295
# hooks:
# - id: pyright
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.14
22 changes: 17 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
test:
python -m unittest -v
.DEFAULT_GOAL := all
.SHELLFLAGS = -e
UPGRADE_ARGS ?= --upgrade
projectname = sanity-python
projectpath = sanity

coverage:
coverage run -m unittest discover
coverage report --skip-empty --sort=name --precision=0
# tools
ruff-check = uv run ruff check $(projectpath)
ruff-format = uv run ruff format $(projectpath)
ruff-lint = uv run ruff lint $(projectpath)
pyright = uv run pyright -v .venv $(projectpath)
BUMP ?= dev

.PHONY: clean
clean:
ruff clean
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete -o -type d -name .mypy_cache -delete
rm -rf build
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# sanity-python
Sanity Python Client

## Example
Python client for Sanity.io CMS HTTP API.

> **ℹ️ Note:**
> This package is an active **fork** of the original project at [OmniPro-Group/sanity-python](https://github.com/OmniPro-Group/sanity-python/).


## Examples

```python
from sanity.client import Client
import logging
Expand Down Expand Up @@ -83,12 +89,3 @@ result = client.mutate(
)
print_json_in_colour(result)
```

## Pre Commit Howto
```shell
pip install -r requirements.txt
pre-commit --version
# create .pre-commit-config.yaml file
pre-commit install
pre-commit run --all-files
```
25 changes: 25 additions & 0 deletions examples/simple_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import logging

from dotenv import load_dotenv

from sanity import Client as SanityClient

load_dotenv()

logger = logging.getLogger("simple_list")

sanity_client = SanityClient(
logger=logger,
)


def run_example_query():
response = sanity_client.query(
groq="*[_type == 'facility']",
variables={"language": "es", "t": 4},
)
print(response)


if __name__ == "__main__":
run_example_query()
103 changes: 91 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,91 @@
[tool.black]
line-length = 88
target_version = ['py39']
include = '\.py'
exclude = '''
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| templates
| docs
)/
'''
[project]
name = "python-sanity"
version = "0.1.0.dev3"
description = "Python client for Sanity.io CMS HTTP API"
readme = "README.md"
license = { file="LICENSE" }
requires-python = "<4.0,>=3.10"
authors = [
{ name="Nik Cubrilovic", email="[email protected]" },
{ name="OmniPro Group", email="[email protected]" },
]
keywords = [
"sanity",
"sanity-http-api",
]
classifiers = [
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.10",
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = [
"requests>=2.32.5",
]

[dependency-groups]
dev = [
"basedpyright>=1.32.1",
"click>=8.3.0",
"coverage>=7.11.0",
"mock>=5.2.0",
"pre-commit>=4.3.0",
"pygments>=2.19.2",
"python-dotenv>=1.2.1",
"responses>=0.25.8",
"ruff>=0.14.2",
]

[tool.uv]
package = true

[tool.ruff]
target-version = "py39"
line-length = 88

[tool.ruff.lint]
select = [
"F", # flake8
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"C", # flake8-comprehensions
"B", # flake8-bugbear
"UP", # pyupgrade
"T", # mypy
]
ignore = [
"B008", # do not perform function calls in argument defaults
"T201", # ignore print
"T203", # ignore pprint
"C901", # ignore function too complex
"E721", # igmpre unsafe type comparison
]

[tool.ruff.format]
quote-style = "double"
docstring-code-format = true
docstring-code-line-length = 88

[tool.pyright]
include = ["sanity/**/*.py"]
exclude = ["sanity/tests/**/*.py"]

reportMissingImports = "error"
reportMissingTypeStubs = false

[tool.pytest.ini_options]
log_cli = true
log_level = "DEBUG"
log_format = "%(asctime)s %(levelname)s %(message)s"
log_date_format = "%Y-%m-%d %H:%M:%S"
minversion = "6.0"
addopts = "-ra -q"
testpaths = [
"tests",
]

Loading