Language differences with Python
Syntactic constructs of Indie
Indie is a subset of Python syntax constructs, namely:
-
supported features in Indie:
- function definitions (at top level only)
- basic control statements:
if
,for
,while
- variable declarations and standard arithmetics
- basic data types are:
int
,float
,bool
,str
- decorators from the Indie’s standard library (like
@indicator
,@algorithm
and others) raise
-ing exceptions- (NOTE: this is a work in progress) container data types:
list
,tuple
. Indie requires explicit typing of the contained items - some limited (yet) support of classes and OOP
- …
-
not (yet) supported in Indie v3:
- nested function definitions
- lambdas
- generator expressions
try
..except
constructwith
..as
construct- containers
list
andtuple
are implemented partially. The other ones e.g.dict
andset
are not yet implemented - f-strings
- functions as first class objects (ability to pass function as an argument to another function call). There is an
exception here — function
Context.calc_on
actually accepts a function as one of it’s arguments… But you cannot write your own custom functions that do the same thing - …
Explicit typing
Indie requires to explicitly declare types of all variables, function parameters and function return values, except for the cases when Indie compiler is able to infer types from the context around. Luckily, in most cases it is able to do so. For example:
Another example:
Example of a function signature with typing:
Scopes of variables
In Python, variables declared in if
-statements, for
-loop blocks, and while
-loop blocks are not local variables,
and stay in scope outside of the block. Indie, on the other hand, has ‘block-level’ scoping which is very similar to
such languages like C/C++, Java, Go. For example, in Python it’s normal to write (but will fail to compile in Indie):
In Indie, variable res
will not exist after the if
..else
statements. Moreover res
of the if
block is a different
variable than the res
from the else
block. So this example in Indie should be rewritten into:
Assignments of None
values
In Indie it is not allowed to assign None
value to a variable of any arbitrary type (e.g. basic data types). But it is
allowed to do so with the help of indie.Optional[T]
class. Read more about this
here.
Syntactic sugar constructs
There are a few language constructs in Indie, which behave weird from the point of view of a standard Python. They are nothing more but a syntactic sugar for somewhat complicated things thus they make writing technical analysis indicators simpler. They are:
Main
function which transforms into aMain
class inherited fromindie.MainContext
.- Functions decorated with
@algorithm
(more info here) which transform into classes inherited fromindie.Algorithm
. Algorithm.new()
static method (e.g.indie.algorithms.Sma.new()
).MutSeries[T].new()
static method.- Functions decorated with
@sec_context
decorator which transform into classes (similar toMain
) inherited fromindie.SecContext
.
More information about this in How Indie’s syntactic sugar works section
Libraries to import from
You may think, ‘Indie is a Python-like language… so… I will import numpy, pandas, yfinance, matplotlib, talib and a lot more cool and very helpful stuff into my TakeProfit indicators right now and have some fun!’ but… unfortunately you cannot do this. Well, at least right now.
There are number of reasons why. Here are some of them:
- Those libraries are not compatible with Indie’s runtime design and internal data types.
- Many of those libraries run on CPython, we in TakeProfit cannot use it effectively as our backend runtime. We are looking forward to WebAssembly/machine code to reach higher performance. We simply cannot run these libraries’ code on those.
- There are a lot of stuff in those libraries which is not allowed to run on our servers due to our ‘sandbox’-related policies.
- We in TakeProfit are too busy to work on integration of our runtime engine with those libraries at the moment, because there are a lot of stuff yet to do to make Indie a great tool for technical analysis.
So, in other words, the fact that Indie is a Python-like language gives it an additional point of growth here. But this is a very complicated task, and it is hard to give any promises/estimates right now about it.
Now, what you can import into Indie right now, is:
- Core stuff from the standard library package
indie
, likeindicator
,algorithm
,sec_context
,Series[T]
, etc. - Classic tech analysis algorithms from the standard library package
indie.algorithms
, likeSma
,Ema
,Highest
,Lowest
, etc. - Some bits and pieces of the Python standard core libraries:
math.pow
math.sqrt
math.nan
math.isnan
statistics.mean
statistics.fmean
statistics.median
The list of items to be imported will definitely be expanded… Please, be patient.
Python built-ins
Standard Python has many built-ins. Indie has only these:
None
, NoneType
, False
, True
, abs()
, bool()
, dict()
, float()
, int()
, len()
, list()
,
min()
, max()
, range()
, round()
, str()
, sum()
, tuple()
.
Indie code runs in a sandbox
We run Indie code on our servers, that is why for the obvious reasons Indie’s runtime is sandboxed. It means that it is very restricted in terms of what is allowed to do with the host system where code is being executed. For example file and socket I/O is not allowed, execution time and memory are limited too.
Was this page helpful?