pycob
Deploy to Pycob Cloud
Interactive
This will open up a browser window at the end to configure your app for deployment.
pip install pycob
python -m pycob.deploy YOUR_API_KEY
For CI/CD
This will not open a browser window at the end.
pip install pycob
python -m pycob.deploy YOUR_API_KEY --no-ui
Services
import pycob as cob
Store Dataframes
This works for any objects that can be pickled but the most common use case is for storing pandas dataframes.
Store Dictionaries
Secrets
Background Jobs
You can also configure these to run on a schedule on https://www.pycob.com
User Authentication
When using Pycob Cloud, there is a built in user authentication system. You can use this to store and retrieve user data. An invisible 'pycob_id' is passed as a parameter to your app URL if a user is logged in.
Your app will see URLs like this (but you won't see the pycob_id in your browser):
https://my_app.pycob.app/page?my_param=hello&pycob_id=...
Other
Deploy
Gets the user data for the given request
Parameters
- request: The request object
Returns
Returns the user data
Example
user = cob.get_user_from_flask_request(request)
print(user.id)
print(user.email)
print(user.picture)
Sends an email
Example
import pycob as cob
cob.send_email(
from_email='user1@example.com',
to_email='user2@example.com',
subject='Hello',
content='Hello World!'
)
Starts a script with given script name and arguments
Parameters
- script_name: Name of the script to be started
- script_args: Arguments to be passed to the script
Returns
Returns the job ID of the started script
Example
import pycob as cob
cob.start_script(
script_name='my_script.py',
script_args={
'arg1': 'value1',
'arg2': 'value2'
}
)
Pickles a given data and stores it in the cloud with the given filename
Parameters
- data: Data to be pickled
- filename: Name of the file to be created and stored
Returns
None
Example
import pycob as cob
cob.store_pickle(
data=[1,2,3],
filename='my_data.pkl'
)
cob.store_pickle(
data={'key': 'value'},
filename='my_dict.pkl'
)
cob.store_pickle(
data=42,
filename='my_integer.pkl'
)
Loads and returns pickled data from a file in cloud storage
Parameters
- filename: Name of the pickled file to be loaded
Returns
Returns the loaded pickled data
Example
import pycob as cob
data = cob.fetch_pickle('my_data.pkl')
data = cob.fetch_pickle('path/to/my_data.pkl')
data = cob.fetch_pickle('data/my_data.pkl')
Stores a dictionary in the database
Parameters
- table_id: Identifier of the table in which the object has to be stored
- object_id: Identifier of the object in the table
- value: Dictionary to be stored
Returns
None
Example
import pycob as cob
cob.store_dict(
table_id='my_table',
object_id='my_object',
value={
'key1': 'value1',
'key2': 2,
'key3': [1, 2, 3]
}
)
fetch a dictionary
Parameters
- table_id: ID of the table to fetch the object from
- object_id: ID of the object to be fetchd
Returns
Returns the object as a dictionary
Example
import pycob as cob
data = cob.fetch_dict(
table_id='table_123',
object_id='object_456'
)
Deletes the object with given object ID from the table with given table ID
Parameters
- table_id: ID of the table
- object_id: ID of the object to be deleted
Returns
None
Example
import pycob as cob
cob.delete_dict(table_id='table_1', object_id='obj_1')
Queries a table in the database and returns a list of objects matching the given field-value pair
Parameters
- table_id: ID of the table to be queried
- field_name: Name of the field to be queried
- field_value: Value of the field to be queried
- field_value: str or int
Returns
Returns a list of objects matching the given field-value pair
Example
import pycob as cob
cob.query_dict(
table_id='my_table',
field_name='name',
field_value='John'
)
Get a list of objects from a table
This function fetchs a list of objects from a table using the provided table ID.
Parameters
- table_id: ID of the table from which to fetch the objects
Returns
Returns a list of objects from the specified table
Example
import pycob as cob
cob.list_objects(table_id='my_table')
Lists object IDs of a table
Parameters
- table_id: ID of the table
Returns
Returns a list of object IDs of the given table
Example
import pycob as cob
cob.list_object_ids(table_id='my_table')
Stores a secret with given name and value
Parameters
- secret_name: Name of the secret to be stored
- secret_value: Value of the secret to be stored
Returns
None
Example
import pycob as cob
cob.store_secret(
secret_name='my_secret',
secret_value='my_secret_value'
)
fetchs the value of a secret
Parameters
- secret_name: Name of the secret to be fetchd
Returns
Returns the value of the secret if it exists, otherwise None
Example
import pycob as cob
cob.fetch_secret("my_secret")