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
4 changes: 2 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
poetry config pypi-token.pypi $PYPI_TOKEN
poetry version ${{ github.ref_name }}
poetry publish --build
poetry install --no-interaction --no-root
poetry install --no-interaction --no-root --with dev,docs --extras "asyncio"
poetry run jake ddt --output-format json -o bom.json --whitelist whitelist.json
- name: update version
uses: stefanzweifel/git-auto-commit-action@v4
Expand All @@ -50,7 +50,7 @@ jobs:
mkdir gh-pages
touch gh-pages/.nojekyll
cd docs
poetry install --no-interaction
poetry install --no-interaction --with dev,docs --extras "asyncio"
poetry run make clean html
cp -r _build/html/* ../gh-pages/
- name: publish docs
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
key: pydeps-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: install dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
run: poetry install --no-interaction --no-root --with dev,docs --extras "asyncio"
- name: install project
run: poetry install --no-interaction
run: poetry install --no-interaction --with dev,docs --extras "asyncio"
- name: run tests
run: |
poetry run pytest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ Pipefile.lock
*.pem
*.pkcs12
bom.json
.coverage
__pycache__
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Spawned from the desire to interact with ServiceNow data in a familiar and consi
pip install pysnc
```

If you also want to install the asyncio support, you can run:

```
pip install pysnc[asyncio]
```

## Quick Start

```python
Expand Down
30 changes: 30 additions & 0 deletions docs/user/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,36 @@ Transform a query into a DataFrame::
>>> df = pd.DataFrame(gr.to_pandas())


Asyncio
-------

You can use most of PySNC’s features asynchronously. Instead of relying on ``pysnc.ServiceNowClient``, use ``pysnc.asyncio.AsyncServiceNowClient``. Below is a simple example of how to migrate from synchronous to asynchronous code:

.. code-block:: diff

- from pysnc import ServiceNowClient
+ import asyncio
+ from pysnc.asyncio import AsyncServiceNowClient

- def main():
- client = ServiceNowClient(...)
- gr = client.GlideRecord('incident')
- gr.query()
- while gr.next():
- print(gr.short_description)
-
- if __name__ == "__main__":
- main()
+ async def main():
+ client = AsyncServiceNowClient(...)
+ gr = await client.GlideRecord('incident')
+ await gr.query()
+ while await gr.next():
+ print(gr.short_description.get_value())
+
+ if __name__ == "__main__":
+ asyncio.run(main())

Performance Concerns
--------------------

Expand Down
126 changes: 119 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
name = "pysnc"
version = "1.1.10"
description = "Python SNC (REST) API"
authors = ["Matthew Gill <[email protected]>"]
authors = [
"Matthew Gill <[email protected]>",
"Patrice Bechard <[email protected]>",
]
license = "MIT"
readme = "README.md"
repository = "https://github.com/ServiceNow/PySNC"
Expand All @@ -23,8 +26,13 @@ requests-oauthlib = { version = ">=1.2.0", optional = true}
certifi = "^2024.7.4"
urllib3 = ">=2.5"

# async deps
asyncio = { version = "^4.0.0", optional = true }
httpx = { version = "^0.28.1", optional = true }

[tool.poetry.extras]
oauth = ["requests-oauthlib"]
asyncio = ["asyncio", "httpx"]

[tool.poetry.group.dev.dependencies]
requests-oauthlib = ">=1.2.0"
Expand Down
32 changes: 32 additions & 0 deletions pysnc/asyncio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Asynchronous implementation of the pysnc package using httpx.AsyncClient.
"""

try:
from .attachment import AsyncAttachment
from .auth import (
AsyncServiceNowFlow,
AsyncServiceNowJWTAuth,
AsyncServiceNowPasswordGrantFlow,
)
from .client import (
AsyncAttachmentAPI,
AsyncBatchAPI,
AsyncServiceNowClient,
AsyncTableAPI,
)
from .record import AsyncGlideRecord
except ImportError:
raise ImportError("httpx is required for the asyncio module. Please install pysnc with the 'asyncio' extra.")

__all__ = [
"AsyncServiceNowClient",
"AsyncTableAPI",
"AsyncBatchAPI",
"AsyncAttachmentAPI",
"AsyncGlideRecord",
"AsyncAttachment",
"AsyncServiceNowFlow",
"AsyncServiceNowPasswordGrantFlow",
"AsyncServiceNowJWTAuth",
]
Loading
Loading