Skip to content
This repository was archived by the owner on Sep 1, 2021. It is now read-only.

Commit 2a619bf

Browse files
committed
Initial client implementation
1 parent e26bbbc commit 2a619bf

17 files changed

+756
-0
lines changed

.gitignore

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*.cover
46+
.hypothesis/
47+
48+
# Translations
49+
*.mo
50+
*.pot
51+
52+
# Django stuff:
53+
*.log
54+
local_settings.py
55+
56+
# Flask stuff:
57+
instance/
58+
.webassets-cache
59+
60+
# Scrapy stuff:
61+
.scrapy
62+
63+
# Sphinx documentation
64+
docs/_build/
65+
66+
# PyBuilder
67+
target/
68+
69+
# Jupyter Notebook
70+
.ipynb_checkpoints
71+
72+
# pyenv
73+
.python-version
74+
75+
# celery beat schedule file
76+
celerybeat-schedule
77+
78+
# SageMath parsed files
79+
*.sage.py
80+
81+
# Environments
82+
.env
83+
.venv
84+
env/
85+
venv/
86+
ENV/
87+
88+
# Spyder project settings
89+
.spyderproject
90+
.spyproject
91+
92+
# Rope project settings
93+
.ropeproject
94+
95+
# mkdocs documentation
96+
/site
97+
98+
# mypy
99+
.mypy_cache/
100+
101+
doc/_*
102+
.idea/

.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# this file is *not* meant to cover or endorse the use of travis, but rather to
2+
# help confirm pull requests to this project.
3+
4+
language: python
5+
6+
env:
7+
- TOXENV=py27
8+
- TOXENV=py33
9+
- TOXENV=py34
10+
- TOXENV=py35
11+
- TOXENV=py36
12+
13+
install: pip install tox
14+
15+
script: tox
16+
17+
notifications:
18+
email: false

