repo
stringlengths
7
54
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
20
28.4k
docstring
stringlengths
1
46.3k
docstring_tokens
listlengths
1
1.66k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
summary
stringlengths
4
350
obf_code
stringlengths
7.85k
764k
pallets/flask-sqlalchemy
examples/flaskr/flaskr/auth/views.py
load_logged_in_user
def load_logged_in_user(): """If a user id is stored in the session, load the user object from the database into ``g.user``.""" user_id = session.get("user_id") g.user = User.query.get(user_id) if user_id is not None else None
python
def load_logged_in_user(): """If a user id is stored in the session, load the user object from the database into ``g.user``.""" user_id = session.get("user_id") g.user = User.query.get(user_id) if user_id is not None else None
[ "def", "load_logged_in_user", "(", ")", ":", "user_id", "=", "session", ".", "get", "(", "\"user_id\"", ")", "g", ".", "user", "=", "User", ".", "query", ".", "get", "(", "user_id", ")", "if", "user_id", "is", "not", "None", "else", "None" ]
If a user id is stored in the session, load the user object from the database into ``g.user``.
[ "If", "a", "user", "id", "is", "stored", "in", "the", "session", "load", "the", "user", "object", "from", "the", "database", "into", "g", ".", "user", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/auth/views.py#L32-L36
train
Load the logged in user into the g. user attribute.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
examples/flaskr/flaskr/auth/views.py
register
def register(): """Register a new user. Validates that the username is not already taken. Hashes the password for security. """ if request.method == "POST": username = request.form["username"] password = request.form["password"] error = None if not username: ...
python
def register(): """Register a new user. Validates that the username is not already taken. Hashes the password for security. """ if request.method == "POST": username = request.form["username"] password = request.form["password"] error = None if not username: ...
[ "def", "register", "(", ")", ":", "if", "request", ".", "method", "==", "\"POST\"", ":", "username", "=", "request", ".", "form", "[", "\"username\"", "]", "password", "=", "request", ".", "form", "[", "\"password\"", "]", "error", "=", "None", "if", "...
Register a new user. Validates that the username is not already taken. Hashes the password for security.
[ "Register", "a", "new", "user", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/auth/views.py#L40-L68
train
Register a new user.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
examples/flaskr/flaskr/auth/views.py
login
def login(): """Log in a registered user by adding the user id to the session.""" if request.method == "POST": username = request.form["username"] password = request.form["password"] error = None user = User.query.filter_by(username=username).first() if user is None: ...
python
def login(): """Log in a registered user by adding the user id to the session.""" if request.method == "POST": username = request.form["username"] password = request.form["password"] error = None user = User.query.filter_by(username=username).first() if user is None: ...
[ "def", "login", "(", ")", ":", "if", "request", ".", "method", "==", "\"POST\"", ":", "username", "=", "request", ".", "form", "[", "\"username\"", "]", "password", "=", "request", ".", "form", "[", "\"password\"", "]", "error", "=", "None", "user", "=...
Log in a registered user by adding the user id to the session.
[ "Log", "in", "a", "registered", "user", "by", "adding", "the", "user", "id", "to", "the", "session", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/auth/views.py#L72-L93
train
Log in a registered user by adding the user id to the session.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
examples/flaskr/flaskr/blog/views.py
index
def index(): """Show all the posts, most recent first.""" posts = Post.query.order_by(Post.created.desc()).all() return render_template("blog/index.html", posts=posts)
python
def index(): """Show all the posts, most recent first.""" posts = Post.query.order_by(Post.created.desc()).all() return render_template("blog/index.html", posts=posts)
[ "def", "index", "(", ")", ":", "posts", "=", "Post", ".", "query", ".", "order_by", "(", "Post", ".", "created", ".", "desc", "(", ")", ")", ".", "all", "(", ")", "return", "render_template", "(", "\"blog/index.html\"", ",", "posts", "=", "posts", ")...
Show all the posts, most recent first.
[ "Show", "all", "the", "posts", "most", "recent", "first", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/blog/views.py#L18-L21
train
Show all the posts most recent first.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
examples/flaskr/flaskr/blog/views.py
get_post
def get_post(id, check_author=True): """Get a post and its author by id. Checks that the id exists and optionally that the current user is the author. :param id: id of post to get :param check_author: require the current user to be the author :return: the post with author information :rais...
python
def get_post(id, check_author=True): """Get a post and its author by id. Checks that the id exists and optionally that the current user is the author. :param id: id of post to get :param check_author: require the current user to be the author :return: the post with author information :rais...
[ "def", "get_post", "(", "id", ",", "check_author", "=", "True", ")", ":", "post", "=", "Post", ".", "query", ".", "get_or_404", "(", "id", ",", "f\"Post id {id} doesn't exist.\"", ")", "if", "check_author", "and", "post", ".", "author", "!=", "g", ".", "...
Get a post and its author by id. Checks that the id exists and optionally that the current user is the author. :param id: id of post to get :param check_author: require the current user to be the author :return: the post with author information :raise 404: if a post with the given id doesn't e...
[ "Get", "a", "post", "and", "its", "author", "by", "id", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/blog/views.py#L24-L41
train
Get a post and its author by id.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
examples/flaskr/flaskr/blog/views.py
create
def create(): """Create a new post for the current user.""" if request.method == "POST": title = request.form["title"] body = request.form["body"] error = None if not title: error = "Title is required." if error is not None: flash(error) ...
python
def create(): """Create a new post for the current user.""" if request.method == "POST": title = request.form["title"] body = request.form["body"] error = None if not title: error = "Title is required." if error is not None: flash(error) ...
[ "def", "create", "(", ")", ":", "if", "request", ".", "method", "==", "\"POST\"", ":", "title", "=", "request", ".", "form", "[", "\"title\"", "]", "body", "=", "request", ".", "form", "[", "\"body\"", "]", "error", "=", "None", "if", "not", "title",...
Create a new post for the current user.
[ "Create", "a", "new", "post", "for", "the", "current", "user", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/blog/views.py#L46-L63
train
Create a new post for the current user.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
examples/flaskr/flaskr/blog/views.py
update
def update(id): """Update a post if the current user is the author.""" post = get_post(id) if request.method == "POST": title = request.form["title"] body = request.form["body"] error = None if not title: error = "Title is required." if error is not Non...
python
def update(id): """Update a post if the current user is the author.""" post = get_post(id) if request.method == "POST": title = request.form["title"] body = request.form["body"] error = None if not title: error = "Title is required." if error is not Non...
[ "def", "update", "(", "id", ")", ":", "post", "=", "get_post", "(", "id", ")", "if", "request", ".", "method", "==", "\"POST\"", ":", "title", "=", "request", ".", "form", "[", "\"title\"", "]", "body", "=", "request", ".", "form", "[", "\"body\"", ...
Update a post if the current user is the author.
[ "Update", "a", "post", "if", "the", "current", "user", "is", "the", "author", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/blog/views.py#L68-L88
train
Update a post if the current user is the author.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
examples/flaskr/flaskr/blog/views.py
delete
def delete(id): """Delete a post. Ensures that the post exists and that the logged in user is the author of the post. """ post = get_post(id) db.session.delete(post) db.session.commit() return redirect(url_for("blog.index"))
python
def delete(id): """Delete a post. Ensures that the post exists and that the logged in user is the author of the post. """ post = get_post(id) db.session.delete(post) db.session.commit() return redirect(url_for("blog.index"))
[ "def", "delete", "(", "id", ")", ":", "post", "=", "get_post", "(", "id", ")", "db", ".", "session", ".", "delete", "(", "post", ")", "db", ".", "session", ".", "commit", "(", ")", "return", "redirect", "(", "url_for", "(", "\"blog.index\"", ")", "...
Delete a post. Ensures that the post exists and that the logged in user is the author of the post.
[ "Delete", "a", "post", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/blog/views.py#L93-L102
train
Delete a post.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/utils.py
parse_version
def parse_version(v): """ Take a string version and conver it to a tuple (for easier comparison), e.g.: "1.2.3" --> (1, 2, 3) "1.2" --> (1, 2, 0) "1" --> (1, 0, 0) """ parts = v.split(".") # Pad the list to make sure there is three elements so that we get maj...
python
def parse_version(v): """ Take a string version and conver it to a tuple (for easier comparison), e.g.: "1.2.3" --> (1, 2, 3) "1.2" --> (1, 2, 0) "1" --> (1, 0, 0) """ parts = v.split(".") # Pad the list to make sure there is three elements so that we get maj...
[ "def", "parse_version", "(", "v", ")", ":", "parts", "=", "v", ".", "split", "(", "\".\"", ")", "# Pad the list to make sure there is three elements so that we get major, minor, point", "# comparisons that default to \"0\" if not given. I.e. \"1.2\" --> (1, 2, 0)", "parts", "=", ...
Take a string version and conver it to a tuple (for easier comparison), e.g.: "1.2.3" --> (1, 2, 3) "1.2" --> (1, 2, 0) "1" --> (1, 0, 0)
[ "Take", "a", "string", "version", "and", "conver", "it", "to", "a", "tuple", "(", "for", "easier", "comparison", ")", "e", ".", "g", ".", ":" ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/utils.py#L6-L18
train
Takes a string version and conver it to a tuple.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
SignallingSession.get_bind
def get_bind(self, mapper=None, clause=None): """Return the engine or connection for a given model or table, using the ``__bind_key__`` if it is set. """ # mapper is None if someone tries to just get a connection if mapper is not None: try: # SA >= 1.3...
python
def get_bind(self, mapper=None, clause=None): """Return the engine or connection for a given model or table, using the ``__bind_key__`` if it is set. """ # mapper is None if someone tries to just get a connection if mapper is not None: try: # SA >= 1.3...
[ "def", "get_bind", "(", "self", ",", "mapper", "=", "None", ",", "clause", "=", "None", ")", ":", "# mapper is None if someone tries to just get a connection", "if", "mapper", "is", "not", "None", ":", "try", ":", "# SA >= 1.3", "persist_selectable", "=", "mapper"...
Return the engine or connection for a given model or table, using the ``__bind_key__`` if it is set.
[ "Return", "the", "engine", "or", "connection", "for", "a", "given", "model", "or", "table", "using", "the", "__bind_key__", "if", "it", "is", "set", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L149-L167
train
Return the engine or connection for a given model or an object.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
Pagination.pages
def pages(self): """The total number of pages""" if self.per_page == 0 or self.total is None: pages = 0 else: pages = int(ceil(self.total / float(self.per_page))) return pages
python
def pages(self): """The total number of pages""" if self.per_page == 0 or self.total is None: pages = 0 else: pages = int(ceil(self.total / float(self.per_page))) return pages
[ "def", "pages", "(", "self", ")", ":", "if", "self", ".", "per_page", "==", "0", "or", "self", ".", "total", "is", "None", ":", "pages", "=", "0", "else", ":", "pages", "=", "int", "(", "ceil", "(", "self", ".", "total", "/", "float", "(", "sel...
The total number of pages
[ "The", "total", "number", "of", "pages" ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L331-L337
train
The total number of pages
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
Pagination.next
def next(self, error_out=False): """Returns a :class:`Pagination` object for the next page.""" assert self.query is not None, 'a query object is required ' \ 'for this method to work' return self.query.paginate(self.page + 1, self.per_page, error_out)
python
def next(self, error_out=False): """Returns a :class:`Pagination` object for the next page.""" assert self.query is not None, 'a query object is required ' \ 'for this method to work' return self.query.paginate(self.page + 1, self.per_page, error_out)
[ "def", "next", "(", "self", ",", "error_out", "=", "False", ")", ":", "assert", "self", ".", "query", "is", "not", "None", ",", "'a query object is required '", "'for this method to work'", "return", "self", ".", "query", ".", "paginate", "(", "self", ".", "...
Returns a :class:`Pagination` object for the next page.
[ "Returns", "a", ":", "class", ":", "Pagination", "object", "for", "the", "next", "page", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L357-L361
train
Returns a : class : Pagination object for the next page.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
BaseQuery.get_or_404
def get_or_404(self, ident, description=None): """Like :meth:`get` but aborts with 404 if not found instead of returning ``None``.""" rv = self.get(ident) if rv is None: abort(404, description=description) return rv
python
def get_or_404(self, ident, description=None): """Like :meth:`get` but aborts with 404 if not found instead of returning ``None``.""" rv = self.get(ident) if rv is None: abort(404, description=description) return rv
[ "def", "get_or_404", "(", "self", ",", "ident", ",", "description", "=", "None", ")", ":", "rv", "=", "self", ".", "get", "(", "ident", ")", "if", "rv", "is", "None", ":", "abort", "(", "404", ",", "description", "=", "description", ")", "return", ...
Like :meth:`get` but aborts with 404 if not found instead of returning ``None``.
[ "Like", ":", "meth", ":", "get", "but", "aborts", "with", "404", "if", "not", "found", "instead", "of", "returning", "None", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L419-L425
train
Like get but aborts with 404 if not found instead of returning None.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
BaseQuery.first_or_404
def first_or_404(self, description=None): """Like :meth:`first` but aborts with 404 if not found instead of returning ``None``.""" rv = self.first() if rv is None: abort(404, description=description) return rv
python
def first_or_404(self, description=None): """Like :meth:`first` but aborts with 404 if not found instead of returning ``None``.""" rv = self.first() if rv is None: abort(404, description=description) return rv
[ "def", "first_or_404", "(", "self", ",", "description", "=", "None", ")", ":", "rv", "=", "self", ".", "first", "(", ")", "if", "rv", "is", "None", ":", "abort", "(", "404", ",", "description", "=", "description", ")", "return", "rv" ]
Like :meth:`first` but aborts with 404 if not found instead of returning ``None``.
[ "Like", ":", "meth", ":", "first", "but", "aborts", "with", "404", "if", "not", "found", "instead", "of", "returning", "None", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L427-L433
train
Like first but aborts with 404 if not found instead of returning None.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
BaseQuery.paginate
def paginate(self, page=None, per_page=None, error_out=True, max_per_page=None, count=True): """Returns ``per_page`` items from page ``page``. If ``page`` or ``per_page`` are ``None``, they will be retrieved from the request query. If ``max_per_page`` is specified, ``per_page`` will be ...
python
def paginate(self, page=None, per_page=None, error_out=True, max_per_page=None, count=True): """Returns ``per_page`` items from page ``page``. If ``page`` or ``per_page`` are ``None``, they will be retrieved from the request query. If ``max_per_page`` is specified, ``per_page`` will be ...
[ "def", "paginate", "(", "self", ",", "page", "=", "None", ",", "per_page", "=", "None", ",", "error_out", "=", "True", ",", "max_per_page", "=", "None", ",", "count", "=", "True", ")", ":", "if", "request", ":", "if", "page", "is", "None", ":", "tr...
Returns ``per_page`` items from page ``page``. If ``page`` or ``per_page`` are ``None``, they will be retrieved from the request query. If ``max_per_page`` is specified, ``per_page`` will be limited to that value. If there is no request or they aren't in the query, they default to 1 and...
[ "Returns", "per_page", "items", "from", "page", "page", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L435-L512
train
Returns a pagination object for the items in the current page.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
SQLAlchemy.create_scoped_session
def create_scoped_session(self, options=None): """Create a :class:`~sqlalchemy.orm.scoping.scoped_session` on the factory from :meth:`create_session`. An extra key ``'scopefunc'`` can be set on the ``options`` dict to specify a custom scope function. If it's not provided, Flask's app ...
python
def create_scoped_session(self, options=None): """Create a :class:`~sqlalchemy.orm.scoping.scoped_session` on the factory from :meth:`create_session`. An extra key ``'scopefunc'`` can be set on the ``options`` dict to specify a custom scope function. If it's not provided, Flask's app ...
[ "def", "create_scoped_session", "(", "self", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "scopefunc", "=", "options", ".", "pop", "(", "'scopefunc'", ",", "_app_ctx_stack", ".", "__ident_func__", ")"...
Create a :class:`~sqlalchemy.orm.scoping.scoped_session` on the factory from :meth:`create_session`. An extra key ``'scopefunc'`` can be set on the ``options`` dict to specify a custom scope function. If it's not provided, Flask's app context stack identity is used. This will ensure th...
[ "Create", "a", ":", "class", ":", "~sqlalchemy", ".", "orm", ".", "scoping", ".", "scoped_session", "on", "the", "factory", "from", ":", "meth", ":", "create_session", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L735-L756
train
Create a scoped session on the factory from the Flask s create_session method.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
SQLAlchemy.create_session
def create_session(self, options): """Create the session factory used by :meth:`create_scoped_session`. The factory **must** return an object that SQLAlchemy recognizes as a session, or registering session events may raise an exception. Valid factories include a :class:`~sqlalchemy.orm...
python
def create_session(self, options): """Create the session factory used by :meth:`create_scoped_session`. The factory **must** return an object that SQLAlchemy recognizes as a session, or registering session events may raise an exception. Valid factories include a :class:`~sqlalchemy.orm...
[ "def", "create_session", "(", "self", ",", "options", ")", ":", "return", "orm", ".", "sessionmaker", "(", "class_", "=", "SignallingSession", ",", "db", "=", "self", ",", "*", "*", "options", ")" ]
Create the session factory used by :meth:`create_scoped_session`. The factory **must** return an object that SQLAlchemy recognizes as a session, or registering session events may raise an exception. Valid factories include a :class:`~sqlalchemy.orm.session.Session` class or a :class:`~...
[ "Create", "the", "session", "factory", "used", "by", ":", "meth", ":", "create_scoped_session", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L758-L772
train
Create the session factory used by create_scoped_session.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
SQLAlchemy.make_declarative_base
def make_declarative_base(self, model, metadata=None): """Creates the declarative base that all models will inherit from. :param model: base model class (or a tuple of base classes) to pass to :func:`~sqlalchemy.ext.declarative.declarative_base`. Or a class returned from ``decla...
python
def make_declarative_base(self, model, metadata=None): """Creates the declarative base that all models will inherit from. :param model: base model class (or a tuple of base classes) to pass to :func:`~sqlalchemy.ext.declarative.declarative_base`. Or a class returned from ``decla...
[ "def", "make_declarative_base", "(", "self", ",", "model", ",", "metadata", "=", "None", ")", ":", "if", "not", "isinstance", "(", "model", ",", "DeclarativeMeta", ")", ":", "model", "=", "declarative_base", "(", "cls", "=", "model", ",", "name", "=", "'...
Creates the declarative base that all models will inherit from. :param model: base model class (or a tuple of base classes) to pass to :func:`~sqlalchemy.ext.declarative.declarative_base`. Or a class returned from ``declarative_base``, in which case a new base class is not c...
[ "Creates", "the", "declarative", "base", "that", "all", "models", "will", "inherit", "from", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L774-L805
train
Creates a declarative base that all models will inherit from.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
SQLAlchemy.init_app
def init_app(self, app): """This callback can be used to initialize an application for the use with this database setup. Never use a database in the context of an application not initialized that way or connections will leak. """ if ( 'SQLALCHEMY_DATABASE_URI...
python
def init_app(self, app): """This callback can be used to initialize an application for the use with this database setup. Never use a database in the context of an application not initialized that way or connections will leak. """ if ( 'SQLALCHEMY_DATABASE_URI...
[ "def", "init_app", "(", "self", ",", "app", ")", ":", "if", "(", "'SQLALCHEMY_DATABASE_URI'", "not", "in", "app", ".", "config", "and", "'SQLALCHEMY_BINDS'", "not", "in", "app", ".", "config", ")", ":", "warnings", ".", "warn", "(", "'Neither SQLALCHEMY_DATA...
This callback can be used to initialize an application for the use with this database setup. Never use a database in the context of an application not initialized that way or connections will leak.
[ "This", "callback", "can", "be", "used", "to", "initialize", "an", "application", "for", "the", "use", "with", "this", "database", "setup", ".", "Never", "use", "a", "database", "in", "the", "context", "of", "an", "application", "not", "initialized", "that",...
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L807-L859
train
This callback can be used to initialize an application for the current context.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
SQLAlchemy.apply_driver_hacks
def apply_driver_hacks(self, app, sa_url, options): """This method is called before engine creation and used to inject driver specific hacks into the options. The `options` parameter is a dictionary of keyword arguments that will then be used to call the :func:`sqlalchemy.create_engine`...
python
def apply_driver_hacks(self, app, sa_url, options): """This method is called before engine creation and used to inject driver specific hacks into the options. The `options` parameter is a dictionary of keyword arguments that will then be used to call the :func:`sqlalchemy.create_engine`...
[ "def", "apply_driver_hacks", "(", "self", ",", "app", ",", "sa_url", ",", "options", ")", ":", "if", "sa_url", ".", "drivername", ".", "startswith", "(", "'mysql'", ")", ":", "sa_url", ".", "query", ".", "setdefault", "(", "'charset'", ",", "'utf8'", ")"...
This method is called before engine creation and used to inject driver specific hacks into the options. The `options` parameter is a dictionary of keyword arguments that will then be used to call the :func:`sqlalchemy.create_engine` function. The default implementation provides some sa...
[ "This", "method", "is", "called", "before", "engine", "creation", "and", "used", "to", "inject", "driver", "specific", "hacks", "into", "the", "options", ".", "The", "options", "parameter", "is", "a", "dictionary", "of", "keyword", "arguments", "that", "will",...
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L871-L931
train
This method is called before the engine creation and used to inject driver specific hacks into the options.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
SQLAlchemy.make_connector
def make_connector(self, app=None, bind=None): """Creates the connector for a given state and bind.""" return _EngineConnector(self, self.get_app(app), bind)
python
def make_connector(self, app=None, bind=None): """Creates the connector for a given state and bind.""" return _EngineConnector(self, self.get_app(app), bind)
[ "def", "make_connector", "(", "self", ",", "app", "=", "None", ",", "bind", "=", "None", ")", ":", "return", "_EngineConnector", "(", "self", ",", "self", ".", "get_app", "(", "app", ")", ",", "bind", ")" ]
Creates the connector for a given state and bind.
[ "Creates", "the", "connector", "for", "a", "given", "state", "and", "bind", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L943-L945
train
Creates the connector for a given state and bind.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
SQLAlchemy.get_engine
def get_engine(self, app=None, bind=None): """Returns a specific engine.""" app = self.get_app(app) state = get_state(app) with self._engine_lock: connector = state.connectors.get(bind) if connector is None: connector = self.make_connector(app, ...
python
def get_engine(self, app=None, bind=None): """Returns a specific engine.""" app = self.get_app(app) state = get_state(app) with self._engine_lock: connector = state.connectors.get(bind) if connector is None: connector = self.make_connector(app, ...
[ "def", "get_engine", "(", "self", ",", "app", "=", "None", ",", "bind", "=", "None", ")", ":", "app", "=", "self", ".", "get_app", "(", "app", ")", "state", "=", "get_state", "(", "app", ")", "with", "self", ".", "_engine_lock", ":", "connector", "...
Returns a specific engine.
[ "Returns", "a", "specific", "engine", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L947-L960
train
Returns a specific engine.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
SQLAlchemy.get_app
def get_app(self, reference_app=None): """Helper method that implements the logic to look up an application.""" if reference_app is not None: return reference_app if current_app: return current_app._get_current_object() if self.app is not None: ...
python
def get_app(self, reference_app=None): """Helper method that implements the logic to look up an application.""" if reference_app is not None: return reference_app if current_app: return current_app._get_current_object() if self.app is not None: ...
[ "def", "get_app", "(", "self", ",", "reference_app", "=", "None", ")", ":", "if", "reference_app", "is", "not", "None", ":", "return", "reference_app", "if", "current_app", ":", "return", "current_app", ".", "_get_current_object", "(", ")", "if", "self", "."...
Helper method that implements the logic to look up an application.
[ "Helper", "method", "that", "implements", "the", "logic", "to", "look", "up", "an", "application", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L972-L989
train
Helper method that returns the application object that is used to access the anova.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
SQLAlchemy.get_tables_for_bind
def get_tables_for_bind(self, bind=None): """Returns a list of all tables relevant for a bind.""" result = [] for table in itervalues(self.Model.metadata.tables): if table.info.get('bind_key') == bind: result.append(table) return result
python
def get_tables_for_bind(self, bind=None): """Returns a list of all tables relevant for a bind.""" result = [] for table in itervalues(self.Model.metadata.tables): if table.info.get('bind_key') == bind: result.append(table) return result
[ "def", "get_tables_for_bind", "(", "self", ",", "bind", "=", "None", ")", ":", "result", "=", "[", "]", "for", "table", "in", "itervalues", "(", "self", ".", "Model", ".", "metadata", ".", "tables", ")", ":", "if", "table", ".", "info", ".", "get", ...
Returns a list of all tables relevant for a bind.
[ "Returns", "a", "list", "of", "all", "tables", "relevant", "for", "a", "bind", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L991-L997
train
Returns a list of all tables relevant for a bind.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
SQLAlchemy.get_binds
def get_binds(self, app=None): """Returns a dictionary with a table->engine mapping. This is suitable for use of sessionmaker(binds=db.get_binds(app)). """ app = self.get_app(app) binds = [None] + list(app.config.get('SQLALCHEMY_BINDS') or ()) retval = {} for bin...
python
def get_binds(self, app=None): """Returns a dictionary with a table->engine mapping. This is suitable for use of sessionmaker(binds=db.get_binds(app)). """ app = self.get_app(app) binds = [None] + list(app.config.get('SQLALCHEMY_BINDS') or ()) retval = {} for bin...
[ "def", "get_binds", "(", "self", ",", "app", "=", "None", ")", ":", "app", "=", "self", ".", "get_app", "(", "app", ")", "binds", "=", "[", "None", "]", "+", "list", "(", "app", ".", "config", ".", "get", "(", "'SQLALCHEMY_BINDS'", ")", "or", "("...
Returns a dictionary with a table->engine mapping. This is suitable for use of sessionmaker(binds=db.get_binds(app)).
[ "Returns", "a", "dictionary", "with", "a", "table", "-", ">", "engine", "mapping", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L999-L1011
train
Returns a dictionary with a table - > engine mapping.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
flask_sqlalchemy/__init__.py
SQLAlchemy.reflect
def reflect(self, bind='__all__', app=None): """Reflects tables from the database. .. versionchanged:: 0.12 Parameters were added """ self._execute_for_all_tables(app, bind, 'reflect', skip_tables=True)
python
def reflect(self, bind='__all__', app=None): """Reflects tables from the database. .. versionchanged:: 0.12 Parameters were added """ self._execute_for_all_tables(app, bind, 'reflect', skip_tables=True)
[ "def", "reflect", "(", "self", ",", "bind", "=", "'__all__'", ",", "app", "=", "None", ")", ":", "self", ".", "_execute_for_all_tables", "(", "app", ",", "bind", ",", "'reflect'", ",", "skip_tables", "=", "True", ")" ]
Reflects tables from the database. .. versionchanged:: 0.12 Parameters were added
[ "Reflects", "tables", "from", "the", "database", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/flask_sqlalchemy/__init__.py#L1047-L1053
train
Reflects tables from the database.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
pallets/flask-sqlalchemy
examples/flaskr/flaskr/__init__.py
create_app
def create_app(test_config=None): """Create and configure an instance of the Flask application.""" app = Flask(__name__, instance_relative_config=True) # some deploy systems set the database url in the environ db_url = os.environ.get("DATABASE_URL") if db_url is None: # default to a sqlite...
python
def create_app(test_config=None): """Create and configure an instance of the Flask application.""" app = Flask(__name__, instance_relative_config=True) # some deploy systems set the database url in the environ db_url = os.environ.get("DATABASE_URL") if db_url is None: # default to a sqlite...
[ "def", "create_app", "(", "test_config", "=", "None", ")", ":", "app", "=", "Flask", "(", "__name__", ",", "instance_relative_config", "=", "True", ")", "# some deploy systems set the database url in the environ", "db_url", "=", "os", ".", "environ", ".", "get", "...
Create and configure an instance of the Flask application.
[ "Create", "and", "configure", "an", "instance", "of", "the", "Flask", "application", "." ]
3d3261f4fc6d28f5bf407cf7d523e36a09a8c144
https://github.com/pallets/flask-sqlalchemy/blob/3d3261f4fc6d28f5bf407cf7d523e36a09a8c144/examples/flaskr/flaskr/__init__.py#L13-L53
train
Create and configure an instance of the Flask application.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/objective_functions.py
negative_sharpe
def negative_sharpe( weights, expected_returns, cov_matrix, gamma=0, risk_free_rate=0.02 ): """ Calculate the negative Sharpe ratio of a portfolio :param weights: asset weights of the portfolio :type weights: np.ndarray :param expected_returns: expected return of each asset :type expected_r...
python
def negative_sharpe( weights, expected_returns, cov_matrix, gamma=0, risk_free_rate=0.02 ): """ Calculate the negative Sharpe ratio of a portfolio :param weights: asset weights of the portfolio :type weights: np.ndarray :param expected_returns: expected return of each asset :type expected_r...
[ "def", "negative_sharpe", "(", "weights", ",", "expected_returns", ",", "cov_matrix", ",", "gamma", "=", "0", ",", "risk_free_rate", "=", "0.02", ")", ":", "mu", "=", "weights", ".", "dot", "(", "expected_returns", ")", "sigma", "=", "np", ".", "sqrt", "...
Calculate the negative Sharpe ratio of a portfolio :param weights: asset weights of the portfolio :type weights: np.ndarray :param expected_returns: expected return of each asset :type expected_returns: pd.Series :param cov_matrix: the covariance matrix of asset returns :type cov_matrix: pd.Dat...
[ "Calculate", "the", "negative", "Sharpe", "ratio", "of", "a", "portfolio" ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/objective_functions.py#L38-L61
train
Calculate the negative Sharpe ratio of a single asset on the cluster
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/objective_functions.py
volatility
def volatility(weights, cov_matrix, gamma=0): """ Calculate the volatility of a portfolio. This is actually a misnomer because the function returns variance, which is technically the correct objective function when minimising volatility. :param weights: asset weights of the portfolio :type weig...
python
def volatility(weights, cov_matrix, gamma=0): """ Calculate the volatility of a portfolio. This is actually a misnomer because the function returns variance, which is technically the correct objective function when minimising volatility. :param weights: asset weights of the portfolio :type weig...
[ "def", "volatility", "(", "weights", ",", "cov_matrix", ",", "gamma", "=", "0", ")", ":", "L2_reg", "=", "gamma", "*", "(", "weights", "**", "2", ")", ".", "sum", "(", ")", "portfolio_volatility", "=", "np", ".", "dot", "(", "weights", ".", "T", ",...
Calculate the volatility of a portfolio. This is actually a misnomer because the function returns variance, which is technically the correct objective function when minimising volatility. :param weights: asset weights of the portfolio :type weights: np.ndarray :param cov_matrix: the covariance matr...
[ "Calculate", "the", "volatility", "of", "a", "portfolio", ".", "This", "is", "actually", "a", "misnomer", "because", "the", "function", "returns", "variance", "which", "is", "technically", "the", "correct", "objective", "function", "when", "minimising", "volatilit...
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/objective_functions.py#L64-L82
train
Calculate the volatility of a portfolio.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/objective_functions.py
negative_cvar
def negative_cvar(weights, returns, s=10000, beta=0.95, random_state=None): """ Calculate the negative CVaR. Though we want the "min CVaR portfolio", we actually need to maximise the expected return of the worst q% cases, thus we need this value to be negative. :param weights: asset weights of the ...
python
def negative_cvar(weights, returns, s=10000, beta=0.95, random_state=None): """ Calculate the negative CVaR. Though we want the "min CVaR portfolio", we actually need to maximise the expected return of the worst q% cases, thus we need this value to be negative. :param weights: asset weights of the ...
[ "def", "negative_cvar", "(", "weights", ",", "returns", ",", "s", "=", "10000", ",", "beta", "=", "0.95", ",", "random_state", "=", "None", ")", ":", "np", ".", "random", ".", "seed", "(", "seed", "=", "random_state", ")", "# Calcualte the returns given th...
Calculate the negative CVaR. Though we want the "min CVaR portfolio", we actually need to maximise the expected return of the worst q% cases, thus we need this value to be negative. :param weights: asset weights of the portfolio :type weights: np.ndarray :param returns: asset returns :type retu...
[ "Calculate", "the", "negative", "CVaR", ".", "Though", "we", "want", "the", "min", "CVaR", "portfolio", "we", "actually", "need", "to", "maximise", "the", "expected", "return", "of", "the", "worst", "q%", "cases", "thus", "we", "need", "this", "value", "to...
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/objective_functions.py#L85-L113
train
Calculate the negative CVaR for a given portfolio.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/expected_returns.py
mean_historical_return
def mean_historical_return(prices, frequency=252): """ Calculate annualised mean (daily) historical return from input (daily) asset prices. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.DataFrame :param fr...
python
def mean_historical_return(prices, frequency=252): """ Calculate annualised mean (daily) historical return from input (daily) asset prices. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.DataFrame :param fr...
[ "def", "mean_historical_return", "(", "prices", ",", "frequency", "=", "252", ")", ":", "if", "not", "isinstance", "(", "prices", ",", "pd", ".", "DataFrame", ")", ":", "warnings", ".", "warn", "(", "\"prices are not in a dataframe\"", ",", "RuntimeWarning", "...
Calculate annualised mean (daily) historical return from input (daily) asset prices. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.DataFrame :param frequency: number of time periods in a year, defaults to 252 (the...
[ "Calculate", "annualised", "mean", "(", "daily", ")", "historical", "return", "from", "input", "(", "daily", ")", "asset", "prices", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/expected_returns.py#L32-L49
train
Calculate annualised mean historical return for each asset.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/expected_returns.py
ema_historical_return
def ema_historical_return(prices, frequency=252, span=500): """ Calculate the exponentially-weighted mean of (daily) historical returns, giving higher weight to more recent data. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. ...
python
def ema_historical_return(prices, frequency=252, span=500): """ Calculate the exponentially-weighted mean of (daily) historical returns, giving higher weight to more recent data. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. ...
[ "def", "ema_historical_return", "(", "prices", ",", "frequency", "=", "252", ",", "span", "=", "500", ")", ":", "if", "not", "isinstance", "(", "prices", ",", "pd", ".", "DataFrame", ")", ":", "warnings", ".", "warn", "(", "\"prices are not in a dataframe\""...
Calculate the exponentially-weighted mean of (daily) historical returns, giving higher weight to more recent data. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.DataFrame :param frequency: number of time perio...
[ "Calculate", "the", "exponentially", "-", "weighted", "mean", "of", "(", "daily", ")", "historical", "returns", "giving", "higher", "weight", "to", "more", "recent", "data", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/expected_returns.py#L52-L72
train
Calculate the exponentially - weighted mean of the historical returns of an asset.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/efficient_frontier.py
EfficientFrontier.max_sharpe
def max_sharpe(self, risk_free_rate=0.02): """ Maximise the Sharpe Ratio. The result is also referred to as the tangency portfolio, as it is the tangent to the efficient frontier curve that intercepts the risk-free rate. :param risk_free_rate: risk-free rate of borrowing/lending...
python
def max_sharpe(self, risk_free_rate=0.02): """ Maximise the Sharpe Ratio. The result is also referred to as the tangency portfolio, as it is the tangent to the efficient frontier curve that intercepts the risk-free rate. :param risk_free_rate: risk-free rate of borrowing/lending...
[ "def", "max_sharpe", "(", "self", ",", "risk_free_rate", "=", "0.02", ")", ":", "if", "not", "isinstance", "(", "risk_free_rate", ",", "(", "int", ",", "float", ")", ")", ":", "raise", "ValueError", "(", "\"risk_free_rate should be numeric\"", ")", "args", "...
Maximise the Sharpe Ratio. The result is also referred to as the tangency portfolio, as it is the tangent to the efficient frontier curve that intercepts the risk-free rate. :param risk_free_rate: risk-free rate of borrowing/lending, defaults to 0.02 :type risk_free_rate: float, optiona...
[ "Maximise", "the", "Sharpe", "Ratio", ".", "The", "result", "is", "also", "referred", "to", "as", "the", "tangency", "portfolio", "as", "it", "is", "the", "tangent", "to", "the", "efficient", "frontier", "curve", "that", "intercepts", "the", "risk", "-", "...
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/efficient_frontier.py#L86-L111
train
Maximise the Sharpe - maximising portfolio.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/efficient_frontier.py
EfficientFrontier.min_volatility
def min_volatility(self): """ Minimise volatility. :return: asset weights for the volatility-minimising portfolio :rtype: dict """ args = (self.cov_matrix, self.gamma) result = sco.minimize( objective_functions.volatility, x0=self.initial_...
python
def min_volatility(self): """ Minimise volatility. :return: asset weights for the volatility-minimising portfolio :rtype: dict """ args = (self.cov_matrix, self.gamma) result = sco.minimize( objective_functions.volatility, x0=self.initial_...
[ "def", "min_volatility", "(", "self", ")", ":", "args", "=", "(", "self", ".", "cov_matrix", ",", "self", ".", "gamma", ")", "result", "=", "sco", ".", "minimize", "(", "objective_functions", ".", "volatility", ",", "x0", "=", "self", ".", "initial_guess...
Minimise volatility. :return: asset weights for the volatility-minimising portfolio :rtype: dict
[ "Minimise", "volatility", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/efficient_frontier.py#L113-L130
train
Minimise volatility.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/efficient_frontier.py
EfficientFrontier.custom_objective
def custom_objective(self, objective_function, *args): """ Optimise some objective function. While an implicit requirement is that the function can be optimised via a quadratic optimiser, this is not enforced. Thus there is a decent chance of silent failure. :param objective_fun...
python
def custom_objective(self, objective_function, *args): """ Optimise some objective function. While an implicit requirement is that the function can be optimised via a quadratic optimiser, this is not enforced. Thus there is a decent chance of silent failure. :param objective_fun...
[ "def", "custom_objective", "(", "self", ",", "objective_function", ",", "*", "args", ")", ":", "result", "=", "sco", ".", "minimize", "(", "objective_function", ",", "x0", "=", "self", ".", "initial_guess", ",", "args", "=", "args", ",", "method", "=", "...
Optimise some objective function. While an implicit requirement is that the function can be optimised via a quadratic optimiser, this is not enforced. Thus there is a decent chance of silent failure. :param objective_function: function which maps (weight, args) -> cost :type objective_f...
[ "Optimise", "some", "objective", "function", ".", "While", "an", "implicit", "requirement", "is", "that", "the", "function", "can", "be", "optimised", "via", "a", "quadratic", "optimiser", "this", "is", "not", "enforced", ".", "Thus", "there", "is", "a", "de...
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/efficient_frontier.py#L132-L152
train
Optimise some objective function.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/efficient_frontier.py
EfficientFrontier.efficient_risk
def efficient_risk(self, target_risk, risk_free_rate=0.02, market_neutral=False): """ Calculate the Sharpe-maximising portfolio for a given volatility (i.e max return for a target risk). :param target_risk: the desired volatility of the resulting portfolio. :type target_risk: fl...
python
def efficient_risk(self, target_risk, risk_free_rate=0.02, market_neutral=False): """ Calculate the Sharpe-maximising portfolio for a given volatility (i.e max return for a target risk). :param target_risk: the desired volatility of the resulting portfolio. :type target_risk: fl...
[ "def", "efficient_risk", "(", "self", ",", "target_risk", ",", "risk_free_rate", "=", "0.02", ",", "market_neutral", "=", "False", ")", ":", "if", "not", "isinstance", "(", "target_risk", ",", "float", ")", "or", "target_risk", "<", "0", ":", "raise", "Val...
Calculate the Sharpe-maximising portfolio for a given volatility (i.e max return for a target risk). :param target_risk: the desired volatility of the resulting portfolio. :type target_risk: float :param risk_free_rate: risk-free rate of borrowing/lending, defaults to 0.02 :type...
[ "Calculate", "the", "Sharpe", "-", "maximising", "portfolio", "for", "a", "given", "volatility", "(", "i", ".", "e", "max", "return", "for", "a", "target", "risk", ")", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/efficient_frontier.py#L154-L207
train
Calculates the Sharpe - Maximising portfolio for a given target risk.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/efficient_frontier.py
EfficientFrontier.efficient_return
def efficient_return(self, target_return, market_neutral=False): """ Calculate the 'Markowitz portfolio', minimising volatility for a given target return. :param target_return: the desired return of the resulting portfolio. :type target_return: float :param market_neutral: wheth...
python
def efficient_return(self, target_return, market_neutral=False): """ Calculate the 'Markowitz portfolio', minimising volatility for a given target return. :param target_return: the desired return of the resulting portfolio. :type target_return: float :param market_neutral: wheth...
[ "def", "efficient_return", "(", "self", ",", "target_return", ",", "market_neutral", "=", "False", ")", ":", "if", "not", "isinstance", "(", "target_return", ",", "float", ")", "or", "target_return", "<", "0", ":", "raise", "ValueError", "(", "\"target_return ...
Calculate the 'Markowitz portfolio', minimising volatility for a given target return. :param target_return: the desired return of the resulting portfolio. :type target_return: float :param market_neutral: whether the portfolio should be market neutral (weights sum to zero), ...
[ "Calculate", "the", "Markowitz", "portfolio", "minimising", "volatility", "for", "a", "given", "target", "return", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/efficient_frontier.py#L209-L255
train
Calculates the asset weights for a given target return.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/efficient_frontier.py
EfficientFrontier.portfolio_performance
def portfolio_performance(self, verbose=False, risk_free_rate=0.02): """ After optimising, calculate (and optionally print) the performance of the optimal portfolio. Currently calculates expected return, volatility, and the Sharpe ratio. :param verbose: whether performance should be pri...
python
def portfolio_performance(self, verbose=False, risk_free_rate=0.02): """ After optimising, calculate (and optionally print) the performance of the optimal portfolio. Currently calculates expected return, volatility, and the Sharpe ratio. :param verbose: whether performance should be pri...
[ "def", "portfolio_performance", "(", "self", ",", "verbose", "=", "False", ",", "risk_free_rate", "=", "0.02", ")", ":", "return", "base_optimizer", ".", "portfolio_performance", "(", "self", ".", "expected_returns", ",", "self", ".", "cov_matrix", ",", "self", ...
After optimising, calculate (and optionally print) the performance of the optimal portfolio. Currently calculates expected return, volatility, and the Sharpe ratio. :param verbose: whether performance should be printed, defaults to False :type verbose: bool, optional :param risk_free_ra...
[ "After", "optimising", "calculate", "(", "and", "optionally", "print", ")", "the", "performance", "of", "the", "optimal", "portfolio", ".", "Currently", "calculates", "expected", "return", "volatility", "and", "the", "Sharpe", "ratio", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/efficient_frontier.py#L257-L276
train
Calculates the performance of the optimal portfolio.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/base_optimizer.py
portfolio_performance
def portfolio_performance( expected_returns, cov_matrix, weights, verbose=False, risk_free_rate=0.02 ): """ After optimising, calculate (and optionally print) the performance of the optimal portfolio. Currently calculates expected return, volatility, and the Sharpe ratio. :param expected_returns: e...
python
def portfolio_performance( expected_returns, cov_matrix, weights, verbose=False, risk_free_rate=0.02 ): """ After optimising, calculate (and optionally print) the performance of the optimal portfolio. Currently calculates expected return, volatility, and the Sharpe ratio. :param expected_returns: e...
[ "def", "portfolio_performance", "(", "expected_returns", ",", "cov_matrix", ",", "weights", ",", "verbose", "=", "False", ",", "risk_free_rate", "=", "0.02", ")", ":", "if", "isinstance", "(", "weights", ",", "dict", ")", ":", "if", "isinstance", "(", "expec...
After optimising, calculate (and optionally print) the performance of the optimal portfolio. Currently calculates expected return, volatility, and the Sharpe ratio. :param expected_returns: expected returns for each asset. Set to None if optimising for volatility only. :type ex...
[ "After", "optimising", "calculate", "(", "and", "optionally", "print", ")", "the", "performance", "of", "the", "optimal", "portfolio", ".", "Currently", "calculates", "expected", "return", "volatility", "and", "the", "Sharpe", "ratio", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/base_optimizer.py#L94-L143
train
Calculates the performance of a single node in a cluster portfolio.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/base_optimizer.py
BaseOptimizer.clean_weights
def clean_weights(self, cutoff=1e-4, rounding=5): """ Helper method to clean the raw weights, setting any weights whose absolute values are below the cutoff to zero, and rounding the rest. :param cutoff: the lower bound, defaults to 1e-4 :type cutoff: float, optional :pa...
python
def clean_weights(self, cutoff=1e-4, rounding=5): """ Helper method to clean the raw weights, setting any weights whose absolute values are below the cutoff to zero, and rounding the rest. :param cutoff: the lower bound, defaults to 1e-4 :type cutoff: float, optional :pa...
[ "def", "clean_weights", "(", "self", ",", "cutoff", "=", "1e-4", ",", "rounding", "=", "5", ")", ":", "if", "not", "isinstance", "(", "rounding", ",", "int", ")", "or", "rounding", "<", "1", ":", "raise", "ValueError", "(", "\"rounding must be a positive i...
Helper method to clean the raw weights, setting any weights whose absolute values are below the cutoff to zero, and rounding the rest. :param cutoff: the lower bound, defaults to 1e-4 :type cutoff: float, optional :param rounding: number of decimal places to round the weights, defaults ...
[ "Helper", "method", "to", "clean", "the", "raw", "weights", "setting", "any", "weights", "whose", "absolute", "values", "are", "below", "the", "cutoff", "to", "zero", "and", "rounding", "the", "rest", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/base_optimizer.py#L37-L56
train
Clean the raw asset weights
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/base_optimizer.py
BaseScipyOptimizer._make_valid_bounds
def _make_valid_bounds(self, test_bounds): """ Private method: process input bounds into a form acceptable by scipy.optimize, and check the validity of said bounds. :param test_bounds: minimum and maximum weight of an asset :type test_bounds: tuple :raises ValueError: if...
python
def _make_valid_bounds(self, test_bounds): """ Private method: process input bounds into a form acceptable by scipy.optimize, and check the validity of said bounds. :param test_bounds: minimum and maximum weight of an asset :type test_bounds: tuple :raises ValueError: if...
[ "def", "_make_valid_bounds", "(", "self", ",", "test_bounds", ")", ":", "if", "len", "(", "test_bounds", ")", "!=", "2", "or", "not", "isinstance", "(", "test_bounds", ",", "tuple", ")", ":", "raise", "ValueError", "(", "\"test_bounds must be a tuple of (lower b...
Private method: process input bounds into a form acceptable by scipy.optimize, and check the validity of said bounds. :param test_bounds: minimum and maximum weight of an asset :type test_bounds: tuple :raises ValueError: if ``test_bounds`` is not a tuple of length two. :raises ...
[ "Private", "method", ":", "process", "input", "bounds", "into", "a", "form", "acceptable", "by", "scipy", ".", "optimize", "and", "check", "the", "validity", "of", "said", "bounds", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/base_optimizer.py#L72-L91
train
Private method to make sure that the input bounds are acceptable by scipy. optimize. get_valid_asset_range_of_cache_entries.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/discrete_allocation.py
portfolio
def portfolio(weights, latest_prices, min_allocation=0.01, total_portfolio_value=10000): """ For a long only portfolio, convert the continuous weights to a discrete allocation in a greedy iterative approach. This can be thought of as a clever way to round the continuous weights to an integer number of s...
python
def portfolio(weights, latest_prices, min_allocation=0.01, total_portfolio_value=10000): """ For a long only portfolio, convert the continuous weights to a discrete allocation in a greedy iterative approach. This can be thought of as a clever way to round the continuous weights to an integer number of s...
[ "def", "portfolio", "(", "weights", ",", "latest_prices", ",", "min_allocation", "=", "0.01", ",", "total_portfolio_value", "=", "10000", ")", ":", "if", "not", "isinstance", "(", "weights", ",", "dict", ")", ":", "raise", "TypeError", "(", "\"weights should b...
For a long only portfolio, convert the continuous weights to a discrete allocation in a greedy iterative approach. This can be thought of as a clever way to round the continuous weights to an integer number of shares :param weights: continuous weights generated from the ``efficient_frontier`` module :t...
[ "For", "a", "long", "only", "portfolio", "convert", "the", "continuous", "weights", "to", "a", "discrete", "allocation", "in", "a", "greedy", "iterative", "approach", ".", "This", "can", "be", "thought", "of", "as", "a", "clever", "way", "to", "round", "th...
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/discrete_allocation.py#L27-L127
train
This function takes a continuous weight dictionary and returns a discrete allocation of the number of shares of each asset in the order they are purchased.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/discrete_allocation.py
portfolio_lp
def portfolio_lp( weights, latest_prices, min_allocation=0.01, total_portfolio_value=10000 ): """ For a long only portfolio, convert the continuous weights to a discrete allocation using Mixed Integer Linear Programming. This can be thought of as a clever way to round the continuous weights to an in...
python
def portfolio_lp( weights, latest_prices, min_allocation=0.01, total_portfolio_value=10000 ): """ For a long only portfolio, convert the continuous weights to a discrete allocation using Mixed Integer Linear Programming. This can be thought of as a clever way to round the continuous weights to an in...
[ "def", "portfolio_lp", "(", "weights", ",", "latest_prices", ",", "min_allocation", "=", "0.01", ",", "total_portfolio_value", "=", "10000", ")", ":", "import", "pulp", "if", "not", "isinstance", "(", "weights", ",", "dict", ")", ":", "raise", "TypeError", "...
For a long only portfolio, convert the continuous weights to a discrete allocation using Mixed Integer Linear Programming. This can be thought of as a clever way to round the continuous weights to an integer number of shares :param weights: continuous weights generated from the ``efficient_frontier`` modul...
[ "For", "a", "long", "only", "portfolio", "convert", "the", "continuous", "weights", "to", "a", "discrete", "allocation", "using", "Mixed", "Integer", "Linear", "Programming", ".", "This", "can", "be", "thought", "of", "as", "a", "clever", "way", "to", "round...
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/discrete_allocation.py#L130-L184
train
Converts continuous weights to discrete allocation
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/discrete_allocation.py
portfolio_byvalue
def portfolio_byvalue( weights, steps, min_values, max_values=1e9, total_portfolio_value=10000 ): """ For a long only portfolio, convert the continuous weights to a discrete allocation using Mixed Integer Linear Programming. This function assumes that we buy some asset based on value instead of shar...
python
def portfolio_byvalue( weights, steps, min_values, max_values=1e9, total_portfolio_value=10000 ): """ For a long only portfolio, convert the continuous weights to a discrete allocation using Mixed Integer Linear Programming. This function assumes that we buy some asset based on value instead of shar...
[ "def", "portfolio_byvalue", "(", "weights", ",", "steps", ",", "min_values", ",", "max_values", "=", "1e9", ",", "total_portfolio_value", "=", "10000", ")", ":", "import", "pulp", "if", "not", "isinstance", "(", "weights", ",", "dict", ")", ":", "raise", "...
For a long only portfolio, convert the continuous weights to a discrete allocation using Mixed Integer Linear Programming. This function assumes that we buy some asset based on value instead of shares, and there is a limit of minimum value and increasing step. :param weights: continuous weights generat...
[ "For", "a", "long", "only", "portfolio", "convert", "the", "continuous", "weights", "to", "a", "discrete", "allocation", "using", "Mixed", "Integer", "Linear", "Programming", ".", "This", "function", "assumes", "that", "we", "buy", "some", "asset", "based", "o...
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/discrete_allocation.py#L187-L250
train
This function takes a continuous weight dictionary and returns a discrete version of the portfolio.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/value_at_risk.py
CVAROpt.min_cvar
def min_cvar(self, s=10000, beta=0.95, random_state=None): """ Find the portfolio weights that minimises the CVaR, via Monte Carlo sampling from the return distribution. :param s: number of bootstrap draws, defaults to 10000 :type s: int, optional :param beta: "significa...
python
def min_cvar(self, s=10000, beta=0.95, random_state=None): """ Find the portfolio weights that minimises the CVaR, via Monte Carlo sampling from the return distribution. :param s: number of bootstrap draws, defaults to 10000 :type s: int, optional :param beta: "significa...
[ "def", "min_cvar", "(", "self", ",", "s", "=", "10000", ",", "beta", "=", "0.95", ",", "random_state", "=", "None", ")", ":", "args", "=", "(", "self", ".", "returns", ",", "s", ",", "beta", ",", "random_state", ")", "result", "=", "noisyopt", ".",...
Find the portfolio weights that minimises the CVaR, via Monte Carlo sampling from the return distribution. :param s: number of bootstrap draws, defaults to 10000 :type s: int, optional :param beta: "significance level" (i. 1 - q), defaults to 0.95 :type beta: float, optional ...
[ "Find", "the", "portfolio", "weights", "that", "minimises", "the", "CVaR", "via", "Monte", "Carlo", "sampling", "from", "the", "return", "distribution", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/value_at_risk.py#L54-L78
train
Find the portfolio weights that minimises the CVaR via Monte Carlo sampling from the return distribution.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/risk_models.py
sample_cov
def sample_cov(prices, frequency=252): """ Calculate the annualised sample covariance matrix of (daily) asset returns. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.DataFrame :param frequency: number of ti...
python
def sample_cov(prices, frequency=252): """ Calculate the annualised sample covariance matrix of (daily) asset returns. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.DataFrame :param frequency: number of ti...
[ "def", "sample_cov", "(", "prices", ",", "frequency", "=", "252", ")", ":", "if", "not", "isinstance", "(", "prices", ",", "pd", ".", "DataFrame", ")", ":", "warnings", ".", "warn", "(", "\"prices are not in a dataframe\"", ",", "RuntimeWarning", ")", "price...
Calculate the annualised sample covariance matrix of (daily) asset returns. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.DataFrame :param frequency: number of time periods in a year, defaults to 252 (the number ...
[ "Calculate", "the", "annualised", "sample", "covariance", "matrix", "of", "(", "daily", ")", "asset", "returns", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/risk_models.py#L28-L45
train
Calculate the annualised sample covariance matrix of the given prices.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/risk_models.py
semicovariance
def semicovariance(prices, benchmark=0, frequency=252): """ Estimate the semicovariance matrix, i.e the covariance given that the returns are less than the benchmark. .. semicov = E([min(r_i - B, 0)] . [min(r_j - B, 0)]) :param prices: adjusted closing prices of the asset, each row is a date ...
python
def semicovariance(prices, benchmark=0, frequency=252): """ Estimate the semicovariance matrix, i.e the covariance given that the returns are less than the benchmark. .. semicov = E([min(r_i - B, 0)] . [min(r_j - B, 0)]) :param prices: adjusted closing prices of the asset, each row is a date ...
[ "def", "semicovariance", "(", "prices", ",", "benchmark", "=", "0", ",", "frequency", "=", "252", ")", ":", "if", "not", "isinstance", "(", "prices", ",", "pd", ".", "DataFrame", ")", ":", "warnings", ".", "warn", "(", "\"prices are not in a dataframe\"", ...
Estimate the semicovariance matrix, i.e the covariance given that the returns are less than the benchmark. .. semicov = E([min(r_i - B, 0)] . [min(r_j - B, 0)]) :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.D...
[ "Estimate", "the", "semicovariance", "matrix", "i", ".", "e", "the", "covariance", "given", "that", "the", "returns", "are", "less", "than", "the", "benchmark", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/risk_models.py#L48-L71
train
Estimate the semicovariance matrix given a set of prices.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/risk_models.py
_pair_exp_cov
def _pair_exp_cov(X, Y, span=180): """ Calculate the exponential covariance between two timeseries of returns. :param X: first time series of returns :type X: pd.Series :param Y: second time series of returns :type Y: pd.Series :param span: the span of the exponential weighting function, de...
python
def _pair_exp_cov(X, Y, span=180): """ Calculate the exponential covariance between two timeseries of returns. :param X: first time series of returns :type X: pd.Series :param Y: second time series of returns :type Y: pd.Series :param span: the span of the exponential weighting function, de...
[ "def", "_pair_exp_cov", "(", "X", ",", "Y", ",", "span", "=", "180", ")", ":", "covariation", "=", "(", "X", "-", "X", ".", "mean", "(", ")", ")", "*", "(", "Y", "-", "Y", ".", "mean", "(", ")", ")", "# Exponentially weight the covariation and take t...
Calculate the exponential covariance between two timeseries of returns. :param X: first time series of returns :type X: pd.Series :param Y: second time series of returns :type Y: pd.Series :param span: the span of the exponential weighting function, defaults to 180 :type span: int, optional ...
[ "Calculate", "the", "exponential", "covariance", "between", "two", "timeseries", "of", "returns", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/risk_models.py#L74-L91
train
Calculate the exponential covariance between two timeseries of returns.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/risk_models.py
exp_cov
def exp_cov(prices, span=180, frequency=252): """ Estimate the exponentially-weighted covariance matrix, which gives greater weight to more recent data. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.DataFr...
python
def exp_cov(prices, span=180, frequency=252): """ Estimate the exponentially-weighted covariance matrix, which gives greater weight to more recent data. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.DataFr...
[ "def", "exp_cov", "(", "prices", ",", "span", "=", "180", ",", "frequency", "=", "252", ")", ":", "if", "not", "isinstance", "(", "prices", ",", "pd", ".", "DataFrame", ")", ":", "warnings", ".", "warn", "(", "\"prices are not in a dataframe\"", ",", "Ru...
Estimate the exponentially-weighted covariance matrix, which gives greater weight to more recent data. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.DataFrame :param span: the span of the exponential weighting...
[ "Estimate", "the", "exponentially", "-", "weighted", "covariance", "matrix", "which", "gives", "greater", "weight", "to", "more", "recent", "data", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/risk_models.py#L94-L124
train
Estimate the exponential covariance matrix for a single asset.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/risk_models.py
min_cov_determinant
def min_cov_determinant(prices, frequency=252, random_state=None): """ Calculate the minimum covariance determinant, an estimator of the covariance matrix that is more robust to noise. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker...
python
def min_cov_determinant(prices, frequency=252, random_state=None): """ Calculate the minimum covariance determinant, an estimator of the covariance matrix that is more robust to noise. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker...
[ "def", "min_cov_determinant", "(", "prices", ",", "frequency", "=", "252", ",", "random_state", "=", "None", ")", ":", "if", "not", "isinstance", "(", "prices", ",", "pd", ".", "DataFrame", ")", ":", "warnings", ".", "warn", "(", "\"prices are not in a dataf...
Calculate the minimum covariance determinant, an estimator of the covariance matrix that is more robust to noise. :param prices: adjusted closing prices of the asset, each row is a date and each column is a ticker/id. :type prices: pd.DataFrame :param frequency: number of time period...
[ "Calculate", "the", "minimum", "covariance", "determinant", "an", "estimator", "of", "the", "covariance", "matrix", "that", "is", "more", "robust", "to", "noise", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/risk_models.py#L127-L150
train
Calculate the minimum covariance determinant of a single asset.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/risk_models.py
CovarianceShrinkage.format_and_annualise
def format_and_annualise(self, raw_cov_array): """ Helper method which annualises the output of shrinkage calculations, and formats the result into a dataframe :param raw_cov_array: raw covariance matrix of daily returns :type raw_cov_array: np.ndarray :return: annualise...
python
def format_and_annualise(self, raw_cov_array): """ Helper method which annualises the output of shrinkage calculations, and formats the result into a dataframe :param raw_cov_array: raw covariance matrix of daily returns :type raw_cov_array: np.ndarray :return: annualise...
[ "def", "format_and_annualise", "(", "self", ",", "raw_cov_array", ")", ":", "assets", "=", "self", ".", "X", ".", "columns", "return", "(", "pd", ".", "DataFrame", "(", "raw_cov_array", ",", "index", "=", "assets", ",", "columns", "=", "assets", ")", "*"...
Helper method which annualises the output of shrinkage calculations, and formats the result into a dataframe :param raw_cov_array: raw covariance matrix of daily returns :type raw_cov_array: np.ndarray :return: annualised covariance matrix :rtype: pd.DataFrame
[ "Helper", "method", "which", "annualises", "the", "output", "of", "shrinkage", "calculations", "and", "formats", "the", "result", "into", "a", "dataframe" ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/risk_models.py#L182-L195
train
This method annualises the output of shrinkage calculations and returns a dataframe containing the annualised covariance matrix.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/risk_models.py
CovarianceShrinkage.shrunk_covariance
def shrunk_covariance(self, delta=0.2): """ Shrink a sample covariance matrix to the identity matrix (scaled by the average sample variance). This method does not estimate an optimal shrinkage parameter, it requires manual input. :param delta: shrinkage parameter, defaults to 0....
python
def shrunk_covariance(self, delta=0.2): """ Shrink a sample covariance matrix to the identity matrix (scaled by the average sample variance). This method does not estimate an optimal shrinkage parameter, it requires manual input. :param delta: shrinkage parameter, defaults to 0....
[ "def", "shrunk_covariance", "(", "self", ",", "delta", "=", "0.2", ")", ":", "self", ".", "delta", "=", "delta", "N", "=", "self", ".", "S", ".", "shape", "[", "1", "]", "# Shrinkage target", "mu", "=", "np", ".", "trace", "(", "self", ".", "S", ...
Shrink a sample covariance matrix to the identity matrix (scaled by the average sample variance). This method does not estimate an optimal shrinkage parameter, it requires manual input. :param delta: shrinkage parameter, defaults to 0.2. :type delta: float, optional :return: shr...
[ "Shrink", "a", "sample", "covariance", "matrix", "to", "the", "identity", "matrix", "(", "scaled", "by", "the", "average", "sample", "variance", ")", ".", "This", "method", "does", "not", "estimate", "an", "optimal", "shrinkage", "parameter", "it", "requires",...
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/risk_models.py#L197-L215
train
Shrink a sample covariance matrix to the identity matrix scaled by the average sample variance.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/risk_models.py
CovarianceShrinkage.ledoit_wolf
def ledoit_wolf(self): """ Calculate the Ledoit-Wolf shrinkage estimate. :return: shrunk sample covariance matrix :rtype: np.ndarray """ X = np.nan_to_num(self.X.values) shrunk_cov, self.delta = covariance.ledoit_wolf(X) return self.format_and_annualise(s...
python
def ledoit_wolf(self): """ Calculate the Ledoit-Wolf shrinkage estimate. :return: shrunk sample covariance matrix :rtype: np.ndarray """ X = np.nan_to_num(self.X.values) shrunk_cov, self.delta = covariance.ledoit_wolf(X) return self.format_and_annualise(s...
[ "def", "ledoit_wolf", "(", "self", ")", ":", "X", "=", "np", ".", "nan_to_num", "(", "self", ".", "X", ".", "values", ")", "shrunk_cov", ",", "self", ".", "delta", "=", "covariance", ".", "ledoit_wolf", "(", "X", ")", "return", "self", ".", "format_a...
Calculate the Ledoit-Wolf shrinkage estimate. :return: shrunk sample covariance matrix :rtype: np.ndarray
[ "Calculate", "the", "Ledoit", "-", "Wolf", "shrinkage", "estimate", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/risk_models.py#L217-L226
train
Calculate the Ledoit - Wolf shrinkage estimate.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/risk_models.py
CovarianceShrinkage.oracle_approximating
def oracle_approximating(self): """ Calculate the Oracle Approximating Shrinkage estimate :return: shrunk sample covariance matrix :rtype: np.ndarray """ X = np.nan_to_num(self.X.values) shrunk_cov, self.delta = covariance.oas(X) return self.format_and_an...
python
def oracle_approximating(self): """ Calculate the Oracle Approximating Shrinkage estimate :return: shrunk sample covariance matrix :rtype: np.ndarray """ X = np.nan_to_num(self.X.values) shrunk_cov, self.delta = covariance.oas(X) return self.format_and_an...
[ "def", "oracle_approximating", "(", "self", ")", ":", "X", "=", "np", ".", "nan_to_num", "(", "self", ".", "X", ".", "values", ")", "shrunk_cov", ",", "self", ".", "delta", "=", "covariance", ".", "oas", "(", "X", ")", "return", "self", ".", "format_...
Calculate the Oracle Approximating Shrinkage estimate :return: shrunk sample covariance matrix :rtype: np.ndarray
[ "Calculate", "the", "Oracle", "Approximating", "Shrinkage", "estimate" ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/risk_models.py#L228-L237
train
Calculate the Oracle Approximating Shrinkage estimate
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/risk_models.py
ConstantCorrelation.shrink
def shrink(self): """ Calculate the Constant-Correlation covariance matrix. :return: shrunk sample covariance matrix :rtype: np.ndarray """ x = np.nan_to_num(self.X.values) # de-mean returns t, n = np.shape(x) meanx = x.mean(axis=0) x = x...
python
def shrink(self): """ Calculate the Constant-Correlation covariance matrix. :return: shrunk sample covariance matrix :rtype: np.ndarray """ x = np.nan_to_num(self.X.values) # de-mean returns t, n = np.shape(x) meanx = x.mean(axis=0) x = x...
[ "def", "shrink", "(", "self", ")", ":", "x", "=", "np", ".", "nan_to_num", "(", "self", ".", "X", ".", "values", ")", "# de-mean returns", "t", ",", "n", "=", "np", ".", "shape", "(", "x", ")", "meanx", "=", "x", ".", "mean", "(", "axis", "=", ...
Calculate the Constant-Correlation covariance matrix. :return: shrunk sample covariance matrix :rtype: np.ndarray
[ "Calculate", "the", "Constant", "-", "Correlation", "covariance", "matrix", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/risk_models.py#L248-L308
train
Calculate the Constant - Correlation covariance matrix.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/risk_models.py
SingleIndex.shrink
def shrink(self): """ Calculate the Constant-Correlation covariance matrix. :return: shrunk sample covariance matrix :rtype: np.ndarray """ x = np.nan_to_num(self.X.values) # de-mean returns t, n = np.shape(x) meanx = x.mean(axis=0) x = x...
python
def shrink(self): """ Calculate the Constant-Correlation covariance matrix. :return: shrunk sample covariance matrix :rtype: np.ndarray """ x = np.nan_to_num(self.X.values) # de-mean returns t, n = np.shape(x) meanx = x.mean(axis=0) x = x...
[ "def", "shrink", "(", "self", ")", ":", "x", "=", "np", ".", "nan_to_num", "(", "self", ".", "X", ".", "values", ")", "# de-mean returns", "t", ",", "n", "=", "np", ".", "shape", "(", "x", ")", "meanx", "=", "x", ".", "mean", "(", "axis", "=", ...
Calculate the Constant-Correlation covariance matrix. :return: shrunk sample covariance matrix :rtype: np.ndarray
[ "Calculate", "the", "Constant", "-", "Correlation", "covariance", "matrix", "." ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/risk_models.py#L323-L379
train
Calculate the Constant - Correlation covariance matrix.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/cla.py
CLA.min_volatility
def min_volatility(self): """Get the minimum variance solution""" if not self.w: self.solve() var = [] for w in self.w: a = np.dot(np.dot(w.T, self.cov_matrix), w) var.append(a) # return min(var)**.5, self.w[var.index(min(var))] self.we...
python
def min_volatility(self): """Get the minimum variance solution""" if not self.w: self.solve() var = [] for w in self.w: a = np.dot(np.dot(w.T, self.cov_matrix), w) var.append(a) # return min(var)**.5, self.w[var.index(min(var))] self.we...
[ "def", "min_volatility", "(", "self", ")", ":", "if", "not", "self", ".", "w", ":", "self", ".", "solve", "(", ")", "var", "=", "[", "]", "for", "w", "in", "self", ".", "w", ":", "a", "=", "np", ".", "dot", "(", "np", ".", "dot", "(", "w", ...
Get the minimum variance solution
[ "Get", "the", "minimum", "variance", "solution" ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/cla.py#L275-L285
train
Get the minimum variance solution
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/cla.py
CLA.max_sharpe
def max_sharpe(self): """Get the max Sharpe ratio portfolio""" if not self.w: self.solve() # 1) Compute the local max SR portfolio between any two neighbor turning points w_sr, sr = [], [] for i in range(len(self.w) - 1): w0 = np.copy(self.w[i]) ...
python
def max_sharpe(self): """Get the max Sharpe ratio portfolio""" if not self.w: self.solve() # 1) Compute the local max SR portfolio between any two neighbor turning points w_sr, sr = [], [] for i in range(len(self.w) - 1): w0 = np.copy(self.w[i]) ...
[ "def", "max_sharpe", "(", "self", ")", ":", "if", "not", "self", ".", "w", ":", "self", ".", "solve", "(", ")", "# 1) Compute the local max SR portfolio between any two neighbor turning points", "w_sr", ",", "sr", "=", "[", "]", ",", "[", "]", "for", "i", "i...
Get the max Sharpe ratio portfolio
[ "Get", "the", "max", "Sharpe", "ratio", "portfolio" ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/cla.py#L287-L302
train
Get the max Sharpe ratio portfolio
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
robertmartin8/PyPortfolioOpt
pypfopt/cla.py
CLA.efficient_frontier
def efficient_frontier(self, points): """Get the efficient frontier""" mu, sigma, weights = [], [], [] # remove the 1, to avoid duplications a = np.linspace(0, 1, points / len(self.w))[:-1] b = list(range(len(self.w) - 1)) for i in b: w0, w1 = self.w[i], self....
python
def efficient_frontier(self, points): """Get the efficient frontier""" mu, sigma, weights = [], [], [] # remove the 1, to avoid duplications a = np.linspace(0, 1, points / len(self.w))[:-1] b = list(range(len(self.w) - 1)) for i in b: w0, w1 = self.w[i], self....
[ "def", "efficient_frontier", "(", "self", ",", "points", ")", ":", "mu", ",", "sigma", ",", "weights", "=", "[", "]", ",", "[", "]", ",", "[", "]", "# remove the 1, to avoid duplications", "a", "=", "np", ".", "linspace", "(", "0", ",", "1", ",", "po...
Get the efficient frontier
[ "Get", "the", "efficient", "frontier" ]
dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc
https://github.com/robertmartin8/PyPortfolioOpt/blob/dfad1256cb6995c7fbd7a025eedb54b1ca04b2fc/pypfopt/cla.py#L347-L363
train
Get the efficient frontier for the given set of points.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
emit
def emit(event, *args, **kwargs): """Emit a SocketIO event. This function emits a SocketIO event to one or more connected clients. A JSON blob can be attached to the event as payload. This is a function that can only be called from a SocketIO event handler, as in obtains some information from the c...
python
def emit(event, *args, **kwargs): """Emit a SocketIO event. This function emits a SocketIO event to one or more connected clients. A JSON blob can be attached to the event as payload. This is a function that can only be called from a SocketIO event handler, as in obtains some information from the c...
[ "def", "emit", "(", "event", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "'namespace'", "in", "kwargs", ":", "namespace", "=", "kwargs", "[", "'namespace'", "]", "else", ":", "namespace", "=", "flask", ".", "request", ".", "namespace", ...
Emit a SocketIO event. This function emits a SocketIO event to one or more connected clients. A JSON blob can be attached to the event as payload. This is a function that can only be called from a SocketIO event handler, as in obtains some information from the current client context. Example:: ...
[ "Emit", "a", "SocketIO", "event", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L676-L726
train
Emits a SocketIO event to one or more connected clients.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
send
def send(message, **kwargs): """Send a SocketIO message. This function sends a simple SocketIO message to one or more connected clients. The message can be a string or a JSON blob. This is a simpler version of ``emit()``, which should be preferred. This is a function that can only be called from a ...
python
def send(message, **kwargs): """Send a SocketIO message. This function sends a simple SocketIO message to one or more connected clients. The message can be a string or a JSON blob. This is a simpler version of ``emit()``, which should be preferred. This is a function that can only be called from a ...
[ "def", "send", "(", "message", ",", "*", "*", "kwargs", ")", ":", "json", "=", "kwargs", ".", "get", "(", "'json'", ",", "False", ")", "if", "'namespace'", "in", "kwargs", ":", "namespace", "=", "kwargs", "[", "'namespace'", "]", "else", ":", "namesp...
Send a SocketIO message. This function sends a simple SocketIO message to one or more connected clients. The message can be a string or a JSON blob. This is a simpler version of ``emit()``, which should be preferred. This is a function that can only be called from a SocketIO event handler. :param ...
[ "Send", "a", "SocketIO", "message", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L729-L776
train
Send a SocketIO message to one or more connected clients.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
join_room
def join_room(room, sid=None, namespace=None): """Join a room. This function puts the user in a room, under the current namespace. The user and the namespace are obtained from the event context. This is a function that can only be called from a SocketIO event handler. Example:: @socketio.on('j...
python
def join_room(room, sid=None, namespace=None): """Join a room. This function puts the user in a room, under the current namespace. The user and the namespace are obtained from the event context. This is a function that can only be called from a SocketIO event handler. Example:: @socketio.on('j...
[ "def", "join_room", "(", "room", ",", "sid", "=", "None", ",", "namespace", "=", "None", ")", ":", "socketio", "=", "flask", ".", "current_app", ".", "extensions", "[", "'socketio'", "]", "sid", "=", "sid", "or", "flask", ".", "request", ".", "sid", ...
Join a room. This function puts the user in a room, under the current namespace. The user and the namespace are obtained from the event context. This is a function that can only be called from a SocketIO event handler. Example:: @socketio.on('join') def on_join(data): username ...
[ "Join", "a", "room", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L779-L802
train
Join a room.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
leave_room
def leave_room(room, sid=None, namespace=None): """Leave a room. This function removes the user from a room, under the current namespace. The user and the namespace are obtained from the event context. Example:: @socketio.on('leave') def on_leave(data): username = session['user...
python
def leave_room(room, sid=None, namespace=None): """Leave a room. This function removes the user from a room, under the current namespace. The user and the namespace are obtained from the event context. Example:: @socketio.on('leave') def on_leave(data): username = session['user...
[ "def", "leave_room", "(", "room", ",", "sid", "=", "None", ",", "namespace", "=", "None", ")", ":", "socketio", "=", "flask", ".", "current_app", ".", "extensions", "[", "'socketio'", "]", "sid", "=", "sid", "or", "flask", ".", "request", ".", "sid", ...
Leave a room. This function removes the user from a room, under the current namespace. The user and the namespace are obtained from the event context. Example:: @socketio.on('leave') def on_leave(data): username = session['username'] room = data['room'] leav...
[ "Leave", "a", "room", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L805-L827
train
Leave a room.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
close_room
def close_room(room, namespace=None): """Close a room. This function removes any users that are in the given room and then deletes the room from the server. :param room: The name of the room to close. :param namespace: The namespace for the room. If not provided, the namespac...
python
def close_room(room, namespace=None): """Close a room. This function removes any users that are in the given room and then deletes the room from the server. :param room: The name of the room to close. :param namespace: The namespace for the room. If not provided, the namespac...
[ "def", "close_room", "(", "room", ",", "namespace", "=", "None", ")", ":", "socketio", "=", "flask", ".", "current_app", ".", "extensions", "[", "'socketio'", "]", "namespace", "=", "namespace", "or", "flask", ".", "request", ".", "namespace", "socketio", ...
Close a room. This function removes any users that are in the given room and then deletes the room from the server. :param room: The name of the room to close. :param namespace: The namespace for the room. If not provided, the namespace is obtained from the request context.
[ "Close", "a", "room", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L830-L842
train
Closes a room.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
rooms
def rooms(sid=None, namespace=None): """Return a list of the rooms the client is in. This function returns all the rooms the client has entered, including its own room, assigned by the Socket.IO server. :param sid: The session id of the client. If not provided, the client is obtained f...
python
def rooms(sid=None, namespace=None): """Return a list of the rooms the client is in. This function returns all the rooms the client has entered, including its own room, assigned by the Socket.IO server. :param sid: The session id of the client. If not provided, the client is obtained f...
[ "def", "rooms", "(", "sid", "=", "None", ",", "namespace", "=", "None", ")", ":", "socketio", "=", "flask", ".", "current_app", ".", "extensions", "[", "'socketio'", "]", "sid", "=", "sid", "or", "flask", ".", "request", ".", "sid", "namespace", "=", ...
Return a list of the rooms the client is in. This function returns all the rooms the client has entered, including its own room, assigned by the Socket.IO server. :param sid: The session id of the client. If not provided, the client is obtained from the request context. :param namespac...
[ "Return", "a", "list", "of", "the", "rooms", "the", "client", "is", "in", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L845-L859
train
Return a list of the rooms the client is in.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
disconnect
def disconnect(sid=None, namespace=None, silent=False): """Disconnect the client. This function terminates the connection with the client. As a result of this call the client will receive a disconnect event. Example:: @socketio.on('message') def receive_message(msg): if is_bann...
python
def disconnect(sid=None, namespace=None, silent=False): """Disconnect the client. This function terminates the connection with the client. As a result of this call the client will receive a disconnect event. Example:: @socketio.on('message') def receive_message(msg): if is_bann...
[ "def", "disconnect", "(", "sid", "=", "None", ",", "namespace", "=", "None", ",", "silent", "=", "False", ")", ":", "socketio", "=", "flask", ".", "current_app", ".", "extensions", "[", "'socketio'", "]", "sid", "=", "sid", "or", "flask", ".", "request...
Disconnect the client. This function terminates the connection with the client. As a result of this call the client will receive a disconnect event. Example:: @socketio.on('message') def receive_message(msg): if is_banned(session['username']): disconnect() ...
[ "Disconnect", "the", "client", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L862-L884
train
Disconnect the client.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
SocketIO.on
def on(self, message, namespace=None): """Decorator to register a SocketIO event handler. This decorator must be applied to SocketIO event handlers. Example:: @socketio.on('my event', namespace='/chat') def handle_my_custom_event(json): print('received json: ' +...
python
def on(self, message, namespace=None): """Decorator to register a SocketIO event handler. This decorator must be applied to SocketIO event handlers. Example:: @socketio.on('my event', namespace='/chat') def handle_my_custom_event(json): print('received json: ' +...
[ "def", "on", "(", "self", ",", "message", ",", "namespace", "=", "None", ")", ":", "namespace", "=", "namespace", "or", "'/'", "def", "decorator", "(", "handler", ")", ":", "def", "_handler", "(", "sid", ",", "*", "args", ")", ":", "return", "self", ...
Decorator to register a SocketIO event handler. This decorator must be applied to SocketIO event handlers. Example:: @socketio.on('my event', namespace='/chat') def handle_my_custom_event(json): print('received json: ' + str(json)) :param message: The name of t...
[ "Decorator", "to", "register", "a", "SocketIO", "event", "handler", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L235-L266
train
Decorator to register a SocketIO event handler.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
SocketIO.on_error
def on_error(self, namespace=None): """Decorator to define a custom error handler for SocketIO events. This decorator can be applied to a function that acts as an error handler for a namespace. This handler will be invoked when a SocketIO event handler raises an exception. The handler f...
python
def on_error(self, namespace=None): """Decorator to define a custom error handler for SocketIO events. This decorator can be applied to a function that acts as an error handler for a namespace. This handler will be invoked when a SocketIO event handler raises an exception. The handler f...
[ "def", "on_error", "(", "self", ",", "namespace", "=", "None", ")", ":", "namespace", "=", "namespace", "or", "'/'", "def", "decorator", "(", "exception_handler", ")", ":", "if", "not", "callable", "(", "exception_handler", ")", ":", "raise", "ValueError", ...
Decorator to define a custom error handler for SocketIO events. This decorator can be applied to a function that acts as an error handler for a namespace. This handler will be invoked when a SocketIO event handler raises an exception. The handler function must accept one argument, which...
[ "Decorator", "to", "define", "a", "custom", "error", "handler", "for", "SocketIO", "events", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L268-L290
train
Decorator to define a custom error handler for SocketIO events.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
SocketIO.on_error_default
def on_error_default(self, exception_handler): """Decorator to define a default error handler for SocketIO events. This decorator can be applied to a function that acts as a default error handler for any namespaces that do not have a specific handler. Example:: @socketio.on...
python
def on_error_default(self, exception_handler): """Decorator to define a default error handler for SocketIO events. This decorator can be applied to a function that acts as a default error handler for any namespaces that do not have a specific handler. Example:: @socketio.on...
[ "def", "on_error_default", "(", "self", ",", "exception_handler", ")", ":", "if", "not", "callable", "(", "exception_handler", ")", ":", "raise", "ValueError", "(", "'exception_handler must be callable'", ")", "self", ".", "default_exception_handler", "=", "exception_...
Decorator to define a default error handler for SocketIO events. This decorator can be applied to a function that acts as a default error handler for any namespaces that do not have a specific handler. Example:: @socketio.on_error_default def error_handler(e): ...
[ "Decorator", "to", "define", "a", "default", "error", "handler", "for", "SocketIO", "events", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L292-L306
train
Decorator to define a default error handler for SocketIO events.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
SocketIO.on_event
def on_event(self, message, handler, namespace=None): """Register a SocketIO event handler. ``on_event`` is the non-decorator version of ``'on'``. Example:: def on_foo_event(json): print('received json: ' + str(json)) socketio.on_event('my event', on_f...
python
def on_event(self, message, handler, namespace=None): """Register a SocketIO event handler. ``on_event`` is the non-decorator version of ``'on'``. Example:: def on_foo_event(json): print('received json: ' + str(json)) socketio.on_event('my event', on_f...
[ "def", "on_event", "(", "self", ",", "message", ",", "handler", ",", "namespace", "=", "None", ")", ":", "self", ".", "on", "(", "message", ",", "namespace", "=", "namespace", ")", "(", "handler", ")" ]
Register a SocketIO event handler. ``on_event`` is the non-decorator version of ``'on'``. Example:: def on_foo_event(json): print('received json: ' + str(json)) socketio.on_event('my event', on_foo_event, namespace='/chat') :param message: The name of...
[ "Register", "a", "SocketIO", "event", "handler", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L308-L331
train
Register a SocketIO event handler.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
SocketIO.emit
def emit(self, event, *args, **kwargs): """Emit a server generated SocketIO event. This function emits a SocketIO event to one or more connected clients. A JSON blob can be attached to the event as payload. This function can be used outside of a SocketIO event context, so it is appropri...
python
def emit(self, event, *args, **kwargs): """Emit a server generated SocketIO event. This function emits a SocketIO event to one or more connected clients. A JSON blob can be attached to the event as payload. This function can be used outside of a SocketIO event context, so it is appropri...
[ "def", "emit", "(", "self", ",", "event", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "namespace", "=", "kwargs", ".", "pop", "(", "'namespace'", ",", "'/'", ")", "room", "=", "kwargs", ".", "pop", "(", "'room'", ",", "None", ")", "inclu...
Emit a server generated SocketIO event. This function emits a SocketIO event to one or more connected clients. A JSON blob can be attached to the event as payload. This function can be used outside of a SocketIO event context, so it is appropriate to use when the server is the originato...
[ "Emit", "a", "server", "generated", "SocketIO", "event", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L342-L381
train
Emit a SocketIO event to one or more connected clients.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
SocketIO.send
def send(self, data, json=False, namespace=None, room=None, callback=None, include_self=True, skip_sid=None, **kwargs): """Send a server-generated SocketIO message. This function sends a simple SocketIO message to one or more connected clients. The message can be a string or a JSON...
python
def send(self, data, json=False, namespace=None, room=None, callback=None, include_self=True, skip_sid=None, **kwargs): """Send a server-generated SocketIO message. This function sends a simple SocketIO message to one or more connected clients. The message can be a string or a JSON...
[ "def", "send", "(", "self", ",", "data", ",", "json", "=", "False", ",", "namespace", "=", "None", ",", "room", "=", "None", ",", "callback", "=", "None", ",", "include_self", "=", "True", ",", "skip_sid", "=", "None", ",", "*", "*", "kwargs", ")",...
Send a server-generated SocketIO message. This function sends a simple SocketIO message to one or more connected clients. The message can be a string or a JSON blob. This is a simpler version of ``emit()``, which should be preferred. This function can be used outside of a SocketIO event...
[ "Send", "a", "server", "-", "generated", "SocketIO", "message", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L383-L417
train
Send a message to one or more connected SocketIO clients.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
SocketIO.run
def run(self, app, host=None, port=None, **kwargs): """Run the SocketIO web server. :param app: The Flask application instance. :param host: The hostname or IP address for the server to listen on. Defaults to 127.0.0.1. :param port: The port number for the server to...
python
def run(self, app, host=None, port=None, **kwargs): """Run the SocketIO web server. :param app: The Flask application instance. :param host: The hostname or IP address for the server to listen on. Defaults to 127.0.0.1. :param port: The port number for the server to...
[ "def", "run", "(", "self", ",", "app", ",", "host", "=", "None", ",", "port", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "host", "is", "None", ":", "host", "=", "'127.0.0.1'", "if", "port", "is", "None", ":", "server_name", "=", "app",...
Run the SocketIO web server. :param app: The Flask application instance. :param host: The hostname or IP address for the server to listen on. Defaults to 127.0.0.1. :param port: The port number for the server to listen on. Defaults to 5000. :par...
[ "Run", "the", "SocketIO", "web", "server", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L432-L564
train
This method runs the SocketIO web server.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
SocketIO.stop
def stop(self): """Stop a running SocketIO web server. This method must be called from a HTTP or SocketIO handler function. """ if self.server.eio.async_mode == 'threading': func = flask.request.environ.get('werkzeug.server.shutdown') if func: fun...
python
def stop(self): """Stop a running SocketIO web server. This method must be called from a HTTP or SocketIO handler function. """ if self.server.eio.async_mode == 'threading': func = flask.request.environ.get('werkzeug.server.shutdown') if func: fun...
[ "def", "stop", "(", "self", ")", ":", "if", "self", ".", "server", ".", "eio", ".", "async_mode", "==", "'threading'", ":", "func", "=", "flask", ".", "request", ".", "environ", ".", "get", "(", "'werkzeug.server.shutdown'", ")", "if", "func", ":", "fu...
Stop a running SocketIO web server. This method must be called from a HTTP or SocketIO handler function.
[ "Stop", "a", "running", "SocketIO", "web", "server", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L566-L580
train
Stop a running SocketIO web server.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/__init__.py
SocketIO.start_background_task
def start_background_task(self, target, *args, **kwargs): """Start a background task using the appropriate async model. This is a utility function that applications can use to start a background task using the method that is compatible with the selected async mode. :param targe...
python
def start_background_task(self, target, *args, **kwargs): """Start a background task using the appropriate async model. This is a utility function that applications can use to start a background task using the method that is compatible with the selected async mode. :param targe...
[ "def", "start_background_task", "(", "self", ",", "target", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "server", ".", "start_background_task", "(", "target", ",", "*", "args", ",", "*", "*", "kwargs", ")" ]
Start a background task using the appropriate async model. This is a utility function that applications can use to start a background task using the method that is compatible with the selected async mode. :param target: the target function to execute. :param args: arguments to ...
[ "Start", "a", "background", "task", "using", "the", "appropriate", "async", "model", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/__init__.py#L582-L597
train
Start a background task using the appropriate async model.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/namespace.py
Namespace.trigger_event
def trigger_event(self, event, *args): """Dispatch an event to the proper handler method. In the most common usage, this method is not overloaded by subclasses, as it performs the routing of events to methods. However, this method can be overriden if special dispatching rules are needed...
python
def trigger_event(self, event, *args): """Dispatch an event to the proper handler method. In the most common usage, this method is not overloaded by subclasses, as it performs the routing of events to methods. However, this method can be overriden if special dispatching rules are needed...
[ "def", "trigger_event", "(", "self", ",", "event", ",", "*", "args", ")", ":", "handler_name", "=", "'on_'", "+", "event", "if", "not", "hasattr", "(", "self", ",", "handler_name", ")", ":", "# there is no handler for this event, so we ignore it", "return", "han...
Dispatch an event to the proper handler method. In the most common usage, this method is not overloaded by subclasses, as it performs the routing of events to methods. However, this method can be overriden if special dispatching rules are needed, or if having a single method that catche...
[ "Dispatch", "an", "event", "to", "the", "proper", "handler", "method", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/namespace.py#L12-L26
train
Dispatch an event to the proper handler method.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/namespace.py
Namespace.emit
def emit(self, event, data=None, room=None, include_self=True, namespace=None, callback=None): """Emit a custom event to one or more connected clients.""" return self.socketio.emit(event, data, room=room, include_self=include_self, ...
python
def emit(self, event, data=None, room=None, include_self=True, namespace=None, callback=None): """Emit a custom event to one or more connected clients.""" return self.socketio.emit(event, data, room=room, include_self=include_self, ...
[ "def", "emit", "(", "self", ",", "event", ",", "data", "=", "None", ",", "room", "=", "None", ",", "include_self", "=", "True", ",", "namespace", "=", "None", ",", "callback", "=", "None", ")", ":", "return", "self", ".", "socketio", ".", "emit", "...
Emit a custom event to one or more connected clients.
[ "Emit", "a", "custom", "event", "to", "one", "or", "more", "connected", "clients", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/namespace.py#L28-L34
train
Emit a custom event to one or more connected clients.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/namespace.py
Namespace.send
def send(self, data, room=None, include_self=True, namespace=None, callback=None): """Send a message to one or more connected clients.""" return self.socketio.send(data, room=room, include_self=include_self, namespace=namespace or self.namespace, ...
python
def send(self, data, room=None, include_self=True, namespace=None, callback=None): """Send a message to one or more connected clients.""" return self.socketio.send(data, room=room, include_self=include_self, namespace=namespace or self.namespace, ...
[ "def", "send", "(", "self", ",", "data", ",", "room", "=", "None", ",", "include_self", "=", "True", ",", "namespace", "=", "None", ",", "callback", "=", "None", ")", ":", "return", "self", ".", "socketio", ".", "send", "(", "data", ",", "room", "=...
Send a message to one or more connected clients.
[ "Send", "a", "message", "to", "one", "or", "more", "connected", "clients", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/namespace.py#L36-L41
train
Send a message to one or more connected clients.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
flask_socketio/namespace.py
Namespace.close_room
def close_room(self, room, namespace=None): """Close a room.""" return self.socketio.close_room(room=room, namespace=namespace or self.namespace)
python
def close_room(self, room, namespace=None): """Close a room.""" return self.socketio.close_room(room=room, namespace=namespace or self.namespace)
[ "def", "close_room", "(", "self", ",", "room", ",", "namespace", "=", "None", ")", ":", "return", "self", ".", "socketio", ".", "close_room", "(", "room", "=", "room", ",", "namespace", "=", "namespace", "or", "self", ".", "namespace", ")" ]
Close a room.
[ "Close", "a", "room", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/flask_socketio/namespace.py#L43-L46
train
Close a room.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
miguelgrinberg/Flask-SocketIO
example/app.py
background_thread
def background_thread(): """Example of how to send server generated events to clients.""" count = 0 while True: socketio.sleep(10) count += 1 socketio.emit('my_response', {'data': 'Server generated event', 'count': count}, namespace='/test'...
python
def background_thread(): """Example of how to send server generated events to clients.""" count = 0 while True: socketio.sleep(10) count += 1 socketio.emit('my_response', {'data': 'Server generated event', 'count': count}, namespace='/test'...
[ "def", "background_thread", "(", ")", ":", "count", "=", "0", "while", "True", ":", "socketio", ".", "sleep", "(", "10", ")", "count", "+=", "1", "socketio", ".", "emit", "(", "'my_response'", ",", "{", "'data'", ":", "'Server generated event'", ",", "'c...
Example of how to send server generated events to clients.
[ "Example", "of", "how", "to", "send", "server", "generated", "events", "to", "clients", "." ]
4bef800d5e7ba7d98a6f4cd94191ff0b4496c334
https://github.com/miguelgrinberg/Flask-SocketIO/blob/4bef800d5e7ba7d98a6f4cd94191ff0b4496c334/example/app.py#L19-L27
train
Example of how to send server generated events to clients.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/pipelines/celery_task.py
OperationTask.on_failure
def on_failure(self, exc, task_id, args, kwargs, einfo): """Update query status and send email notification to a user""" super().on_failure(exc, task_id, args, kwargs, einfo) if isinstance(exc, OperationRunDoesNotExist): return self._operation_run.on_failure()
python
def on_failure(self, exc, task_id, args, kwargs, einfo): """Update query status and send email notification to a user""" super().on_failure(exc, task_id, args, kwargs, einfo) if isinstance(exc, OperationRunDoesNotExist): return self._operation_run.on_failure()
[ "def", "on_failure", "(", "self", ",", "exc", ",", "task_id", ",", "args", ",", "kwargs", ",", "einfo", ")", ":", "super", "(", ")", ".", "on_failure", "(", "exc", ",", "task_id", ",", "args", ",", "kwargs", ",", "einfo", ")", "if", "isinstance", "...
Update query status and send email notification to a user
[ "Update", "query", "status", "and", "send", "email", "notification", "to", "a", "user" ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/pipelines/celery_task.py#L32-L37
train
Update query status and send email notification to a user
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/pipelines/celery_task.py
OperationTask.on_success
def on_success(self, retval, task_id, args, kwargs): """Send email notification and a file, if requested to do so by a user""" super().on_success(retval, task_id, args, kwargs) self._operation_run.on_success()
python
def on_success(self, retval, task_id, args, kwargs): """Send email notification and a file, if requested to do so by a user""" super().on_success(retval, task_id, args, kwargs) self._operation_run.on_success()
[ "def", "on_success", "(", "self", ",", "retval", ",", "task_id", ",", "args", ",", "kwargs", ")", ":", "super", "(", ")", ".", "on_success", "(", "retval", ",", "task_id", ",", "args", ",", "kwargs", ")", "self", ".", "_operation_run", ".", "on_success...
Send email notification and a file, if requested to do so by a user
[ "Send", "email", "notification", "and", "a", "file", "if", "requested", "to", "do", "so", "by", "a", "user" ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/pipelines/celery_task.py#L43-L46
train
Send email notification and a file if requested to do so by a user
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/auditor/service.py
AuditorService.record_event
def record_event(self, event: Event) -> None: """ Record the event async. """ from polyaxon.celery_api import celery_app from polyaxon.settings import EventsCeleryTasks if not event.ref_id: event.ref_id = self.get_ref_id() serialized_event = event.ser...
python
def record_event(self, event: Event) -> None: """ Record the event async. """ from polyaxon.celery_api import celery_app from polyaxon.settings import EventsCeleryTasks if not event.ref_id: event.ref_id = self.get_ref_id() serialized_event = event.ser...
[ "def", "record_event", "(", "self", ",", "event", ":", "Event", ")", "->", "None", ":", "from", "polyaxon", ".", "celery_api", "import", "celery_app", "from", "polyaxon", ".", "settings", "import", "EventsCeleryTasks", "if", "not", "event", ".", "ref_id", ":...
Record the event async.
[ "Record", "the", "event", "async", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/auditor/service.py#L33-L51
train
Record the event async.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/event_manager/event_manager.py
EventManager.user_write_events
def user_write_events(self) -> List[str]: """Return event types where use acted on an object. The write events are events with actions: * CREATED * UPDATED * DELETED * RESUMED * COPIED * CLONED * STOPPED """ ...
python
def user_write_events(self) -> List[str]: """Return event types where use acted on an object. The write events are events with actions: * CREATED * UPDATED * DELETED * RESUMED * COPIED * CLONED * STOPPED """ ...
[ "def", "user_write_events", "(", "self", ")", "->", "List", "[", "str", "]", ":", "return", "[", "event_type", "for", "event_type", ",", "event", "in", "self", ".", "items", "if", "event", ".", "get_event_action", "(", ")", "in", "event_actions", ".", "W...
Return event types where use acted on an object. The write events are events with actions: * CREATED * UPDATED * DELETED * RESUMED * COPIED * CLONED * STOPPED
[ "Return", "event", "types", "where", "use", "acted", "on", "an", "object", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/event_manager/event_manager.py#L26-L39
train
Return the list of event types where use acted on an object.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/event_manager/event_manager.py
EventManager.user_view_events
def user_view_events(self) -> List[str]: """Return event types where use viewed a main object.""" return [event_type for event_type, event in self.items if event.get_event_action() == event_actions.VIEWED]
python
def user_view_events(self) -> List[str]: """Return event types where use viewed a main object.""" return [event_type for event_type, event in self.items if event.get_event_action() == event_actions.VIEWED]
[ "def", "user_view_events", "(", "self", ")", "->", "List", "[", "str", "]", ":", "return", "[", "event_type", "for", "event_type", ",", "event", "in", "self", ".", "items", "if", "event", ".", "get_event_action", "(", ")", "==", "event_actions", ".", "VI...
Return event types where use viewed a main object.
[ "Return", "event", "types", "where", "use", "viewed", "a", "main", "object", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/event_manager/event_manager.py#L41-L44
train
Return event types where use viewed a main object.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/api/users/validators.py
validate_new_email
def validate_new_email(email): """Validates a "new" email address by checking if it is already used by other users.""" email = normalize_email(email) User = get_user_model() # noqa if User.objects.filter(email=email).exists(): raise ValidationError('The given email address is already registered...
python
def validate_new_email(email): """Validates a "new" email address by checking if it is already used by other users.""" email = normalize_email(email) User = get_user_model() # noqa if User.objects.filter(email=email).exists(): raise ValidationError('The given email address is already registered...
[ "def", "validate_new_email", "(", "email", ")", ":", "email", "=", "normalize_email", "(", "email", ")", "User", "=", "get_user_model", "(", ")", "# noqa", "if", "User", ".", "objects", ".", "filter", "(", "email", "=", "email", ")", ".", "exists", "(", ...
Validates a "new" email address by checking if it is already used by other users.
[ "Validates", "a", "new", "email", "address", "by", "checking", "if", "it", "is", "already", "used", "by", "other", "users", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/api/users/validators.py#L14-L19
train
Validates a new email address by checking if it is already used by other users.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/scheduler/spawners/templates/project_jobs/pods.py
get_project_pod_spec
def get_project_pod_spec(volume_mounts, volumes, image, command, args, ports, env_vars=None, env_from=None, container_na...
python
def get_project_pod_spec(volume_mounts, volumes, image, command, args, ports, env_vars=None, env_from=None, container_na...
[ "def", "get_project_pod_spec", "(", "volume_mounts", ",", "volumes", ",", "image", ",", "command", ",", "args", ",", "ports", ",", "env_vars", "=", "None", ",", "env_from", "=", "None", ",", "container_name", "=", "None", ",", "resources", "=", "None", ","...
Pod spec to be used to create pods for project: tensorboard, notebooks.
[ "Pod", "spec", "to", "be", "used", "to", "create", "pods", "for", "project", ":", "tensorboard", "notebooks", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/scheduler/spawners/templates/project_jobs/pods.py#L41-L90
train
Returns a pod spec for the project.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/api/endpoint/base.py
BaseEndpoint.get_object
def get_object(self): """We memoize the access to this function in case a second call is made.""" if self._object: return self._object self._object = super().get_object() if not self.AUDITOR_EVENT_TYPES: return self._object method = self.request.method ...
python
def get_object(self): """We memoize the access to this function in case a second call is made.""" if self._object: return self._object self._object = super().get_object() if not self.AUDITOR_EVENT_TYPES: return self._object method = self.request.method ...
[ "def", "get_object", "(", "self", ")", ":", "if", "self", ".", "_object", ":", "return", "self", ".", "_object", "self", ".", "_object", "=", "super", "(", ")", ".", "get_object", "(", ")", "if", "not", "self", ".", "AUDITOR_EVENT_TYPES", ":", "return"...
We memoize the access to this function in case a second call is made.
[ "We", "memoize", "the", "access", "to", "this", "function", "in", "case", "a", "second", "call", "is", "made", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/api/endpoint/base.py#L37-L56
train
We memoize the access to this function in case a second call is made.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/api/endpoint/base.py
BaseEndpoint.initialize_context
def initialize_context(self, request: HttpRequest, *args, **kwargs) -> None: """ Initializes the endpoint with the context keys based on the passed and/or based on the query parameters (request.GET). """ for key in self.CONTEXT_KEYS: setattr(self, key, kwargs.get(key)...
python
def initialize_context(self, request: HttpRequest, *args, **kwargs) -> None: """ Initializes the endpoint with the context keys based on the passed and/or based on the query parameters (request.GET). """ for key in self.CONTEXT_KEYS: setattr(self, key, kwargs.get(key)...
[ "def", "initialize_context", "(", "self", ",", "request", ":", "HttpRequest", ",", "*", "args", ",", "*", "*", "kwargs", ")", "->", "None", ":", "for", "key", "in", "self", ".", "CONTEXT_KEYS", ":", "setattr", "(", "self", ",", "key", ",", "kwargs", ...
Initializes the endpoint with the context keys based on the passed and/or based on the query parameters (request.GET).
[ "Initializes", "the", "endpoint", "with", "the", "context", "keys", "based", "on", "the", "passed", "and", "/", "or", "based", "on", "the", "query", "parameters", "(", "request", ".", "GET", ")", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/api/endpoint/base.py#L86-L96
train
Initializes the endpoint with the passed context keys based on the passed query parameters and the passed request.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/scheduler/spawners/templates/volumes.py
get_shm_volumes
def get_shm_volumes(): """ Mount an tmpfs volume to /dev/shm. This will set /dev/shm size to half of the RAM of node. By default, /dev/shm is very small, only 64MB. Some experiments will fail due to lack of share memory, such as some experiments running on Pytorch. """ volumes, volume_mo...
python
def get_shm_volumes(): """ Mount an tmpfs volume to /dev/shm. This will set /dev/shm size to half of the RAM of node. By default, /dev/shm is very small, only 64MB. Some experiments will fail due to lack of share memory, such as some experiments running on Pytorch. """ volumes, volume_mo...
[ "def", "get_shm_volumes", "(", ")", ":", "volumes", ",", "volume_mounts", "=", "[", "]", ",", "[", "]", "shm_volume", "=", "client", ".", "V1Volume", "(", "name", "=", "constants", ".", "SHM_VOLUME", ",", "empty_dir", "=", "client", ".", "V1EmptyDirVolumeS...
Mount an tmpfs volume to /dev/shm. This will set /dev/shm size to half of the RAM of node. By default, /dev/shm is very small, only 64MB. Some experiments will fail due to lack of share memory, such as some experiments running on Pytorch.
[ "Mount", "an", "tmpfs", "volume", "to", "/", "dev", "/", "shm", ".", "This", "will", "set", "/", "dev", "/", "shm", "size", "to", "half", "of", "the", "RAM", "of", "node", ".", "By", "default", "/", "dev", "/", "shm", "is", "very", "small", "only...
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/scheduler/spawners/templates/volumes.py#L128-L144
train
Get the list of volumes and volumes_mounts for the current project.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/db/models/experiments.py
Experiment.last_job_statuses
def last_job_statuses(self) -> List[str]: """The last constants of the job in this experiment.""" statuses = [] for status in self.jobs.values_list('status__status', flat=True): if status is not None: statuses.append(status) return statuses
python
def last_job_statuses(self) -> List[str]: """The last constants of the job in this experiment.""" statuses = [] for status in self.jobs.values_list('status__status', flat=True): if status is not None: statuses.append(status) return statuses
[ "def", "last_job_statuses", "(", "self", ")", "->", "List", "[", "str", "]", ":", "statuses", "=", "[", "]", "for", "status", "in", "self", ".", "jobs", ".", "values_list", "(", "'status__status'", ",", "flat", "=", "True", ")", ":", "if", "status", ...
The last constants of the job in this experiment.
[ "The", "last", "constants", "of", "the", "job", "in", "this", "experiment", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/db/models/experiments.py#L196-L202
train
The last constants of the job in this experiment.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/db/models/experiments.py
Experiment.has_running_jobs
def has_running_jobs(self) -> bool: """"Return a boolean indicating if the experiment has any running jobs""" return self.jobs.exclude(status__status__in=ExperimentLifeCycle.DONE_STATUS).exists()
python
def has_running_jobs(self) -> bool: """"Return a boolean indicating if the experiment has any running jobs""" return self.jobs.exclude(status__status__in=ExperimentLifeCycle.DONE_STATUS).exists()
[ "def", "has_running_jobs", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "jobs", ".", "exclude", "(", "status__status__in", "=", "ExperimentLifeCycle", ".", "DONE_STATUS", ")", ".", "exists", "(", ")" ]
Return a boolean indicating if the experiment has any running jobs
[ "Return", "a", "boolean", "indicating", "if", "the", "experiment", "has", "any", "running", "jobs" ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/db/models/experiments.py#L205-L207
train
Return a boolean indicating if the experiment has any running jobs
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/scopes/authentication/internal.py
get_internal_header
def get_internal_header(request: HttpRequest) -> str: """ Return request's 'X_POLYAXON_INTERNAL:' header, as a bytestring. """ return get_header(request=request, header_service=conf.get('HEADERS_INTERNAL'))
python
def get_internal_header(request: HttpRequest) -> str: """ Return request's 'X_POLYAXON_INTERNAL:' header, as a bytestring. """ return get_header(request=request, header_service=conf.get('HEADERS_INTERNAL'))
[ "def", "get_internal_header", "(", "request", ":", "HttpRequest", ")", "->", "str", ":", "return", "get_header", "(", "request", "=", "request", ",", "header_service", "=", "conf", ".", "get", "(", "'HEADERS_INTERNAL'", ")", ")" ]
Return request's 'X_POLYAXON_INTERNAL:' header, as a bytestring.
[ "Return", "request", "s", "X_POLYAXON_INTERNAL", ":", "header", "as", "a", "bytestring", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/scopes/authentication/internal.py#L49-L53
train
Get the internal header of the request.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/logs_handlers/tasks/log_sidecars.py
logs_sidecars_experiments
def logs_sidecars_experiments(experiment_name: str, experiment_uuid: str, job_uuid: str, log_lines: Optional[Union[str, Iterable[str]]]) -> None: """Signal handling for sidecars logs.""" handle_experiment_job_log(experimen...
python
def logs_sidecars_experiments(experiment_name: str, experiment_uuid: str, job_uuid: str, log_lines: Optional[Union[str, Iterable[str]]]) -> None: """Signal handling for sidecars logs.""" handle_experiment_job_log(experimen...
[ "def", "logs_sidecars_experiments", "(", "experiment_name", ":", "str", ",", "experiment_uuid", ":", "str", ",", "job_uuid", ":", "str", ",", "log_lines", ":", "Optional", "[", "Union", "[", "str", ",", "Iterable", "[", "str", "]", "]", "]", ")", "->", "...
Signal handling for sidecars logs.
[ "Signal", "handling", "for", "sidecars", "logs", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/logs_handlers/tasks/log_sidecars.py#L11-L25
train
Signal handling for sidecars logs.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/logs_handlers/tasks/log_sidecars.py
logs_sidecars_jobs
def logs_sidecars_jobs(job_uuid: str, job_name: str, log_lines: Optional[Union[str, Iterable[str]]]) -> None: """Signal handling for sidecars logs.""" handle_job_logs(job_uuid=job_uuid, job_name=job_name, log_lines=log_lines) ...
python
def logs_sidecars_jobs(job_uuid: str, job_name: str, log_lines: Optional[Union[str, Iterable[str]]]) -> None: """Signal handling for sidecars logs.""" handle_job_logs(job_uuid=job_uuid, job_name=job_name, log_lines=log_lines) ...
[ "def", "logs_sidecars_jobs", "(", "job_uuid", ":", "str", ",", "job_name", ":", "str", ",", "log_lines", ":", "Optional", "[", "Union", "[", "str", ",", "Iterable", "[", "str", "]", "]", "]", ")", "->", "None", ":", "handle_job_logs", "(", "job_uuid", ...
Signal handling for sidecars logs.
[ "Signal", "handling", "for", "sidecars", "logs", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/logs_handlers/tasks/log_sidecars.py#L29-L41
train
Signal handling for sidecars logs.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/logs_handlers/tasks/log_sidecars.py
logs_sidecars_builds
def logs_sidecars_builds(job_uuid: str, job_name: str, log_lines: Optional[Union[str, Iterable[str]]]) -> None: """Signal handling for sidecars logs.""" handle_build_job_logs(job_uuid=job_uuid, job_name=job_name, ...
python
def logs_sidecars_builds(job_uuid: str, job_name: str, log_lines: Optional[Union[str, Iterable[str]]]) -> None: """Signal handling for sidecars logs.""" handle_build_job_logs(job_uuid=job_uuid, job_name=job_name, ...
[ "def", "logs_sidecars_builds", "(", "job_uuid", ":", "str", ",", "job_name", ":", "str", ",", "log_lines", ":", "Optional", "[", "Union", "[", "str", ",", "Iterable", "[", "str", "]", "]", "]", ")", "->", "None", ":", "handle_build_job_logs", "(", "job_u...
Signal handling for sidecars logs.
[ "Signal", "handling", "for", "sidecars", "logs", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/logs_handlers/tasks/log_sidecars.py#L45-L57
train
Signal handling for sidecars logs.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/db/redis/group_check.py
GroupChecks.is_checked
def is_checked(self) -> bool: """One task ran (checked).""" if not self.redis_key_checked: return False value = self._red.get(self.redis_key_checked) if not value: return False return True
python
def is_checked(self) -> bool: """One task ran (checked).""" if not self.redis_key_checked: return False value = self._red.get(self.redis_key_checked) if not value: return False return True
[ "def", "is_checked", "(", "self", ")", "->", "bool", ":", "if", "not", "self", ".", "redis_key_checked", ":", "return", "False", "value", "=", "self", ".", "_red", ".", "get", "(", "self", ".", "redis_key_checked", ")", "if", "not", "value", ":", "retu...
One task ran (checked).
[ "One", "task", "ran", "(", "checked", ")", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/db/redis/group_check.py#L37-L46
train
Returns True if one task ran ( checked ).
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/db/redis/group_check.py
GroupChecks.is_delayed
def is_delayed(self) -> bool: """One task ran (checked), and one task has been delayed.""" if not self.redis_key_delayed: return False value = self._red.get(self.redis_key_delayed) if not value: return False return True
python
def is_delayed(self) -> bool: """One task ran (checked), and one task has been delayed.""" if not self.redis_key_delayed: return False value = self._red.get(self.redis_key_delayed) if not value: return False return True
[ "def", "is_delayed", "(", "self", ")", "->", "bool", ":", "if", "not", "self", ".", "redis_key_delayed", ":", "return", "False", "value", "=", "self", ".", "_red", ".", "get", "(", "self", ".", "redis_key_delayed", ")", "if", "not", "value", ":", "retu...
One task ran (checked), and one task has been delayed.
[ "One", "task", "ran", "(", "checked", ")", "and", "one", "task", "has", "been", "delayed", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/db/redis/group_check.py#L48-L57
train
Returns True if one task ran and one task has been delayed.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/streams/consumers/consumers.py
Consumer.connect
def connect(self): """This method connects to RabbitMQ, returning the connection handle. When the connection is established, the on_connection_open method will be invoked by pika. :rtype: pika.SelectConnection """ _logger.info('Connecting to %s', self.AMQP_URL) w...
python
def connect(self): """This method connects to RabbitMQ, returning the connection handle. When the connection is established, the on_connection_open method will be invoked by pika. :rtype: pika.SelectConnection """ _logger.info('Connecting to %s', self.AMQP_URL) w...
[ "def", "connect", "(", "self", ")", ":", "_logger", ".", "info", "(", "'Connecting to %s'", ",", "self", ".", "AMQP_URL", ")", "while", "True", ":", "try", ":", "return", "adapters", ".", "AsyncioConnection", "(", "pika", ".", "URLParameters", "(", "self",...
This method connects to RabbitMQ, returning the connection handle. When the connection is established, the on_connection_open method will be invoked by pika. :rtype: pika.SelectConnection
[ "This", "method", "connects", "to", "RabbitMQ", "returning", "the", "connection", "handle", ".", "When", "the", "connection", "is", "established", "the", "on_connection_open", "method", "will", "be", "invoked", "by", "pika", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/streams/consumers/consumers.py#L48-L61
train
This method connects to RabbitMQ returning the connection handle.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...
polyaxon/polyaxon
polyaxon/streams/consumers/consumers.py
Consumer.on_channel_open
def on_channel_open(self, channel): """This method is invoked by pika when the channel has been opened. The channel object is passed in so we can make use of it. Since the channel is now open, we'll declare the exchange to use. :param pika.channel.Channel channel: The channel object ...
python
def on_channel_open(self, channel): """This method is invoked by pika when the channel has been opened. The channel object is passed in so we can make use of it. Since the channel is now open, we'll declare the exchange to use. :param pika.channel.Channel channel: The channel object ...
[ "def", "on_channel_open", "(", "self", ",", "channel", ")", ":", "_logger", ".", "info", "(", "'Channel opened'", ")", "self", ".", "_channel", "=", "channel", "self", ".", "add_on_channel_close_callback", "(", ")", "self", ".", "setup_exchange", "(", "self", ...
This method is invoked by pika when the channel has been opened. The channel object is passed in so we can make use of it. Since the channel is now open, we'll declare the exchange to use. :param pika.channel.Channel channel: The channel object
[ "This", "method", "is", "invoked", "by", "pika", "when", "the", "channel", "has", "been", "opened", ".", "The", "channel", "object", "is", "passed", "in", "so", "we", "can", "make", "use", "of", "it", "." ]
e1724f0756b1a42f9e7aa08a976584a84ef7f016
https://github.com/polyaxon/polyaxon/blob/e1724f0756b1a42f9e7aa08a976584a84ef7f016/polyaxon/streams/consumers/consumers.py#L121-L132
train
This method is invoked by pika when the channel is opened.
Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL...