shopifyql 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- shopifyql-0.1.2/.gitignore +44 -0
- shopifyql-0.1.2/CHANGELOG.md +17 -0
- shopifyql-0.1.2/CODE_OF_CONDUCT.md +128 -0
- shopifyql-0.1.2/CONTRIBUTING.md +51 -0
- shopifyql-0.1.2/LICENSE.md +7 -0
- shopifyql-0.1.2/PKG-INFO +232 -0
- shopifyql-0.1.2/README.md +198 -0
- shopifyql-0.1.2/pyproject.toml +44 -0
- shopifyql-0.1.2/src/shopifyql/__init__.py +20 -0
- shopifyql-0.1.2/src/shopifyql/auth.py +175 -0
- shopifyql-0.1.2/src/shopifyql/client.py +280 -0
- shopifyql-0.1.2/src/shopifyql/limiter.py +44 -0
- shopifyql-0.1.2/src/shopifyql/results.py +170 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# OS
|
|
2
|
+
.DS_Store
|
|
3
|
+
|
|
4
|
+
# Virtual envs
|
|
5
|
+
.venv/
|
|
6
|
+
.env/
|
|
7
|
+
.python-version
|
|
8
|
+
|
|
9
|
+
# Python cache/bytecode
|
|
10
|
+
__pycache__/
|
|
11
|
+
*.py[cod]
|
|
12
|
+
*$py.class
|
|
13
|
+
|
|
14
|
+
# Packaging
|
|
15
|
+
build/
|
|
16
|
+
dist/
|
|
17
|
+
*.egg-info/
|
|
18
|
+
|
|
19
|
+
# Test & coverage
|
|
20
|
+
.pytest_cache/
|
|
21
|
+
.coverage
|
|
22
|
+
.coverage.*
|
|
23
|
+
htmlcov/
|
|
24
|
+
|
|
25
|
+
# Linters/type checkers
|
|
26
|
+
.mypy_cache/
|
|
27
|
+
.ruff_cache/
|
|
28
|
+
.pyright/
|
|
29
|
+
|
|
30
|
+
# IDE/editor
|
|
31
|
+
.idea/
|
|
32
|
+
.vscode/
|
|
33
|
+
|
|
34
|
+
# UV
|
|
35
|
+
.uv/
|
|
36
|
+
|
|
37
|
+
__pycache__/
|
|
38
|
+
.pytest_cache/
|
|
39
|
+
.nox/
|
|
40
|
+
.venv/
|
|
41
|
+
.coverage
|
|
42
|
+
dist/
|
|
43
|
+
build/
|
|
44
|
+
*.egg-info/
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
|
|
6
|
+
|
|
7
|
+
## [0.1.2] - 2025-11-05
|
|
8
|
+
|
|
9
|
+
- Initial public release.
|
|
10
|
+
|
|
11
|
+
# Changelog
|
|
12
|
+
|
|
13
|
+
All notable changes to this project will be documented in this file.
|
|
14
|
+
|
|
15
|
+
## 0.1.2 - Initial release
|
|
16
|
+
|
|
17
|
+
- Initial client
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity
|
|
10
|
+
and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
- Demonstrating empathy and kindness toward other people
|
|
21
|
+
- Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
- Giving and gracefully accepting constructive feedback
|
|
23
|
+
- Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
- Focusing on what is best not just for us as individuals, but for the
|
|
26
|
+
overall community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
- The use of sexualized language or imagery, and sexual attention or
|
|
31
|
+
advances of any kind
|
|
32
|
+
- Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
- Public or private harassment
|
|
34
|
+
- Publishing others' private information, such as a physical or email
|
|
35
|
+
address, without their explicit permission
|
|
36
|
+
- Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
opensource@shopify.com.
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series
|
|
86
|
+
of actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or
|
|
93
|
+
permanent ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
|
113
|
+
the community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.0, available at
|
|
119
|
+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
|
122
|
+
enforcement ladder](https://github.com/mozilla/diversity).
|
|
123
|
+
|
|
124
|
+
[homepage]: https://www.contributor-covenant.org
|
|
125
|
+
|
|
126
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
127
|
+
https://www.contributor-covenant.org/faq. Translations are available at
|
|
128
|
+
https://www.contributor-covenant.org/translations.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Contributing to shopifyql
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in contributing! We welcome issues and pull requests to make this library better for everyone.
|
|
4
|
+
|
|
5
|
+
By participating in this project, you agree to abide by our [Code of Conduct](./CODE_OF_CONDUCT.md).
|
|
6
|
+
|
|
7
|
+
## How to contribute
|
|
8
|
+
|
|
9
|
+
- Open an issue describing the bug fix or feature you’d like to work on.
|
|
10
|
+
- For small fixes, feel free to open a pull request directly and reference the issue if one exists.
|
|
11
|
+
|
|
12
|
+
## Development setup
|
|
13
|
+
|
|
14
|
+
This project targets Python 3.11+.
|
|
15
|
+
|
|
16
|
+
Using uv:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
uv venv
|
|
20
|
+
uv sync --group dev
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Using pip:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
python -m venv .venv
|
|
27
|
+
source .venv/bin/activate
|
|
28
|
+
pip install -e .[dev]
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Testing
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pytest -q
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Linting & type checking
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
ruff check .
|
|
41
|
+
pyright
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Release process
|
|
45
|
+
|
|
46
|
+
- We follow semantic versioning.
|
|
47
|
+
- Maintainers will publish releases to PyPI.
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
By contributing, you agree that your contributions will be licensed under the terms of the [MIT License](./LICENSE.md).
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025-present, Shopify Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
shopifyql-0.1.2/PKG-INFO
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: shopifyql
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Python SDK and utilities for ShopifyQL queries
|
|
5
|
+
Author-email: "Shopify Inc." <opensource@shopify.com>
|
|
6
|
+
License: Copyright 2025-present, Shopify Inc.
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
13
|
+
License-File: LICENSE.md
|
|
14
|
+
Keywords: Shopify,ShopifyQL,analytics,ecommerce
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
24
|
+
Requires-Python: <4,>=3.11
|
|
25
|
+
Requires-Dist: requests>=2.32
|
|
26
|
+
Provides-Extra: all
|
|
27
|
+
Requires-Dist: pandas>=2.2; extra == 'all'
|
|
28
|
+
Requires-Dist: polars>=1.0; extra == 'all'
|
|
29
|
+
Provides-Extra: pandas
|
|
30
|
+
Requires-Dist: pandas>=2.2; extra == 'pandas'
|
|
31
|
+
Provides-Extra: polars
|
|
32
|
+
Requires-Dist: polars>=1.0; extra == 'polars'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# shopifyql
|
|
36
|
+
|
|
37
|
+
Python SDK for running ShopifyQL queries from Python. It aims to make it fast and easy to get your store data with minimal setup, while staying flexible for power users.
|
|
38
|
+
|
|
39
|
+
Key points:
|
|
40
|
+
|
|
41
|
+
- No hard runtime deps by default (only `requests`).
|
|
42
|
+
- Choose your result backend: dependency-free records (default), pandas, or polars.
|
|
43
|
+
- Optional OAuth helper to obtain an access token during development.
|
|
44
|
+
|
|
45
|
+
## Quick setup with CLI template
|
|
46
|
+
|
|
47
|
+
For the easiest way to test this package, you can use our CLI template that sets up everything for you to start working in a Jupyter Notebook with access to your store:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
shopify app init --template=https://github.com/Shopify/shopify-app-notebooks-template
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This template will:
|
|
54
|
+
- Set up a Python 3.11+ environment with all dependencies needed to run `shopifyql` inside Jupyter notebooks
|
|
55
|
+
- Handle app configuration and authentication automatically
|
|
56
|
+
- Provide a ready-to-use development environment powered by Shopify CLI
|
|
57
|
+
|
|
58
|
+
See the [template repository](https://github.com/Shopify/shopify-app-notebooks-template) for more details.
|
|
59
|
+
|
|
60
|
+
## Requirements
|
|
61
|
+
|
|
62
|
+
- Python 3.11+
|
|
63
|
+
- A Shopify `shop` (e.g., `your-shop-name`) and an Admin API access token with access to the `read_reports` scope.
|
|
64
|
+
|
|
65
|
+
## Installation
|
|
66
|
+
|
|
67
|
+
Base (no heavy dependencies):
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install shopifyql
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
With pandas support:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install "shopifyql[pandas]"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
With polars support:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pip install "shopifyql[polars]"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
With both pandas and polars:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install "shopifyql[all]"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Using uv for local development of this repo:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
uv venv
|
|
95
|
+
uv sync --group dev
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Quick start
|
|
99
|
+
|
|
100
|
+
The default return type is a list of dict records, so you can use the library without dependencies if needed.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from shopifyql import ShopifyQLClient
|
|
104
|
+
|
|
105
|
+
client = ShopifyQLClient(shop="your-shop", access_token="shpat_...")
|
|
106
|
+
|
|
107
|
+
records = client.query("FROM sales SHOW total_sales SINCE 2025-01-01 UNTIL 2025-12-31")
|
|
108
|
+
print(records[:2]) # e.g., [{"total_sales": 123.45}, {"total_sales": 67.89}]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Using pandas
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pip install "shopifyql[pandas]"
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from shopifyql import ShopifyQLClient, ShopifyQLPandasResult
|
|
119
|
+
|
|
120
|
+
client = ShopifyQLClient(shop="your-shop", access_token="shpat_...")
|
|
121
|
+
df = client.query_pandas("FROM sales SHOW orders TIMESERIES DAY SINCE -30d")
|
|
122
|
+
print(df.head())
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Using polars
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pip install "shopifyql[polars]"
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from shopifyql import ShopifyQLClient, ShopifyQLPolarsResult
|
|
133
|
+
|
|
134
|
+
client = ShopifyQLClient(shop="your-shop", access_token="shpat_...")
|
|
135
|
+
df = client.query_polars("FROM sales SHOW total_sales group by product_title")
|
|
136
|
+
print(df.head())
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## OAuth helper (optional)
|
|
140
|
+
|
|
141
|
+
If you don’t have a token handy, you can use a local browser OAuth helper to obtain one during development:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from shopifyql import ShopifyQLClient
|
|
145
|
+
|
|
146
|
+
client = ShopifyQLClient.from_oauth(
|
|
147
|
+
shop="your-shop",
|
|
148
|
+
key="your_api_key",
|
|
149
|
+
secret="your_api_secret",
|
|
150
|
+
port = 4545
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
df = client.query_pandas("FROM sales SHOW total_sales SINCE -7d")
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Steps for oauth
|
|
157
|
+
- Requires read_reports access scope. Also: Level 2 access to Customer data including name, address, phone, and email fields. Please refer to https://shopify.dev/docs/apps/launch/protected-customer-data. Scopes caan be modified in your app version settings: https://dev.shopify.com/dashboard/ -> Your App -> Versions -> Create a version
|
|
158
|
+
- A valid redirect_uri is needed for this oauth flow to work, please use `http://localhost:4545/callback`
|
|
159
|
+
- You can only receive scopes that are enabled in your app settings, if you need more you will want to submit a new app version.
|
|
160
|
+
- If your browser lands on `admin.shopify.com/.../oauth/authorize` and the helper never returns to `http://localhost:4545/callback`, your app’s Redirect URLs probably don’t include the exact `redirect_uri`. Add `http://localhost:4545/callback` (or the port you pass, configurable in from_oauth) to App setup → Redirect URLs, then try again. The `redirect_uri` must match exactly.
|
|
161
|
+
- After auth, you can confirm what the scopes are currently available with:
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
scopes = client.get_current_scopes()
|
|
165
|
+
print(scopes)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Context manager and connection reuse
|
|
169
|
+
|
|
170
|
+
When running multiple queries, use the client as a context manager to reuse a keep-alive `requests.Session` per thread and avoid repeated TLS/HTTP setup costs:
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from shopifyql import ShopifyQLClient
|
|
174
|
+
|
|
175
|
+
SHOP = "your-shop"
|
|
176
|
+
ACCESS_TOKEN = "shpat_..."
|
|
177
|
+
|
|
178
|
+
with ShopifyQLClient(SHOP, ACCESS_TOKEN) as client:
|
|
179
|
+
df1 = client.query_pandas("FROM sales SHOW total_sales GROUP BY product_title SINCE -30d UNTIL now")
|
|
180
|
+
df2 = client.query_pandas("FROM sales SHOW net_sales GROUP BY product_title SINCE -30d UNTIL now")
|
|
181
|
+
print(df1.merge(df2, on="product_title"))
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Custom result classes
|
|
185
|
+
|
|
186
|
+
You can provide your own result transformer by implementing `ShopifyQLResult`:
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
from typing import Any
|
|
190
|
+
from shopifyql import ShopifyQLClient, ShopifyQLResult
|
|
191
|
+
|
|
192
|
+
class MyResult(ShopifyQLResult):
|
|
193
|
+
@classmethod
|
|
194
|
+
def from_table_data(cls, table_data: dict[str, Any]) -> Any:
|
|
195
|
+
# Transform the ShopifyQL tableData into your preferred structure
|
|
196
|
+
return {c["name"]: [row[i] for i, _ in enumerate(table_data["columns"])] for i, c in enumerate(table_data["columns"])}
|
|
197
|
+
|
|
198
|
+
client = ShopifyQLClient(shop="your-shop", access_token="shpat_...")
|
|
199
|
+
custom = client.query("from sales show total_sales", result_class=MyResult)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Error handling & rate limits
|
|
203
|
+
|
|
204
|
+
The client will:
|
|
205
|
+
|
|
206
|
+
- Gate requests with a fixed-window rate limiter to avoid 429s; if the window is exhausted, it sleeps until the next window (with jitter).
|
|
207
|
+
- Backoff and retry on transient request errors (and other request exceptions) up to `max_retries`.
|
|
208
|
+
|
|
209
|
+
You may see:
|
|
210
|
+
|
|
211
|
+
- `requests.exceptions.HTTPError` for non-2xx HTTP responses (after retries as applicable).
|
|
212
|
+
- `requests.exceptions.RequestException` for network errors (after retries).
|
|
213
|
+
- `ValueError("No valid table data found in response")` when the ShopifyQL response is malformed.
|
|
214
|
+
|
|
215
|
+
## Configuration
|
|
216
|
+
|
|
217
|
+
- API version: defaults to `2025-10`. Override via constructor `version="YYYY-MM"`.
|
|
218
|
+
- Timeout: defaults to 10s per request via constructor `connect_timeout`.
|
|
219
|
+
- Retries: defaults to `max_retries=3` with exponential backoff and jitter.
|
|
220
|
+
- Rate limiting: `FixedWindowConfig(window_seconds=60, max_requests=1000)` by default; override via `rate_limit_config`.
|
|
221
|
+
- Connections: when used as a context manager, the client reuses a per-thread `requests.Session` (keep-alive); outside a context it uses ephemeral sessions.
|
|
222
|
+
- Connection pool: `pool_maxsize=10` by default.
|
|
223
|
+
|
|
224
|
+
## Development
|
|
225
|
+
|
|
226
|
+
Clone and develop with uv or pip:
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
uv venv
|
|
230
|
+
uv sync --group=dev
|
|
231
|
+
pytest -q
|
|
232
|
+
```
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# shopifyql
|
|
2
|
+
|
|
3
|
+
Python SDK for running ShopifyQL queries from Python. It aims to make it fast and easy to get your store data with minimal setup, while staying flexible for power users.
|
|
4
|
+
|
|
5
|
+
Key points:
|
|
6
|
+
|
|
7
|
+
- No hard runtime deps by default (only `requests`).
|
|
8
|
+
- Choose your result backend: dependency-free records (default), pandas, or polars.
|
|
9
|
+
- Optional OAuth helper to obtain an access token during development.
|
|
10
|
+
|
|
11
|
+
## Quick setup with CLI template
|
|
12
|
+
|
|
13
|
+
For the easiest way to test this package, you can use our CLI template that sets up everything for you to start working in a Jupyter Notebook with access to your store:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
shopify app init --template=https://github.com/Shopify/shopify-app-notebooks-template
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This template will:
|
|
20
|
+
- Set up a Python 3.11+ environment with all dependencies needed to run `shopifyql` inside Jupyter notebooks
|
|
21
|
+
- Handle app configuration and authentication automatically
|
|
22
|
+
- Provide a ready-to-use development environment powered by Shopify CLI
|
|
23
|
+
|
|
24
|
+
See the [template repository](https://github.com/Shopify/shopify-app-notebooks-template) for more details.
|
|
25
|
+
|
|
26
|
+
## Requirements
|
|
27
|
+
|
|
28
|
+
- Python 3.11+
|
|
29
|
+
- A Shopify `shop` (e.g., `your-shop-name`) and an Admin API access token with access to the `read_reports` scope.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
Base (no heavy dependencies):
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install shopifyql
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
With pandas support:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install "shopifyql[pandas]"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
With polars support:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install "shopifyql[polars]"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
With both pandas and polars:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install "shopifyql[all]"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Using uv for local development of this repo:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
uv venv
|
|
61
|
+
uv sync --group dev
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Quick start
|
|
65
|
+
|
|
66
|
+
The default return type is a list of dict records, so you can use the library without dependencies if needed.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from shopifyql import ShopifyQLClient
|
|
70
|
+
|
|
71
|
+
client = ShopifyQLClient(shop="your-shop", access_token="shpat_...")
|
|
72
|
+
|
|
73
|
+
records = client.query("FROM sales SHOW total_sales SINCE 2025-01-01 UNTIL 2025-12-31")
|
|
74
|
+
print(records[:2]) # e.g., [{"total_sales": 123.45}, {"total_sales": 67.89}]
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Using pandas
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install "shopifyql[pandas]"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from shopifyql import ShopifyQLClient, ShopifyQLPandasResult
|
|
85
|
+
|
|
86
|
+
client = ShopifyQLClient(shop="your-shop", access_token="shpat_...")
|
|
87
|
+
df = client.query_pandas("FROM sales SHOW orders TIMESERIES DAY SINCE -30d")
|
|
88
|
+
print(df.head())
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Using polars
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
pip install "shopifyql[polars]"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from shopifyql import ShopifyQLClient, ShopifyQLPolarsResult
|
|
99
|
+
|
|
100
|
+
client = ShopifyQLClient(shop="your-shop", access_token="shpat_...")
|
|
101
|
+
df = client.query_polars("FROM sales SHOW total_sales group by product_title")
|
|
102
|
+
print(df.head())
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## OAuth helper (optional)
|
|
106
|
+
|
|
107
|
+
If you don’t have a token handy, you can use a local browser OAuth helper to obtain one during development:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from shopifyql import ShopifyQLClient
|
|
111
|
+
|
|
112
|
+
client = ShopifyQLClient.from_oauth(
|
|
113
|
+
shop="your-shop",
|
|
114
|
+
key="your_api_key",
|
|
115
|
+
secret="your_api_secret",
|
|
116
|
+
port = 4545
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
df = client.query_pandas("FROM sales SHOW total_sales SINCE -7d")
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Steps for oauth
|
|
123
|
+
- Requires read_reports access scope. Also: Level 2 access to Customer data including name, address, phone, and email fields. Please refer to https://shopify.dev/docs/apps/launch/protected-customer-data. Scopes caan be modified in your app version settings: https://dev.shopify.com/dashboard/ -> Your App -> Versions -> Create a version
|
|
124
|
+
- A valid redirect_uri is needed for this oauth flow to work, please use `http://localhost:4545/callback`
|
|
125
|
+
- You can only receive scopes that are enabled in your app settings, if you need more you will want to submit a new app version.
|
|
126
|
+
- If your browser lands on `admin.shopify.com/.../oauth/authorize` and the helper never returns to `http://localhost:4545/callback`, your app’s Redirect URLs probably don’t include the exact `redirect_uri`. Add `http://localhost:4545/callback` (or the port you pass, configurable in from_oauth) to App setup → Redirect URLs, then try again. The `redirect_uri` must match exactly.
|
|
127
|
+
- After auth, you can confirm what the scopes are currently available with:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
scopes = client.get_current_scopes()
|
|
131
|
+
print(scopes)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Context manager and connection reuse
|
|
135
|
+
|
|
136
|
+
When running multiple queries, use the client as a context manager to reuse a keep-alive `requests.Session` per thread and avoid repeated TLS/HTTP setup costs:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from shopifyql import ShopifyQLClient
|
|
140
|
+
|
|
141
|
+
SHOP = "your-shop"
|
|
142
|
+
ACCESS_TOKEN = "shpat_..."
|
|
143
|
+
|
|
144
|
+
with ShopifyQLClient(SHOP, ACCESS_TOKEN) as client:
|
|
145
|
+
df1 = client.query_pandas("FROM sales SHOW total_sales GROUP BY product_title SINCE -30d UNTIL now")
|
|
146
|
+
df2 = client.query_pandas("FROM sales SHOW net_sales GROUP BY product_title SINCE -30d UNTIL now")
|
|
147
|
+
print(df1.merge(df2, on="product_title"))
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Custom result classes
|
|
151
|
+
|
|
152
|
+
You can provide your own result transformer by implementing `ShopifyQLResult`:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from typing import Any
|
|
156
|
+
from shopifyql import ShopifyQLClient, ShopifyQLResult
|
|
157
|
+
|
|
158
|
+
class MyResult(ShopifyQLResult):
|
|
159
|
+
@classmethod
|
|
160
|
+
def from_table_data(cls, table_data: dict[str, Any]) -> Any:
|
|
161
|
+
# Transform the ShopifyQL tableData into your preferred structure
|
|
162
|
+
return {c["name"]: [row[i] for i, _ in enumerate(table_data["columns"])] for i, c in enumerate(table_data["columns"])}
|
|
163
|
+
|
|
164
|
+
client = ShopifyQLClient(shop="your-shop", access_token="shpat_...")
|
|
165
|
+
custom = client.query("from sales show total_sales", result_class=MyResult)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Error handling & rate limits
|
|
169
|
+
|
|
170
|
+
The client will:
|
|
171
|
+
|
|
172
|
+
- Gate requests with a fixed-window rate limiter to avoid 429s; if the window is exhausted, it sleeps until the next window (with jitter).
|
|
173
|
+
- Backoff and retry on transient request errors (and other request exceptions) up to `max_retries`.
|
|
174
|
+
|
|
175
|
+
You may see:
|
|
176
|
+
|
|
177
|
+
- `requests.exceptions.HTTPError` for non-2xx HTTP responses (after retries as applicable).
|
|
178
|
+
- `requests.exceptions.RequestException` for network errors (after retries).
|
|
179
|
+
- `ValueError("No valid table data found in response")` when the ShopifyQL response is malformed.
|
|
180
|
+
|
|
181
|
+
## Configuration
|
|
182
|
+
|
|
183
|
+
- API version: defaults to `2025-10`. Override via constructor `version="YYYY-MM"`.
|
|
184
|
+
- Timeout: defaults to 10s per request via constructor `connect_timeout`.
|
|
185
|
+
- Retries: defaults to `max_retries=3` with exponential backoff and jitter.
|
|
186
|
+
- Rate limiting: `FixedWindowConfig(window_seconds=60, max_requests=1000)` by default; override via `rate_limit_config`.
|
|
187
|
+
- Connections: when used as a context manager, the client reuses a per-thread `requests.Session` (keep-alive); outside a context it uses ephemeral sessions.
|
|
188
|
+
- Connection pool: `pool_maxsize=10` by default.
|
|
189
|
+
|
|
190
|
+
## Development
|
|
191
|
+
|
|
192
|
+
Clone and develop with uv or pip:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
uv venv
|
|
196
|
+
uv sync --group=dev
|
|
197
|
+
pytest -q
|
|
198
|
+
```
|