LICENSE.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright 2018-2019 Swiftype, Inc. (http://swiftype.com/)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include LICENSE.txt
2+

README.rst

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,136 @@
11
=========================================
22
Python Client for Swiftype App Search API
33
=========================================
4+
5+
**Note: Swiftype App Search is currently in beta**
6+
7+
About
8+
=====
9+
10+
A Python client for interacting with Swiftype App Search API.
11+
12+
For more information, go to our official documentation page:
13+
https://swiftype.com/documentation/app-search/
14+
15+
Installation
16+
============
17+
Swiftype App Search Client can be installed with
18+
`pip <http://pypi.python.org/pypi/pip>`_::
19+
20+
$ python -m pip install swiftype_app_search
21+
22+
You can also download the project source and run::
23+
24+
$ python setup.py install
25+
26+
Dependencies
27+
============
28+
Swiftype App Search supports Python 2.7 and Python 3.3+. It depends on requests.
29+
30+
Usage
31+
========
32+
33+
Instantiating a client
34+
----------------------
35+
36+
.. code-block:: python
37+
38+
>>> from swiftype_app_search import Client
39+
>>> account_host_key = 'host-c5s2mj'
40+
>>> api_key = 'api-mu75psc5egt9ppzuycnc2mc3'
41+
>>> client = Client(account_host_key, api_key)
42+
43+
44+
Index documents
45+
---------------
46+
47+
.. code-block:: python
48+
49+
>>> engine_name = 'favorite-videos'
50+
>>> documents = [
51+
{
52+
'id': 'INscMGmhmX4',
53+
'url': 'https://www.youtube.com/watch?v=INscMGmhmX4',
54+
'title': 'The Original Grumpy Cat',
55+
'body': 'A wonderful video of a magnificent cat.'
56+
},
57+
{
58+
'id': 'JNDFojsd02',
59+
'url': 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
60+
'title': 'Another Grumpy Cat',
61+
'body': 'A great video of another cool cat.'
62+
}
63+
]
64+
65+
>>> client.index_documents(engine_name, documents)
66+
[{'id': 'INscMGmhmX4', 'errors': []}, {'id': 'JNDFojsd02', 'errors': []}]
67+
68+
Get Documents
69+
-------------
70+
71+
.. code-block:: python
72+
73+
>>> engine_name = 'favorite-videos'
74+
>>> client.get_documents(engine_name, ['INscMGmhmX4'])
75+
[{'id': 'INscMGmhmX4','url': 'https://www.youtube.com/watch?v=INscMGmhmX4','title': 'The Original Grumpy Cat','body': 'A wonderful video of a magnificent cat.'}]
76+
77+
78+
Destroy Documents
79+
-----------------
80+
81+
.. code-block:: python
82+
83+
>>> engine_name = 'favorite-videos'
84+
>>> client.destroy_documents(engine_name, ['INscMGmhmX4'])
85+
[{'id': 'INscMGmhmX4','result': True}]
86+
87+
List Engines
88+
------------
89+
90+
.. code-block:: python
91+
92+
>>> client.list_engines()
93+
[{'name': 'favorite-videos'}, {'name': 'another-engine'}]
94+
95+
Get an Engine
96+
-------------
97+
98+
.. code-block:: python
99+
100+
>>> client.get_engine('favorite-videos')
101+
{'name': 'favorite-videos'}
102+
103+
Create an Engine
104+
----------------
105+
106+
.. code-block:: python
107+
108+
>>> client.create_engine('favorite-videos')
109+
{'name': 'favorite-videos'}
110+
111+
Destroy an Engine
112+
-----------------
113+
114+
.. code-block:: python
115+
116+
>>> client.destroy_engine('favorite-videos')
117+
{'deleted': True}
118+
119+
Search
120+
------
121+
122+
.. code-block:: python
123+
124+
>>> client.search('favorite-videos', 'grumpy cat', {})
125+
{'meta': {'page': {'current': 1, 'total_pages': 1, 'total_results': 2, 'size': 10}, ...}, 'results': [...]}
126+
127+
Create a Signed Search Key
128+
--------------------------
129+
Creating a search key that will only search over the body field.
130+
131+
.. code-block:: python
132+
133+
>>> api_key = 'api-mu75psc5egt9ppzuycnc2mc3'
134+
>>> api_key_id = '42'
135+
>>> signed_search_key = Client.create_signed_search_key(api_key, api_key_id, {'search_fields': { 'body': {}}})
136+
>>> client = Client(account_host_key, signed_search_key)

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests==2.18.1
2+
PyJWT==1.5.3

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[bdist_wheel]
2+
# This flag says that the code is written to work on both Python 2 and Python
3+
# 3. If at all possible, it is good practice to do this. If you cannot, you
4+
# will need to generate wheels for each Python version that you support.
5+
universal=1

setup.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from setuptools import setup, find_packages
2+
from codecs import open
3+
from os import path
4+
from unittest import TestLoader
5+
6+
here = path.abspath(path.dirname(__file__))
7+
8+
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
9+
long_description = f.read()
10+
11+
here = path.abspath(path.dirname(__file__))
12+
about = {}
13+
with open(path.join(here, 'swiftype_app_search', '__version__.py'), 'r', 'utf-8') as f:
14+
exec(f.read(), about)
15+
16+
setup(
17+
name=about['__title__'],
18+
version=about['__version__'],
19+
description=about['__description__'],
20+
long_description=long_description,
21+
url=about['__url__'],
22+
author=about['__author__'],
23+
author_email=about['__author_email__'],
24+
license='MIT',
25+
classifiers=[
26+
'Development Status :: 4 - Beta',
27+
'Intended Audience :: Developers',
28+
'License :: OSI Approved :: MIT License',
29+
'Programming Language :: Python :: 2',
30+
'Programming Language :: Python :: 2.7',
31+
'Programming Language :: Python :: 3',
32+
'Programming Language :: Python :: 3.3',
33+
'Programming Language :: Python :: 3.4',
34+
'Programming Language :: Python :: 3.5',
35+
'Programming Language :: Python :: 3.6',
36+
],
37+
keywords='swiftype elastic app search api',
38+
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
39+
install_requires=[
40+
'requests'
41+
],
42+
extras_require={
43+
'test': [
44+
'mock',
45+
'requests_mock',
46+
'future'
47+
],
48+
},
49+
test_suite='tests'
50+
)

swiftype_app_search/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .client import Client
2+
from .__version__ import __version__

swiftype_app_search/__version__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__title__ = 'swiftype_app_search'
2+
__description__ = 'An API client for Swiftype App Search'
3+
__url__ = 'https://github.com/swiftype/swiftype-app-search-python'
4+
__version__ = '0.1.0'
5+
__author__ = 'Swiftype'
6+
__author_email__ = 'eng@swiftype.com'

0 commit comments

Comments
 (0)