This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
sys.path.append('src') | |
project = "sphinx_test" | |
extensions = [ | |
"sphinx.ext.autodoc", | |
"sphinx.ext.napoleon", | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ uvicorn app:app | |
DEBUG:newrelic.config:agent configuration file was newrelic.ini | |
DEBUG:newrelic.config:agent config app_name = 'HelloWorld' | |
DEBUG:newrelic.config:agent config monitor_mode = True | |
DEBUG:newrelic.config:register module ('greenlet', 'newrelic.core.trace_cache', 'greenlet_loaded') | |
DEBUG:newrelic.config:register module ('asyncio', 'newrelic.core.trace_cache', 'asyncio_loaded') | |
DEBUG:newrelic.config:instrument module (<module 'asyncio' from '/home/user/python/lib/python3.8/asyncio/__init__.py'>, 'newrelic.core.trace_cache', 'asyncio_loaded') | |
DEBUG:newrelic.config:register module ('asyncio.base_events', 'newrelic.hooks.coroutines_asyncio', 'instrument_asyncio_base_events') | |
DEBUG:newrelic.config:instrument module (<module 'asyncio.base_events' from '/home/user/python/lib/python3.8/asyncio/base_events.py'>, 'newrelic.hooks.coroutines_asyncio', 'instrument_asyncio_base_events') | |
DEBUG:newrelic.config:register module ('asyncio.events', 'newrelic.hooks.coroutines_asyncio', 'instrument_asyncio_events') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import os | |
#os.environ["NEW_RELIC_LICENSE_KEY"] = "some_valid_key" | |
import sys | |
import logging | |
logging.basicConfig(stream=sys.stdout, level=logging.INFO) | |
import newrelic.agent | |
newrelic.agent.initialize("newrelic.ini") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[tool.poetry] | |
name = "foo" | |
version = "0.1.0" | |
description = "" | |
authors = ["Your Name <[email protected]>"] | |
[tool.poetry.dependencies] | |
python = "^3.8" | |
fastapi = "^0.60" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import newrelic.agent | |
from starlette.types import ASGIApp, Receive, Scope, Send | |
def get_transaction_name(middleware, scope: Scope, *args, **kwargs): | |
# Strip off the leading slash | |
name = scope.get("path", "/no-path") | |
if name == "/": | |
return "" | |
return name[1:] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from logging.config import dictConfig | |
>>> dictConfig( | |
... { | |
... "version": 1, | |
... "disable_existing_loggers": False, | |
... "formatters": { | |
... "standard": { | |
... "format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s" | |
... } | |
... }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
def main(): | |
old_file = input('please give file name: ') | |
new_file = old_file + '.updated' | |
with open(old_file) as old, open(new_file, 'w') as new: | |
writer = csv.writer(new) | |
for row in csv.reader(old): | |
if row[4] == 'MIS': | |
row[3] = row[3].replace('.com', '.net') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, jsonify | |
app = Flask(__name__) | |
@app.route("/", methods=['POST']) | |
def foo(): | |
return jsonify([*request.form.keys()]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import types | |
def inherit_docstrings(_cls=None, *, overload=True): | |
def wrap(cls): | |
for name, member in vars(cls).items(): | |
if not isinstance(member, types.FunctionType): | |
continue # only consider methods | |
if member.__doc__: | |
continue # skip documented methods |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog: | |
__slots__ = ["foo"] | |
def __setattr__(self, name, value): | |
raise TypeError("(•ˋ _ ˊ•) no touch, only throw.") | |
d = Dog() | |
# your one line of code here | |
assert type(d) is Dog | |
print(d.foo) # "take stick" |